com.compomics.util.experiment.identification
Class SequenceFactory

java.lang.Object
  extended by com.compomics.util.experiment.identification.SequenceFactory

public class SequenceFactory
extends java.lang.Object

Factory retrieving the information of the loaded FASTA file

Author:
marc

Field Summary
static java.lang.String[] decoyFlags
          Recognized flags for a decoy protein
 
Method Summary
 void appendDecoySequences(java.io.File destinationFile)
          Appends decoy sequences to the desired file.
 void appendDecoySequences(java.io.File destinationFile, javax.swing.JProgressBar progressBar)
          Appends decoy sequences to the desired file while displaying progress.
 void closeFile()
          Closes the opened file.
 boolean concatenatedTargetDecoy()
          Indicates whether the database loaded contains decoy sequences.
static FastaIndex createFastaIndex(java.io.File fastaFile)
          Static method to create a FASTA index for a FASTA file.
static FastaIndex createFastaIndex(java.io.File fastaFile, javax.swing.JProgressBar progressBar)
          Static method to create a FASTA index for a FASTA file.
 java.util.HashMap<java.lang.String,java.lang.Integer> getAAOccurrences(javax.swing.JProgressBar progressBar)
          Returns the occurrence of every amino acid in the database
 java.util.ArrayList<java.lang.String> getAccessions()
          Returns the sequences present in the database.
 FastaIndex getFastaIndex(java.io.File fastaFile)
          Returns the file index of a FASTA file.
 FastaIndex getFastaIndex(java.io.File fastaFile, javax.swing.JProgressBar progressBar)
          Returns the file index of a FASTA file.
 Header getHeader(java.lang.String accession)
          Returns the desired header for the protein in the FASTA file.
 FastaIndex getIndex(java.io.File fastaIndex)
          Deserializes the index of the FASTA file.
static SequenceFactory getInstance()
          Static method returning the instance of the factory.
static SequenceFactory getInstance(int nCache)
          returns the instance of the factory with the specified cache size.
 int getnCache()
          Returns the size of the cache.
 int getNTargetSequences()
          Returns the number of target sequences in the database.
 Protein getProtein(java.lang.String accession)
          Returns the desired protein.
static boolean isDecoy(java.lang.String proteinAccession)
          Returns a boolean indicating whether a protein is decoy or not based on the protein accession.
 void loadFastaFile(java.io.File fastaFile)
          Loads a new FASTA file in the factory.
 void loadFastaFile(java.io.File fastaFile, javax.swing.JProgressBar progressBar)
          Loads a new FASTA file in the factory.
 void setnCache(int nCache)
          Sets the size of the cache.
 void writeIndex(FastaIndex fastaIndex, java.io.File directory)
          Serializes the FASTA file index in a given directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

decoyFlags

public static final java.lang.String[] decoyFlags
Recognized flags for a decoy protein

Method Detail

getInstance

public static SequenceFactory getInstance()
Static method returning the instance of the factory.

Returns:
the instance of the factory

getInstance

public static SequenceFactory getInstance(int nCache)
returns the instance of the factory with the specified cache size.

Parameters:
nCache - the new cache size
Returns:
the instance of the factory with the specified cache size

getProtein

public Protein getProtein(java.lang.String accession)
                   throws java.io.IOException,
                          java.lang.IllegalArgumentException
Returns the desired protein.

Parameters:
accession - accession of the desired protein
Returns:
the desired protein
Throws:
java.io.IOException - thrown whenever an error is encountered while reading the FASTA file
java.lang.IllegalArgumentException - thrown whenever an error is encountered while reading the FASTA file

getHeader

public Header getHeader(java.lang.String accession)
                 throws java.io.IOException,
                        java.lang.IllegalArgumentException
Returns the desired header for the protein in the FASTA file.

Parameters:
accession - accession of the desired protein
Returns:
the corresponding header
Throws:
java.io.IOException - exception thrown whenever an error occurred while reading the FASTA file
java.lang.IllegalArgumentException - exception thrown whenever a protein is not found

loadFastaFile

public void loadFastaFile(java.io.File fastaFile)
                   throws java.io.FileNotFoundException,
                          java.io.IOException,
                          java.lang.ClassNotFoundException
Loads a new FASTA file in the factory. Only one FASTA file can be loaded at a time.

Parameters:
fastaFile - the FASTA file to load
Throws:
java.io.FileNotFoundException - exception thrown if the file was not found
java.io.IOException - exception thrown if an error occurred while reading the FASTA file
java.lang.ClassNotFoundException - exception thrown whenever an error occurred while deserializing the file index

loadFastaFile

public void loadFastaFile(java.io.File fastaFile,
                          javax.swing.JProgressBar progressBar)
                   throws java.io.FileNotFoundException,
                          java.io.IOException,
                          java.lang.ClassNotFoundException
Loads a new FASTA file in the factory. Only one FASTA file can be loaded at a time.

Parameters:
fastaFile - the FASTA file to load
progressBar - a progress bar showing the progress
Throws:
java.io.FileNotFoundException - exception thrown if the file was not found
java.io.IOException - exception thrown if an error occurred while reading the FASTA file
java.lang.ClassNotFoundException - exception thrown whenever an error occurred while deserializing the file index

getFastaIndex

public FastaIndex getFastaIndex(java.io.File fastaFile)
                         throws java.io.FileNotFoundException,
                                java.io.IOException,
                                java.lang.ClassNotFoundException
