[BioRuby-cvs] bioruby/lib/bio feature.rb,1.6,1.7

Katayama Toshiaki k at pub.open-bio.org
Sun Oct 23 03:21:03 EDT 2005


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

Modified Files:
	feature.rb 
Log Message:
* Changed to RDoc format


Index: feature.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/feature.rb,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** feature.rb	8 Sep 2005 01:22:08 -0000	1.6
--- feature.rb	23 Oct 2005 07:21:00 -0000	1.7
***************
*** 1,6 ****
  #
! # bio/feature.rb - Features/Feature class (GenBank Feature table)
  #
! #   Copyright (C) 2002 KATAYAMA Toshiaki <k at bioruby.org>
  #
  #  This library is free software; you can redistribute it and/or
--- 1,43 ----
  #
! # = bio/feature.rb - Features/Feature class (GenBank Feature table)
  #
! # Author::	Toshiaki Katayama <k at bioruby.org>
! # Copyright::	Copyright (c) 2002, 2005 BioRuby project
! # License::	LGPL
! #
! # $Id$
! #
! # == INSD Feature table definition
! #
! # See http://www.ddbj.nig.ac.jp/FT/full_index.html for the INSD
! # (GenBank/EMBL/DDBJ) Feature table definition.
! #
! # === Example
! #
! #  # suppose features is a Bio::Features object
! #  features.each do |feature|
! #    f_name = feature.feature
! #    f_pos  = feature.position
! #    puts "#{f_name}:\t#{f_pos}"
! #    feature.each do |qualifier|
! #      q_name = qualifier.qualifier
! #      q_val  = qualifier.value
! #      puts "- #{q_name}:\t#{q_val}"
! #    end
! #  end
! #
! #  # Iterates only on CDS features and extract translated amino acid sequences
! #  features.each("CDS") do |feature|
! #    hash = feature.assoc
! #    name = hash["gene"] || hash["product"] || hash["note"] 
! #    seq  = hash["translation"]
! #    pos  = feature.position
! #    if gene and seq
! #      puts ">#{gene} #{feature.position}"
! #      puts aaseq
! #    end
! #  end
! #
! #--
  #
  #  This library is free software; you can redistribute it and/or
***************
*** 18,22 ****
  #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  #
! #  $Id$
  #
  
--- 55,59 ----
  #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  #
! #++
  #
  
***************
*** 25,93 ****
  module Bio
  
!   class Feature
! 
!     def initialize(feature = '', position = '', qualifiers = [])
!       @feature, @position, @qualifiers = feature, position, qualifiers
!     end
!     attr_accessor :feature, :position, :qualifiers
! 
!     def locations
!       Locations.new(@position)
!     end
  
!     def append(a)
!       @qualifiers.push(a) if a.is_a? Qualifier
!       return self
!     end
  
!     def each
!       @qualifiers.each do |x|
!         yield x
!       end
!     end
  
!     def assoc
!       hash = Hash.new
!       @qualifiers.each do |x|
!         hash[x.qualifier] = x.value
!       end
!       return hash
!     end
  
  
!     class Qualifier
  
!       def initialize(key, value)
!         @qualifier, @value = key, value
!       end
!       attr_reader :qualifier, :value
  
      end
- 
    end
  
  
-   class Features
  
!     def initialize(ary = [])
!       @features = ary
!     end
!     attr_accessor :features
  
!     def append(a)
!       @features.push(a) if a.is_a? Feature
!       return self
      end
  
!     def each(arg = nil)
!       @features.each do |x|
!         next if arg and x.feature != arg
!         yield x
!       end
!     end
  
!     def [](*arg)
!       @features[*arg]
!     end
  
    end
--- 62,125 ----
  module Bio
  
! # Container for the sequence annotation.
! class Feature
  
!   def initialize(feature = '', position = '', qualifiers = [])
!     @feature, @position, @qualifiers = feature, position, qualifiers
!   end
  
!   # Returns type of feature in String (e.g 'CDS', 'gene')
!   attr_accessor :feature
  
!   # Returns position of the feature in String (e.g. 'complement(123..146)')
!   attr_accessor :position
  
+   # Returns an Array of Qualifier objects.
+   attr_accessor :qualifiers
  
!   # Returns a Bio::Locations object translated from the position string.
!   def locations
!     Locations.new(@position)
!   end
  
!   # Appends a Qualifier object to the Feature.
!   #
!   # * Returns an Array of Qualifier objects.
!   # * If the argument is not a Qualifier object, returns nil.
!   #
!   def append(a)
!     @qualifiers.push(a) if a.is_a? Qualifier
!     return self
!   end
  
+   # Iterates on each qualifier.
+   def each
+     @qualifiers.each do |x|
+       yield x
      end
    end
  
+   # Returns a Hash constructed from qualifier objects.
+   def assoc
+     hash = Hash.new
+     @qualifiers.each do |x|
+       hash[x.qualifier] = x.value
+     end
+     return hash
+   end
  
  
!   # Container for the qualifier-value pair.
!   class Qualifier
  
!     def initialize(key, value)
!       @qualifier, @value = key, value
      end
  
!     # Qualifier name in String
!     attr_reader :qualifier
  
!     # Qualifier value in String
!     attr_reader :value
  
    end
***************
*** 96,129 ****
  
  
! =begin
! 
! = Bio::Feature
! 
! --- Bio::Feature.new(feature = '', position = '', qualifiers = [])
! 
! --- Bio::Feature#feature -> String
! --- Bio::Feature#position -> String
! --- Bio::Feature#qualifiers -> Array
! 
! --- Bio::Feature#locations -> Bio::Locations
! --- Bio::Feature#append -> Bio::Feature
! --- Bio::Feature#each -> Array
  
! == Bio::Feature::Qualifier
  
! --- Bio::Feature::Qualifier.new(key, value)
  
! --- Bio::Feature::Qualifier#qualifier -> String
! --- Bio::Feature::Qualifier#value -> String
  
! = Bio::Features
  
! --- Bio::Features.new(ary = [])
  
! --- Bio::Features#features -> Array
! --- Bio::Features#append(a) -> Bio::Features
! --- Bio::Features#each -> Array
  
! =end
  
  
--- 128,164 ----
  
  
! # Container for the list of Feature objects.
! class Features
  
!   def initialize(ary = [])
!     @features = ary
!   end
  
!   # Returns an Array of Feature objects.
!   attr_accessor :features
  
!   # Appends a Feature object to Features.
!   def append(a)
!     @features.push(a) if a.is_a? Feature
!     return self
!   end
  
!   # Iterates on each feature.  If a feature name is given as an argument,
!   # only iterates on each feature belongs to the name (e.g. 'CDS' etc.)
!   def each(arg = nil)
!     @features.each do |x|
!       next if arg and x.feature != arg
!       yield x
!     end
!   end
  
!   # Short cut for the Features#features[n]
!   def [](*arg)
!     @features[*arg]
!   end
  
! end
  
! end # Bio
  
  



More information about the bioruby-cvs mailing list