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

Module _tfasta

source code

A module that does stuff with fasta files.

The most useful methods are:

See tfasta_templates documentation for supported fasta file types.

Functions [hide private]
 
fasta_parser(filename, template=None, greedy=None, dogaps=False)
Given a filename, returns an iterator that will iterate 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-'
  fastaname = sys.argv [1]
  fastype = sys.argv [2]
  template = TEMPLATES [fastype]
  __package__ = 'tfasta'
Function Details [hide private]

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

source code 

Given a filename, returns an iterator that will iterate 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

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