[Biojava-l] readFasta problem

Richard Holland holland at eaglegenomics.com
Sun Apr 25 08:21:22 UTC 2010


Hi.

You are calling a non-existing version of writeFasta. I'm surprised your code even compiles!

Have a look at the JavaDocs to find out what you can actually do with writeFasta. For a start, it takes Sequence and FastaHeader objects as parameters, not Strings as you are trying to do.

http://www.biojava.org/docs/api17/org/biojavax/bio/seq/RichSequence.IOTools.html

cheers,
Richard

On 25 Apr 2010, at 06:19, xyz wrote:

> On Wed, 21 Apr 2010 12:29:57 +0100
> Richard Holland wrote:
> 
>>> Q1:
>>> Does RichSequenceIterator read the complete file in memory and then
>>> I retrieve each read from memory? Or does it read the file line by
>>> line and I get each read?
>> 
>> 
>> Line by line.
> 
> That save memory.
> 
>>> Q2:
>>> Why am I not able to retrieve the header from the following fasta
>>> file:
>>>> 1
>>> atccccc
>>>> 2
>>> atccccctttttt
>>>> 3
>>> atccccccccccccccccctttt
>>>> 4
>>> tttttttccccccccccccccccccccccc
>>>> 5
>>> tttttttcccccccccccccccccccccca
>> 
>> Try the other methods on RichSequence - getName() for instance.
> 
> Thank you getName() works.
> 
> I have tried to write fasta file line by line with IOTools, but I have
> got the following error:
> Exception in thread "main" java.lang.RuntimeException: Uncompilable
> source code 1
>        at SortFasta.main(SortFasta.java:31)
> atccccc
> Java Result: 1
> 
> Here is the complete code:
> 
> import java.io.BufferedReader;
> import java.io.FileNotFoundException;
> import java.io.FileOutputStream;
> import java.io.FileReader;
> import org.biojava.bio.BioException;
> import org.biojava.bio.seq.io.SymbolTokenization;
> import org.biojava.bio.symbol.AlphabetManager;
> import org.biojavax.bio.seq.RichSequence;
> import org.biojavax.bio.seq.RichSequenceIterator;
> 
> public class SortFasta {
> 
>  public static void main(String[] args) throws FileNotFoundException,
>  BioException {
> 
> 
>    BufferedReader br = new BufferedReader(new
>    FileReader("sortFasta.fasta")); String type = "DNA";
>    SymbolTokenization toke = AlphabetManager.alphabetForName(type)
> 					.getTokenization("token");
> 
>    FileOutputStream outputFasta = new FileOutputStream("test.fasta");
> 
>    RichSequenceIterator rsi = RichSequence.IOTools.readFasta(br, toke,
>    null);
> 
>    while (rsi.hasNext()) {
>      RichSequence rs = rsi.nextRichSequence();
>      System.out.println(rs.getName());
>      System.out.println(rs.seqString());
> 
>      RichSequence.IOTools.writeFasta(outputFasta, rs.seqString(), null,
>              rs.getName() + "1");
>    }
>  }
> }
> 
> How is it possible to write fasta files line by line?

--
Richard Holland, BSc MBCS
Operations and Delivery Director, Eagle Genomics Ltd
T: +44 (0)1223 654481 ext 3 | E: holland at eaglegenomics.com
http://www.eaglegenomics.com/





More information about the Biojava-l mailing list