Question: Help Me To Read The Fasta File Through Biojava.
4
gravatar for Muhammad
8.5 years ago by
Muhammad40
Muhammad40 wrote:

hi friends, I tried to read the fasta file through biojava manyways. All the time it turns out as depricated API. Please help me to find out the problem. Folowing is the error

symbol  : method readFasta(java.io.BufferedInputStream,org.biojava.bio.symbol.Alphabet)
location: class org.biojavax.bio.seq.RichSequence.IOTools
      SequenceDB db = org.biojavax.bio.seq.RichSequence.IOTools.readFasta(is, alpha);
                                                       ^

Here it is my code

import java.io.*;
import java.util.*;  
import org.biojava.bio.*;
import org.biojava.bio.seq.db.*;
import org.biojava.bio.seq.io.*;
import org.biojava.bio.symbol.*;
import org.biojavax.bio.seq.RichSequenceIterator;
import org.biojavax.bio.seq.io.FastaHeader;
import static org.biojavax.bio.seq.RichSequence.IOTools;

public class ReadFasta {

/**
* The program takes two args: the first is the file name of the Fasta file.
* The second is the name of the Alphabet. Acceptable names are DNA RNA or PROTEIN.
*/
public static void main(String[] args) {

try {
  //setup file input
  String filename = args[0];
  BufferedInputStream is =
      new BufferedInputStream(new FileInputStream(filename));


  //get the appropriate Alphabet
  Alphabet alpha = AlphabetManager.alphabetForName(args[1]);

  //get a SequenceDB of all sequences in the file
  SequenceDB db = org.biojavax.bio.seq.RichSequence.IOTools.readFasta(is, alpha);
  //SequenceDB db = org.biojava.bio.seq.io.SeqIOTools.readFasta(is, alpha);
//org.biojavax.bio.seq.RichSequence.IOTools

}
    catch (BioException ex) {
      //not in fasta format or wrong alphabet
      ex.printStackTrace();
    }catch (NoSuchElementException ex) {
      //no fasta sequences in the file
      ex.printStackTrace();
    }catch (FileNotFoundException ex) {
      //problem reading file
      ex.printStackTrace();
    }
  }
}
fasta biojava java • 5.8k views
ADD COMMENTlink modified 8.5 years ago by Brad Chapman9.3k • written 8.5 years ago by Muhammad40
7
gravatar for Brad Chapman
8.5 years ago by
Brad Chapman9.3k
Boston, MA
Brad Chapman9.3k wrote:

FASTA parsing with BioJava is a bit tricky as the cookbook is out of sync with the latest recommendations; the cookbook example Neil listed will work but is marked as deprecated. Likely this will all be resolved when BioJava 3 is finished. Here's a working program with the biojavax RichSequence classes:

import java.io.*;
import java.util.*;
import org.biojava.bio.*;
import org.biojava.bio.symbol.*;
import org.biojavax.SimpleNamespace;
import org.biojavax.bio.seq.*;

public class ReadFasta {
/**
* The program takes two args: the first is the file name of the Fasta file.
* The second is the name of the Alphabet. Acceptable names are 
* DNA RNA or PROTEIN.
*/
  public static void main(String[] args) throws
      FileNotFoundException, BioException {
    String filename = args[0];
    BufferedReader br = new BufferedReader(new FileReader(filename));
    Alphabet alpha = AlphabetManager.alphabetForName(args[1]);
    SimpleNamespace ns = new SimpleNamespace("biojava");

    RichSequenceIterator iterator = RichSequence.IOTools.readFasta(br,
            alpha.getTokenization("token"), ns);
    while (iterator.hasNext()) {
        RichSequence rec = iterator.nextRichSequence();
        System.out.println(rec.getName());
        System.out.println(rec.length());
    }
  }
}

Compile and run with:

% javac -cp .:/usr/share/java/biojava.jar ReadFasta.java
% java -cp .:/usr/share/java/biojava.jar ReadFasta your.fasta DNA
ADD COMMENTlink written 8.5 years ago by Brad Chapman9.3k

thank you for your help. its working propely

ADD REPLYlink written 8.5 years ago by Muhammad40

hi brad, expected to get sequence infomation too..!!!!

ADD REPLYlink written 8.5 years ago by Muhammad40

Muhammad -- you might want the seqString method. Check out the full API documentation for RichSequence: http://www.biojava.org/docs/api/org/biojavax/bio/seq/RichSequence.html

ADD REPLYlink written 8.5 years ago by Brad Chapman9.3k
4
gravatar for Neilfws
8.5 years ago by
Neilfws48k
Sydney, Australia
Neilfws48k wrote:

Have you looked at the example code in the BioJava cookbook?

It looks a lot like your code, except you import some extra libraries ("biojavax"). I'm not sure if they are required, since they refer to RichSequence. Fasta is not a "rich" sequence format.

ADD COMMENTlink written 8.5 years ago by Neilfws48k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1283 users visited in the last hour