[BioRuby-cvs] bioruby/lib/bio feature.rb,1.8,1.9

Katayama Toshiaki k at pub.open-bio.org
Tue Nov 29 20:54:40 EST 2005


Update of /home/repository/bioruby/bioruby/lib/bio
In directory pub.open-bio.org:/tmp/cvs-serv17445

Modified Files:
	feature.rb 
Log Message:
* Bio::Feature#to_hash, Bio::Feature#[] methods are added to replace
  Bio::Feature#assoc method (which returns incomplete value when
  the feature contains multiple qualifiers of the same name).
* Bio::Feature#each method is improved to accept qualifier name
* Bio::Features#first, Bio::Features#last methods are added.


Index: feature.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/feature.rb,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** feature.rb	4 Nov 2005 17:36:47 -0000	1.8
--- feature.rb	30 Nov 2005 01:54:38 -0000	1.9
***************
*** 99,104 ****
  
    # Iterates on each qualifier.
!   def each
      @qualifiers.each do |x|
        yield x
      end
--- 99,105 ----
  
    # Iterates on each qualifier.
!   def each(arg = nil)
      @qualifiers.each do |x|
+       next if arg and x.qualifier != arg
        yield x
      end
***************
*** 107,110 ****
--- 108,112 ----
    # Returns a Hash constructed from qualifier objects.
    def assoc
+     STDERR.puts "Bio::Feature#assoc is deprecated, use Bio::Feature#to_hash instead" if $DEBUG
      hash = Hash.new
      @qualifiers.each do |x|
***************
*** 114,117 ****
--- 116,133 ----
    end
  
+   # Returns a Hash constructed from qualifier objects.
+   def to_hash
+     hash = Hash.new
+     @qualifiers.each do |x|
+       hash[x.qualifier] ||= []
+       hash[x.qualifier] << x.value
+     end
+     return hash
+   end
+ 
+   # Short cut for the Bio::Feature#to_hash[key]
+   def [](key)
+     self.to_hash[key]
+   end
  
    # Container for the qualifier-value pair.
***************
*** 143,146 ****
--- 159,168 ----
    attr_accessor :features
  
+   def to_gff
+     # *TODO*
+     # to generate Bio::GFF object and implement Bio::GFF#to_s or
+     # to generate GFF string in this method?
+   end
+ 
    # Appends a Feature object to Features.
    def append(a)
***************
*** 161,164 ****
--- 183,196 ----
    def [](*arg)
      @features[*arg]
+   end
+ 
+   # Short cut for the Features#features.first
+   def first
+     @features.first
+   end
+ 
+   # Short cut for the Features#features.last
+   def last
+     @features.last
    end
  



More information about the bioruby-cvs mailing list