This is a test version of Biostars. For the public version, visit https://www.biostars.org.
When To Use Bio::Sequence::Na, And When To Use Bio::Sequence?

When should I use the Bio::Sequence::NA class, and when should I use the Bio::Sequence class, if I've got a nucleotide sequence?

I assumed that you should use Bio::Sequence::NA when you know it's a nucleotide sequence, because otherwise, you're throwing information away - namely the fact that it's a nucleotide sequence, not an amino acid sequence.

However, there's methods available for Bio::Sequence, that aren't available for Bio::Sequence::NA. For example, I can do

string = "gattaca"
sequence = Bio::Sequence.new(string)
sequence.output_fasta

but I can't do the following

string = "gattaca"
na = Bio::Sequence::NA.new(string)
na.output_fasta # => NoMethodError

So which class should I be using, and why?

1 answer

As the documentation says

A Bio::Sequence object is a wrapper around the actual sequence, represented as either a Bio::Sequence::NA or a Bio::Sequence::AA object, For most users, this encapsulation will be completely transparent.

what this means is that the Sequence class offers additional functionality that makes it work identically with both nucleic and aminoacid sequences. In general you should use Bio::Sequence

Does that mean I should do string = "gattaca"; na = Bio::Sequence::NA.new(string); sequence = Bio::Sequence.new(na)?

no it means to forget that Bio::Sequence::NA even exists use the Bio::Sequence directly

Log in to answer this question.