Package tfasta :: Module _tfasta
[hide private]
[frames] | no frames]

Module _tfasta

source code

tfasta: reading and writing of fast files

This is automatically generated documentation and should not be relied on for the API. Please see the official documentation at http://pythonhosted.org/tfasta/.

The most useful functions are:

See tfasta_templates documentation for supported fasta file types.

Functions [hide private]
 
io_fasta_parser(fastafile, template=None, dogaps=False)
Helper generator function for fasta_parser and string_fasta_parser.
source code
 
fasta_parser(filename, template=None, greedy=None, dogaps=False)
Given a filename, returns an iterator that iterates over the fasta file.
source code
 
string_fasta_parser(astr, template=None, dogaps=False)
Given astr (string of fasta), returns an iterator that iterates over the fasta file.
source code
str
make_fasta_from_dict(adict, width=60)
Give it a dict of sequences keyed by name of the sequence and it returns a fasta representation as a str.
source code
str
make_fasta(name, seq, width=60)
Give it a sequence name and a sequence (seq) and it returns a fasta representation as a str.
source code
bool
test_parser(template, filename)
Tests for proper construction of a parser using template or of the fasta file named filename.
source code
Variables [hide private]
  T_DEF = TEMPLATES ['default']
  T_SWISS = TEMPLATES ['swissprot']
  T_PDB = TEMPLATES ['pdb']
  T_NR = TEMPLATES ['nr']
  T_NRBLAST = TEMPLATES ['nrblast']
int FASTA_WIDTH = 60
default width of fasta sequences
  CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-'
  __package__ = 'tfasta'
Function Details [hide private]

io_fasta_parser(fastafile, template=None, dogaps=False)

source code 

Helper generator function for fasta_parser and string_fasta_parser.

Given fastafile (file-like object, open for reading), returns an iterator that iterates over the fasta file. It will yield dictionaries keyed according to the fields in template. These dictionaries will all also include a sequence keyed by "sequence".

Parameters:
  • fastafile - file-like object containing fasta text, opened for reading
  • template (FastaTemplate) - instance of FastaTemplate class--choose from TEMPLATES or define your own.
  • dogaps - a bool specifying whether to keep "-" in the sequence after parsing the file
    • if False, then gaps are ignored
    • handy if processing an alignment

fasta_parser(filename, template=None, greedy=None, dogaps=False)

source code 

Given a filename, returns an iterator that iterates over the fasta file. It will yield dictionaries keyed according to the fields in template. These dictionaries will all also include a sequence keyed by "sequence". Yielding dictionaries allows for flexibility in the types of fasta files parsed.

File format testing is not done, so make sure its a fasta file.

Parameters:
  • filename (str) - name of the fasta file
  • template (FastaTemplate) - instance of FastaTemplate class--choose from TEMPLATES or define your own.
  • greedy (bool) - a bool specifying whether to read the whole fasta file in at once. Set to True for many smaller files or to False for a few or one REALLY big ones.
  • dogaps - a bool specifying whether to keep "-" in the sequence after parsing the file
    • if False, then gaps are ignored
    • handy if processing an alignment

string_fasta_parser(astr, template=None, dogaps=False)

source code 

Given astr (string of fasta), returns an iterator that iterates over the fasta file. It will yield dictionaries keyed according to the fields in template. These dictionaries will all also include a sequence keyed by "sequence". Yielding dictionaries allows for flexibility in the types of fasta files parsed.

This function will do its best to remove unneeded whitespace, including line breaks.

Beyond simple extra whitespace, the `astr` should be properly formatted fasta text.

Parameters:
  • astr (str) - fasta text
  • template (FastaTemplate) - instance of FastaTemplate class--choose from TEMPLATES or define your own.
  • dogaps - a bool specifying whether to keep "-" in the sequence after parsing the file
    • if False, then gaps are ignored
    • handy if processing an alignment

make_fasta_from_dict(adict, width=60)

source code 

Give it a dict of sequences keyed by name of the sequence and it returns a fasta representation as a str.

Parameters:
  • adict (dict) - dict of sequences keyed by name
Returns: str
fasta representation of sequences as a str

make_fasta(name, seq, width=60)

source code 

Give it a sequence name and a sequence (seq) and it returns a fasta representation as a str.

Parameters:
  • name (str) - name of sequence
  • seq (str) - sequence as a str
Returns: str
a string representation of a fasta record

test_parser(template, filename)

source code 

Tests for proper construction of a parser using template or of the fasta file named filename.

Parameters:
  • template (FastaTemplate) - FastaTemplate describing fasta record
  • filename (str) - name of fasta file
Returns: bool
True if it works.
Raises:
  • Exception - raises Exception if fasta file is malformed or if the template didn't work