Dear Richard,
thank you for your answer. What you stated in your PSS is exactly what I
want. It worked well with the ByteArrayOutputStream. Nevertheless I dont
use it but write my own string by concatenating the names and sequences
using String s = ">" + name + "\r\n" + sequence + "\r\n". I know its not
the best way but this fasta format thing modified the input names too
much that I would have had to much trouble getting the right information
out of them.
Best regards,
Oliver
Richard Holland schrieb:
PS. Spot the deliberate mistake in the hasNext() function... that should be <, not
<=!
PPS. In your original email you stated you wanted to read your sequences as
Fasta. In Biojava, all sequences are RichSequences - they have no format other
than the object model of RichSequence itself. Fasta only gets involved when
you're reading from a Fasta file, or writing to one. If you need to show the
sequences as Fasta in your user interface, you should consider using the
FastaWriter writeSequence() method with the PrintStream parameter and wiring in
a StringWriter to the PrintStream so that you can get a String representation
of a Fasta record.
On 6 Dec 2009, at 15:41, Richard Holland wrote:
I'm not sure what you're trying to do here - are you trying to represent your
string array of sequences as a RichSequenceIterator, or are you trying to
convert them into FASTA? I'll answer both anyway...:
To convert your String[] of sequences into a RichSequenceIterator you need to
create a new class that implements the RichSequenceIterator interface. You
would probably write something like this (which I have not checked or compiled
- so if it has bugs, sorry!):
public class MyDNASeqIterator implements RichSequenceIterator {
private final String[] sequences;
private final int counter;
public MyDNASeqIterator(String[] sequences) { this.sequences = sequences;
this.counter = 0; }
public hasNext() {
return this.counter <= this.sequences.length;
}
public Sequence nextSequence() { return nextRichSequence(); }
public BioEntry nextBioEntry() { return nextRichSequence(); }
public RichSequence nextRichSequence() {
String seqName = "MySeq"+this.counter;
return RichSequence.Tools.createRichSequence(seqName,
this.sequences[this.counter++], DNATools.getDNA());
}
}
You can then instantiate an object using MyDNASeqIterator's constructor to give
it your string array, and iterate over it to get corresponding RichSequence
instances.
To convert your sequences to FASTA, use the above iterator to generate
sequences to pass to FastaFormat in the same way that you would write a normal
FASTA file.
cheers,
Richard
On 6 Dec 2009, at 14:04, Oliver Stolpe wrote:
Hello *,
I have a set of sequences as strings in an array. I now want to turn them into
an iterator over RichSequences in fasta-format. I read in the cookbook, but I
dont get it. And looked up the examples in biojavax-doc. I tried much but I
have no good starting point. No starting point at all. How do the
RichSequenceBuilder work? What about the FastaFormat-thing?
I thought about putting the sequences in a fast-file and then read the file.
But there must be a much more straight-forward way!
Thanks in advance for any hints,
Oliver
_______________________________________________
Biojava-l mailing list - [email protected]
http://lists.open-bio.org/mailman/listinfo/biojava-l
--
Richard Holland, BSc MBCS
Operations and Delivery Director, Eagle Genomics Ltd
T: +44 (0)1223 654481 ext 3 | E: [email protected]
http://www.eaglegenomics.com/
_______________________________________________
Biojava-l mailing list - [email protected]
http://lists.open-bio.org/mailman/listinfo/biojava-l
--
Richard Holland, BSc MBCS
Operations and Delivery Director, Eagle Genomics Ltd
T: +44 (0)1223 654481 ext 3 | E: [email protected]
http://www.eaglegenomics.com/
Mit den besten Grüßen,
Oliver
--
Semestersprecher 5. Semester Bioinformatik
<http://page.mi.fu-berlin.de/stolpe/>
<mailto:[email protected]>
_______________________________________________
Biojava-l mailing list - [email protected]
http://lists.open-bio.org/mailman/listinfo/biojava-l