// code to read the fasta file
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();
    }
  }
}

put it in code tags please

Do you have any specific problems or questions?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.