Returns the file index of a FASTA file.

Parameters:
fastaFile - the FASTA file
Returns:
the index of the FASTA file
Throws:
java.io.FileNotFoundException - exception thrown if the file was not found
java.io.IOException - exception thrown if an error occurred while reading the FASTA file
java.lang.ClassNotFoundException - exception thrown whenever an error occurred while deserializing the file index

getFastaIndex

public FastaIndex getFastaIndex(java.io.File fastaFile,
                                javax.swing.JProgressBar progressBar)
                         throws java.io.FileNotFoundException,
                                java.io.IOException,
                                java.lang.ClassNotFoundException
Returns the file index of a FASTA file.

Parameters:
fastaFile - the FASTA file
progressBar - a progress bar showing the progress
Returns:
the index of the FASTA file
Throws:
java.io.FileNotFoundException - exception thrown if the file was not found
java.io.IOException - exception thrown if an error occurred while reading the FASTA file
java.lang.ClassNotFoundException - exception thrown whenever an error occurred while deserializing the file index

writeIndex

public void writeIndex(FastaIndex fastaIndex,
                       java.io.File directory)
                throws java.io.IOException
Serializes the FASTA file index in a given directory.

Parameters:
fastaIndex - the index of the FASTA file
directory - the directory where to write the file
Throws:
java.io.IOException - exception thrown whenever an error occurred while writing the file

getIndex

public FastaIndex getIndex(java.io.File fastaIndex)
                    throws java.io.FileNotFoundException,
                           java.io.IOException,
                           java.lang.ClassNotFoundException
Deserializes the index of the FASTA file.

Parameters:
fastaIndex - the FASTA cui index file
Returns:
the corresponding FastaIndex instance
Throws:
java.io.FileNotFoundException - exception thrown if the file was not found
java.io.IOException - exception thrown if an error occurred while reading the FASTA file
java.lang.ClassNotFoundException - exception thrown whenever an error occurred while deserializing the file index

closeFile

public void closeFile()
               throws java.io.IOException
Closes the opened file.

Throws:
java.io.IOException - exception thrown whenever an error occurred while closing the file

createFastaIndex

public static FastaIndex createFastaIndex(java.io.File fastaFile)
                                   throws java.io.FileNotFoundException,
                                          java.io.IOException
Static method to create a FASTA index for a FASTA file.

Parameters:
fastaFile - the FASTA file
Returns:
the corresponding FASTA index
Throws:
java.io.FileNotFoundException - exception thrown if the FASTA file was not found
java.io.IOException - exception thrown whenever an error occurred while reading the file

createFastaIndex

public static FastaIndex createFastaIndex(java.io.File fastaFile,
                                          javax.swing.JProgressBar progressBar)
                                   throws java.io.FileNotFoundException,
                                          java.io.IOException
Static method to create a FASTA index for a FASTA file.

Parameters:
fastaFile - the FASTA file
progressBar - a progress bar showing the progress
Returns:
the corresponding FASTA index
Throws:
java.io.FileNotFoundException - exception thrown if the FASTA file was not found
java.io.IOException - exception thrown whenever an error occurred while reading the file

isDecoy

public static boolean isDecoy(java.lang.String proteinAccession)
Returns a boolean indicating whether a protein is decoy or not based on the protein accession. Recognized flags for decoy proteins are listed as a static field.

Parameters:
proteinAccession - The accession of the protein
Returns:
a boolean indicating whether the protein is Decoy.

concatenatedTargetDecoy

public boolean concatenatedTargetDecoy()
Indicates whether the database loaded contains decoy sequences.

Returns:
a boolean indicating whether the database loaded contains decoy sequences

getNTargetSequences

public int getNTargetSequences()
Returns the number of target sequences in the database.

Returns:
the number of target sequences in the database

appendDecoySequences

public void appendDecoySequences(java.io.File destinationFile)
                          throws java.io.IOException
Appends decoy sequences to the desired file.

Parameters:
destinationFile - the destination file
Throws:
java.io.IOException - exception thrown whenever an error occurred while reading or writing a file

appendDecoySequences

public void appendDecoySequences(java.io.File destinationFile,
                                 javax.swing.JProgressBar progressBar)
                          throws java.io.IOException,
                                 java.lang.IllegalArgumentException
Appends decoy sequences to the desired file while displaying progress.

Parameters:
destinationFile - the destination file
progressBar - the progress bar
Throws:
java.io.IOException - exception thrown whenever an error occurred while reading or writing a file
java.lang.IllegalArgumentException - exdeption thrown whenever a protein is not found

getAccessions

public java.util.ArrayList<java.lang.String> getAccessions()
Returns the sequences present in the database.

Returns:
the sequences present in the database

getnCache

public int getnCache()
Returns the size of the cache.

Returns:
the size of the cache

setnCache

public void setnCache(int nCache)
Sets the size of the cache.

Parameters:
nCache - the new size of the cache

getAAOccurrences

public java.util.HashMap<java.lang.String,java.lang.Integer> getAAOccurrences(javax.swing.JProgressBar progressBar)
                                                                       throws java.io.IOException
Returns the occurrence of every amino acid in the database

Parameters:
progressBar - a progress bar, can be null
Returns:
a map containing all amino acid occurrence in the database
Throws:
java.io.IOException - exception thrown whenever an error occurred while reading the database


Copyright © 2012. All Rights Reserved.