tfasta
Introduction
The tfasta python package simplifies working with fasta, providing functionality for both reading and writing fasta files. The “t” in “tfasta” represents “templated”, which means that fasta parsing is performed according to pre-defined or user-defined templates:
>>> from tfasta import fasta_parser, T_NR
>>> fast = fasta_parser("cytb.fas", template=T_NR)
>>> f = fast.next()
>>> print f['gi']
5524211
>>> print f['accession']
AAD44166.1
>>> print f['sequence'][:60]
LCLYTHIGRNIYYGSYLYSETWNTGIMLLLITMATAFMGYVLPWGQMSFWGATVITNLFS
This example parses records that follow the conventions of the NCBI non-redundant database (nr).
More examples are given in the tfasta full documentation.
Installation
Install tfasta with pip (recommended) or easy_install:
sudo pip install tfasta
Optionally, download the source files from http://pypi.python.org/pypi/tfasta/ and run the following commands in the source directory:
python setup.py build sudo python setup.py install
Home Page & Repository
Home Page: http://pypi.python.org/pypi/tfasta/
Documentation: http://pythonhosted.org/tfasta/
Repository: https://github.com/jcstroud/tfasta/
Basic Usage
Reading Fasta Files
Reading fasta files is performed with the fasta_parser() function. The following text is the first 2 records from a file called “short-extended.fas”:
>gi|32033604|ref|ZP_00133915.1| ATGQVIGTFTVRNDNGLHARPSAVLVQTLKPFAAKVTVENLDRGTAPANAKSTMKVVALG ASQAHRLRFVAEGEDAQQAIEALAKAFVEGLGESVSFVPAVEDTIEGAAQPQAVESAKNF ANPTASEPTVEGQVEGTFVIQNEHGLHARPSAVLVNEVKKYNATIVVQNLDRNTQLVSAK SLMKIVALGVVKGHRLHFVATGDDAQKAIDGIGEAIAAGLGE >gi|1573424|gb|AAC22107.1| VEGAVVGTFTIRNEHGLHARPSANLVNEVKKFTSKITMQNLTRESEVVSAKSLMKIVALG VTQGHRLRFVAEGEDAKQAIESLGKAIANGLGENVSAVPPSEPDTIEIMGDQIHTPAVTE DDNLPANAIEAVFVIKNEQGLHARPSAILVNEVKKYNASVAVQNLDRNSQLVSAKSLMKI VALGVVKGTRLRFVATGEEAQQAIDGIGAVIESGLGE
Like any other fasta file, short-extended.fas may be parsed with a single command:
fast = fasta_parser(file_name)
For example:
>>> from tfasta import fasta_parser
>>> fast = fasta_parser("short-extended.fas")
>>> f = fast.next()
>>> print f['name']
gi|32033604|ref|ZP_00133915.1|
>>> print f['sequence'][:60]
ATGQVIGTFTVRNDNGLHARPSAVLVQTLKPFAAKVTVENLDRGTAPANAKSTMKVVALG
f = fast.next()
print f['name']
gi|1573424|gb|AAC22107.1|
In this example, the fasta_parser() function returns an iterator of dictionaries (”fast”) with two keys: name and sequence. The name key corresponds to all of the plain text after the fasta format marker “>” that marks a new sequence.
Iteration
The iterator returned by the fasta_parser() function may serve in for loops:
>>> from tfasta import fasta_parser
>>> for f in fasta_parser("short-extended.fas"):
... print f['name']
gi|32033604|ref|ZP_00133915.1|
gi|1573424|gb|AAC22107.1|
[...]
Other Usage
See the tfasta full documentation for more sophisticated reading and writing of fasta.
Metadata
Release files for tfasta 0.3.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tfasta-0.3.4.tar.gz | 122.9 kB | Without provenance | Details for tfasta-0.3.4.tar.gz |
Release files / tfasta-0.3.4.tar.gz
| Download URL | tfasta-0.3.4.tar.gz |
|---|---|
| Size | 122.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
30d9de9ccbd028cfbd8ebadc0487ecd40d8e535f4287bf5829cc0eeba90b79b1
|
|
BLAKE2b-256 checksum How to use checksums |
ba5eb1d8abdac8bff59e0db7ad0c4f8cfd0edf57bd812e98aa26869adab00265
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for tfasta 0.3.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.