0
// 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();
    }
  }
}

Edited by mike_2000_17: Fixed formatting

3
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by NormR1
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.