com.compomics.util.experiment.identification
Class SequenceFactory

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

public class SequenceFactory
extends Object

Factory retrieving the information of the loaded FASTA file.

Author:
Marc Vaudel, Harald Barsnes

Method Summary
 void appendDecoySequences(File destinationFile)
          Appends decoy sequences to the desired file.
 void appendDecoySequences(File destinationFile, WaitingHandler waitingHandler)
          Appends decoy sequences to the desired file while displaying progress.
 void clearFactory()
          Clears the factory getInstance() needs to be called afterwards.
 void closeFile()
          Closes the opened file.
 double computeMolecularWeight(String accession)
          Returns the protein's molecular weight.
 boolean concatenatedTargetDecoy()
          Indicates whether the database loaded contains decoy sequences.
 void emptyCache()
          Empties the cache of the factory.
 HashMap<String,Integer> getAAOccurrences(JProgressBar progressBar)
          Returns the occurrence of every amino acid in the database.
 ArrayList<String> getAccessions()
          Returns the sequences present in the database.
 File getCurrentFastaFile()
          Returns the currently loaded fasta file.
 FastaIndex getCurrentFastaIndex()
          Returns the fasta index of the currently loaded file.
static String getDecoyFlag(String proteinAccession)
          Returns the default tag matched in the sequence if any.
static String getDefaultDecoyAccession(String targetAccession)
          Returns the default decoy accession for a target accession.
static String getDefaultDecoyAccessionSuffix()
          Returns the default suffix for a decoy accession.
static String getDefaultDecoyDescription(String targetDescription)
          Returns the default description for a decoy protein.
static String getDefaultTargetAccession(String decoyAccession)
          Returns the default target accession of a given decoy protein.
 String getFileName()
          Returns the name of the loaded FASTA file.
 Header getHeader(String accession)
          Returns the desired header for the protein in 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(String accession)
          Returns the desired protein.
static String getTargetDecoyFileNameTag()
          Returns the target-decoy file name tag.
static boolean isDecoy(String proteinAccession)
          Deprecated. deprecated, use the isDecoy(proteinAccession, flag) with file dependent flag or isDecoyAccession(String proteinAccession) instead.
static boolean isDecoy(String proteinAccession, String decoyFlag)
          Returns a boolean indicating whether a protein is decoy or not based on the protein accession and a given decoy flag.
 boolean isDecoyAccession(String proteinAccession)
          Indicates whether a protein is decoy in the selected loaded FASTA file.
 boolean isDefaultReversed()
          Indicates whether the decoy sequences are reversed versions of the target and the decoy accessions built based on the sequence factory methods.
 void loadFastaFile(File fastaFile)
          Loads a new FASTA file in the factory.
 void loadFastaFile(File fastaFile, WaitingHandler waitingHandler)
          Loads a new FASTA file in the factory.
static String reverseSequence(String sequence)
          Reverses a protein sequence.
 void saveIndex()
          Saves the index.
 void setnCache(int nCache)
          Sets the size of the cache.
static void setTargetDecoyFileNameTag(String targetDecoyFileNameTag)
          Set the target-decoy file name tag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

clearFactory

public void clearFactory()
                  throws IOException
Clears the factory getInstance() needs to be called afterwards.

Throws:
IOException

emptyCache

public void emptyCache()
Empties the cache of the factory.


getProtein

public Protein getProtein(String accession)
                   throws IOException,
                          IllegalArgumentException,
                          InterruptedException,
                          FileNotFoundException,
                          ClassNotFoundException
Returns the desired protein. If the protein is not found, the database will be re-indexed.

Parameters:
accession - accession of the desired protein
Returns:
the desired protein
Throws:
IOException - thrown whenever an error is encountered while reading the FASTA file
IllegalArgumentException - thrown whenever an error is encountered while reading the FASTA file
InterruptedException
FileNotFoundException
ClassNotFoundException

getHeader

public Header getHeader(String accession)
                 throws IOException,
                        IllegalArgumentException,
                        InterruptedException,
                        FileNotFoundException,
                        ClassNotFoundException
Returns the desired header for the protein in the FASTA file.

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

loadFastaFile

public void loadFastaFile(File fastaFile)
                   throws FileNotFoundException,
                          IOException,
                          ClassNotFoundException,
                          StringIndexOutOfBoundsException,
                          IllegalArgumentException
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:
FileNotFoundException - exception thrown if the file was not found
IOException - exception thrown if an error occurred while reading the FASTA file
ClassNotFoundException - exception thrown whenever an error occurred while deserializing the file index
StringIndexOutOfBoundsException - thrown if issues occur during the parsing of the protein headers
IllegalArgumentException - if non unique accession numbers are found

loadFastaFile

public void loadFastaFile(File fastaFile,
                          WaitingHandler waitingHandler)
                   throws FileNotFoundException,
                          IOException,
                          ClassNotFoundException,
                          StringIndexOutOfBoundsException,
                          IllegalArgumentException
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
waitingHandler - a waitingHandler showing the progress
Throws:
FileNotFoundException - exception thrown if the file was not found
IOException - exception thrown if an error occurred while reading the FASTA file
ClassNotFoundException - exception thrown whenever an error occurred while deserializing the file index
StringIndexOutOfBoundsException - thrown if issues occur during the parsing of the protein headers
IllegalArgumentException - if non unique accession numbers are found

saveIndex

public void saveIndex()
               throws IOException
Saves the index.

