This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Converting from Sequence<AminoAcidCompound> to ProteinSequence in BioJava 4

Hi there,

I'm hoping this is a dreadfully silly question and I'm just missing something fundamental in the JavaDocs because I can't seem to find a good example elsewhere.

Basically I'm working on a sequence validation project where I'm using the TranscriptionEngine class to translate all 6 frames, so I'm left with a map of Frame and Sequence<AminoAcidCompound> objects.

I can't, for the life of me, find the right was to convert from Sequence<AminoAcidCompound> to ProteinSequence

It's a general question really. Looking at the constructors for DNA, RNA, and ProteinSequence classes, they want SequenceReader or ProxySequenceReader instances.

Does this mean I need to construct an ArrayListSequenceReader from my Sequence<C> objects just to create the wrapper?

I have to be missing something.

Thanks!

Code below

​DNASequence dna = *readDNAFasta*(inputFasta);
Sequence<NucleotideCompound> subset = dna.getSubSequence(10, dna.getLength());

SequenceReader<NucleotideCompound> reader = **new **ArrayListSequenceReader<>(subset.getAsList(), subset.getCompoundSet());
DNASequence dnaFromSubset = **new **DNASequence(reader);

Obviously this is a contrived example. But it illustrates my point. What's the proper way to convert from a Sequence<NucleotideCompound> to a DNASequence object? I was hoping there was a simple wrapper, but there's nothing obvious.

biojava

1 answer

a simple one-liner could be:

DNASequence newS = new DNASequence(subset.getSequenceAsString());

Log in to answer this question.