edu.upenn.gloDB.io
Class FASTASequence

java.lang.Object
  extended by edu.upenn.gloDB.io.FASTASequence
All Implemented Interfaces:
DataFile, SequenceFile, SequenceLoader

public class FASTASequence
extends java.lang.Object
implements SequenceFile, SequenceLoader

Import Sequence data from a FASTA file. The basic file format dictates a header line at the beginning of each sequence. There are no standards as to what the header line should contain or how it should be formatted, other than to stipulate that it begins with a ">". Thus this format sufficient for coding Sequence objects but not ideal for sequence annotations (Features). Since some sites, such as www.fruitfly.org, release annotations as FASTA files, some attempt has been made to parse the headers from specific sites. Users can use the FASTAParser interface to create their own header parsers as well.

Version:
$Id: FASTASequence.java,v 1.31.2.16 2007/03/01 21:17:33 fisher Exp $
Notes:
can we assume that the header starts with a Sequence ID?

Nested Class Summary
private  class FASTASequence.FASTAFilter
          FASTA specific FileFilter.
 
Field Summary
private  java.lang.String DESC
           
private  java.lang.String[] EXT
           
private  javax.swing.filechooser.FileFilter fileFilter
           
private  int ID
           
 
Constructor Summary
FASTASequence()
           
 
Method Summary
 java.lang.String getData(java.util.HashMap loaderArgs)
          Return the Sequence data as a String.
 java.lang.String getDesc()
          Get a description of the file type.
 java.lang.String[] getExt()
          Get an array of file extensions.
 javax.swing.filechooser.FileFilter getFileFilter()
          Get a FileFilter for use in the GUI.
 int getID()
          Get the file ID.
 Sequence load(java.lang.String filename)
          Load the first sequence in the FASTA file and return the resulting Sequence object.
 Sequence load(java.lang.String filename, java.lang.String id)
          Load the first sequence in the FASTA file and return the resulting Sequence object.
 Sequence load(java.lang.String filename, java.lang.String id, FASTAParser parser)
          Load the first sequence in the FASTA file and return the resulting Sequence object.
 java.util.HashSet loadAll(java.lang.String filename)
          Load all Sequences in the FASTA file and return a Set containing the resulting Sequence objects.
 java.util.HashSet loadAll(java.lang.String filename, FASTAParser parser)
          Load all Sequences in the FASTA file and return a set containing the resulting Sequence objects.
 void save(java.lang.String id)
          Save the Seqeuence to a file based on it's ID.
 void save(java.lang.String id, java.lang.String filename, boolean overwrite)
          Save the Sequence data.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ID

private final int ID
See Also:
Constant Field Values

DESC

private final java.lang.String DESC
See Also:
Constant Field Values

EXT

private final java.lang.String[] EXT

fileFilter

private final javax.swing.filechooser.FileFilter fileFilter
Constructor Detail

FASTASequence

public FASTASequence()
Method Detail

getID

public int getID()
Description copied from interface: DataFile
Get the file ID. FileIO contains constant values and string equivalents for built-in DataFiles.

Specified by:
getID in interface DataFile

getDesc

public java.lang.String getDesc()
Description copied from interface: DataFile
Get a description of the file type. This description will be used in the file chooser.

Specified by:
getDesc in interface DataFile

getExt

public java.lang.String[] getExt()
Description copied from interface: DataFile
Get an array of file extensions. These extensions will be used by the file chooser.

Specified by:
getExt in interface DataFile

getFileFilter

public javax.swing.filechooser.FileFilter getFileFilter()
Description copied from interface: DataFile
Get a FileFilter for use in the GUI.

Specified by:
getFileFilter in interface DataFile

getData

public java.lang.String getData(java.util.HashMap loaderArgs)
Return the Sequence data as a String. This assumes a single Sequence per file.

Specified by:
getData in interface SequenceLoader
Notes:
This should allow for FASTA files with more than one Sequence -- can use headers to find correct data.

load

public Sequence load(java.lang.String filename)
Load the first sequence in the FASTA file and return the resulting Sequence object.

Specified by:
load in interface SequenceFile

load

public Sequence load(java.lang.String filename,
                     java.lang.String id)
Load the first sequence in the FASTA file and return the resulting Sequence object.

Specified by:
load in interface SequenceFile

load

public Sequence load(java.lang.String filename,
                     java.lang.String id,
                     FASTAParser parser)
Load the first sequence in the FASTA file and return the resulting Sequence object.

Specified by:
load in interface SequenceFile
Notes:
need to throw FileIO exceptions, rather than just print errors.

loadAll

public java.util.HashSet loadAll(java.lang.String filename)
Load all Sequences in the FASTA file and return a Set containing the resulting Sequence objects.

Specified by:
loadAll in interface SequenceFile
Notes:
need to throw FileIO exceptions, rather than just print errors.

loadAll

public java.util.HashSet loadAll(java.lang.String filename,
                                 FASTAParser parser)
Load all Sequences in the FASTA file and return a set containing the resulting Sequence objects.

Specified by:
loadAll in interface SequenceFile
Notes:
need to throw FileIO exceptions, rather than just print errors.

save

public void save(java.lang.String id)
Save the Seqeuence to a file based on it's ID. This will overwrite any existing file. This will append ".fasta" to the filename.

Specified by:
save in interface SequenceFile

save

public void save(java.lang.String id,
                 java.lang.String filename,
                 boolean overwrite)
Save the Sequence data. This will make sure the data is loaded prior to saving the Sequence.

Specified by:
save in interface SequenceFile

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object



Copyright 2012 Stephen Fisher and Junhyong Kim, University of Pennsylvania. All Rights Reserved.