Throws:
IOException

closeFile

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

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

isDecoy

public static boolean isDecoy(String proteinAccession,
                              String decoyFlag)
Returns a boolean indicating whether a protein is decoy or not based on the protein accession and a given decoy flag.

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

getDecoyFlag

public static String getDecoyFlag(String proteinAccession)
Returns the default tag matched in the sequence if any. Null else.

Parameters:
proteinAccession - the protein accession
Returns:
the decoy tag matched by this protein

isDecoyAccession

public boolean isDecoyAccession(String proteinAccession)
Indicates whether a protein is decoy in the selected loaded FASTA file.

Parameters:
proteinAccession - the protein accession of interest.
Returns:
true if decoy

isDecoy

public static boolean isDecoy(String proteinAccession)
Deprecated. deprecated, use the isDecoy(proteinAccession, flag) with file dependent flag or isDecoyAccession(String proteinAccession) instead.

Indicates whether a protein accession is decoy according to the standard decoy flags.

Parameters:
proteinAccession - the accession of interest
Returns:
true if decoy

concatenatedTargetDecoy

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

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

isDefaultReversed

public boolean isDefaultReversed()
Indicates whether the decoy sequences are reversed versions of the target and the decoy accessions built based on the sequence factory methods. See getDefaultDecoyAccession(String targetAccession).

Returns:
true if the the decoy sequences are reversed versions of the target and the decoy accessions built based on the sequence factory method

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(File destinationFile)
                          throws IOException,
                                 IllegalArgumentException,
                                 InterruptedException,
                                 FileNotFoundException,
                                 ClassNotFoundException
Appends decoy sequences to the desired file.

Parameters:
destinationFile - the destination file
Throws:
IOException - exception thrown whenever an error occurred while reading or writing a file
IllegalArgumentException
InterruptedException
FileNotFoundException
ClassNotFoundException

appendDecoySequences

public void appendDecoySequences(File destinationFile,
                                 WaitingHandler waitingHandler)
                          throws IOException,
                                 IllegalArgumentException,
                                 InterruptedException,
                                 FileNotFoundException,
                                 ClassNotFoundException
Appends decoy sequences to the desired file while displaying progress.

Parameters:
destinationFile - the destination file
waitingHandler - the waiting handler
Throws:
IOException - exception thrown whenever an error occurred while reading or writing a file
IllegalArgumentException - exception thrown whenever a protein is not found
InterruptedException
FileNotFoundException
ClassNotFoundException

reverseSequence

public static String reverseSequence(String sequence)
Reverses a protein sequence.

Parameters:
sequence - the protein sequence
Returns:
the reversed protein sequence

getAccessions

public ArrayList<String> getAccessions()
Returns the sequences present in the database. An empty list if no file is loaded.

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 HashMap<String,Integer> getAAOccurrences(JProgressBar progressBar)
                                         throws IOException,
                                                IllegalArgumentException,
                                                InterruptedException,
                                                FileNotFoundException,
                                                ClassNotFoundException
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:
IOException - exception thrown whenever an error occurred while reading the database
IllegalArgumentException
InterruptedException
FileNotFoundException
ClassNotFoundException

computeMolecularWeight

public double computeMolecularWeight(String accession)
                              throws IOException,
                                     IllegalArgumentException,
                                     InterruptedException,
                                     FileNotFoundException,
                                     ClassNotFoundException
Returns the protein's molecular weight.

Parameters:
accession - the protein's accession number
Returns:
the protein's molecular weight
Throws:
IOException
IllegalArgumentException
InterruptedException
FileNotFoundException
ClassNotFoundException

getTargetDecoyFileNameTag

public static String getTargetDecoyFileNameTag()
Returns the target-decoy file name tag.

Returns:
the targetDecoyFileNameTag

setTargetDecoyFileNameTag

public static void setTargetDecoyFileNameTag(String targetDecoyFileNameTag)
Set the target-decoy file name tag.

Parameters:
targetDecoyFileNameTag - the targetDecoyFileNameTag to set

getFileName

public String getFileName()
Returns the name of the loaded FASTA file. Null if none loaded.

Returns:
the name of the loaded FASTA file

getCurrentFastaFile

public File getCurrentFastaFile()
Returns the currently loaded fasta file.

Returns:
the currently loaded fasta file

getDefaultDecoyAccessionSuffix

public static String getDefaultDecoyAccessionSuffix()
Returns the default suffix for a decoy accession.

Returns:
the default suffix for a decoy accession

getDefaultDecoyAccession

public static String getDefaultDecoyAccession(String targetAccession)
Returns the default decoy accession for a target accession.

Parameters:
targetAccession - the target accession
Returns:
the default decoy accession

getDefaultDecoyDescription

public static String getDefaultDecoyDescription(String targetDescription)
Returns the default description for a decoy protein.

Parameters:
targetDescription - the description of a target protein
Returns:
the default description of the decoy protein

getDefaultTargetAccession

public static String getDefaultTargetAccession(String decoyAccession)
Returns the default target accession of a given decoy protein. Note: works only for the accessions constructed according to getDefaultDecoyAccession(String targetAccession).

Parameters:
decoyAccession - the decoy accession
Returns:
the target accession

getCurrentFastaIndex

public FastaIndex getCurrentFastaIndex()
Returns the fasta index of the currently loaded file.

Returns:
the fasta index of the currently loaded file


Copyright © 2013. All Rights Reserved.