[BioRuby-cvs] bioruby/lib/bio/sequence na.rb,1.3,1.4
Naohisa Goto
ngoto at dev.open-bio.org
Tue Jun 27 05:44:59 UTC 2006
Update of /home/repository/bioruby/bioruby/lib/bio/sequence
In directory dev.open-bio.org:/tmp/cvs-serv7649/lib/bio/sequence
Modified Files:
na.rb
Log Message:
Bio::Sequence::NA#gc_content, #at_content, #gc_skew, #at_skew
are newly added.
Bio::Sequence::NA#gc_percent are changed not to raise ZeroDivisionError
and returns 0 when given sequence is empty.
Index: na.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/sequence/na.rb,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** na.rb 26 Mar 2006 02:27:59 -0000 1.3
--- na.rb 27 Jun 2006 05:44:57 -0000 1.4
***************
*** 282,286 ****
# Calculate the ratio of GC / ATGC bases as a percentage rounded to
! # the nearest whole number.
#
# s = Bio::Sequence::NA.new('atggcgtga')
--- 282,286 ----
# Calculate the ratio of GC / ATGC bases as a percentage rounded to
! # the nearest whole number. U is regarded as T.
#
# s = Bio::Sequence::NA.new('atggcgtga')
***************
*** 292,299 ****
--- 292,356 ----
at = count['a'] + count['t'] + count['u']
gc = count['g'] + count['c']
+ return 0 if at + gc == 0
gc = 100 * gc / (at + gc)
return gc
end
+ # Calculate the ratio of GC / ATGC bases. U is regarded as T.
+ #
+ # s = Bio::Sequence::NA.new('atggcgtga')
+ # puts s.gc_content #=> 0.555555555555556
+ # ---
+ # *Returns*:: Float
+ def gc_content
+ count = self.composition
+ at = count['a'] + count['t'] + count['u']
+ gc = count['g'] + count['c']
+ return 0.0 if at + gc == 0
+ return (gc.to_f / (at + gc).to_f)
+ end
+
+ # Calculate the ratio of AT / ATGC bases. U is regarded as T.
+ #
+ # s = Bio::Sequence::NA.new('atggcgtga')
+ # puts s.at_content #=> 0.444444444444444
+ # ---
+ # *Returns*:: Float
+ def at_content
+ count = self.composition
+ at = count['a'] + count['t'] + count['u']
+ gc = count['g'] + count['c']
+ return 0.0 if at + gc == 0
+ return (at.to_f / (at + gc).to_f)
+ end
+
+ # Calculate the ratio of (G - C) / (G + C) bases.
+ #
+ # s = Bio::Sequence::NA.new('atggcgtga')
+ # puts s.gc_skew #=> 0.6
+ # ---
+ # *Returns*:: Float
+ def gc_skew
+ count = self.composition
+ g = count['g']
+ c = count['c']
+ return 0.0 if g + c == 0
+ return ((g - c).to_f / (g + c).to_f)
+ end
+
+ # Calculate the ratio of (A - T) / (A + T) bases. U is regarded as T.
+ #
+ # s = Bio::Sequence::NA.new('atgttgttgttc')
+ # puts s.at_skew #=> -0.75
+ # ---
+ # *Returns*:: Float
+ def at_skew
+ count = self.composition
+ a = count['a']
+ t = count['t'] + count['u']
+ return 0.0 if a + t == 0
+ return ((a - t).to_f / (a + t).to_f)
+ end
+
# Returns an alphabetically sorted array of any non-standard bases
# (other than 'atgcu').
More information about the bioruby-cvs
mailing list