BioRuby Tutorial
Trying Bioruby
Now test the following:
require 'bio'
seq = Bio::Sequence::NA.new("atgcatgcaaaa")
=> atgcatgcaaaa
seq.complement
=> ttttgcatgcat
Working with nucleic / amino acid sequences (Bio::Sequence class)
The Bio::Sequence
class allows the usual sequence transformations and translations.
In the example below the DNA sequence atgcatgcaaaa
is converted into the complemental strand and spliced into a subsequence; next, the nucleic acid composition is calculated and the sequence is translated into the amino acid sequence, the molecular weight calculated, and so on. When translating into amino acid sequences, the frame can be specified and optionally the codon table selected (as defined in codontable.rb).
seq = Bio::Sequence::NA.new("atgcatgcaaaa")
=> atgcatgcaaaa
# complemental sequence (Bio::Sequence::NA object)
seq.complement
=> ttttgcatgcat
seq.subseq(3,8) # gets subsequence of positions 3 to 8 (starting from 1)
=> gcatgc
seq.gc_percent
=> 33
seq.composition
=> {"a"=>6, "t"=>2, "g"=>2, "c"=>2}
seq.translate
=> MHAK
seq.translate(2)
=> CMQ
seq.translate(1,11)
=> MHAK
seq.translate.codes
=> ["Met", "His", "Ala", "Lys"]
seq.translate.names
=> ["methionine", "histidine", "alanine", "lysine"]
seq.translate.composition
=> {"M"=>1, "H"=>1, "A"=>1, "K"=>1}
seq.translate.molecular_weight
=> 485.6050000000001
seq.complement.translate
=> FCMH