fastasma
A collection of tools for working with FASTA files.
Installation
pip install fastasma
Usage
Pipeline example
import fastasma
source = fastasma.ImportFasta("input.fasta")
source = fastasma.DropAnnotationKeys(source, keys_to_remove=["length"])
source = fastasma.AddAnnotationToHeader(source, annotation_key="organism", position="suffix")
source = fastasma.FilterByLen(source, is_="greater", length=200)
source = fastasma.DeduplicateHeaders(source, separator="_")
source = fastasma.Head(source, n=10)
fastasma.WriteFasta(source, output_path="output.fasta")
Modules
Importers
Read sequences from files or directories.
| Class | Description |
|---|---|
ImportFasta(filepath) |
Reads a single FASTA file. Parses header annotations in [key=value] format. |
ImportFastas(filepaths=None, directory=None) |
Reads multiple FASTA files from a list or directory. |
ImportTSV(filepath, header_idx=0, seq_idx=1, annotation_idx=None, header=True) |
Reads sequences from a TSV file with configurable column indices. |
Annotators
Modify sequence annotations or headers.
| Class | Description |
|---|---|
DropAnnotations(source) |
Removes all annotations from every sequence. |
DropAnnotationKeys(source, keys_to_remove) |
Removes specific annotation keys by name. |
AddTaxonomyFromFilename(source, key, header_formatter=None) |
Extracts a taxon from the source filename and adds it to the header. |
AddTaxidFromName(source, taxonomy_db, organism_field="organism") |
Looks up organism names in a SQLite taxonomy DB and adds the corresponding taxid. |
AddNameFromTaxid(source, taxonomy_db, taxid_field="taxid", name_field="organism") |
Converts taxid values to scientific names using a taxonomy DB. |
AddTaxonomicRankFromTaxid(source, taxonomy_db, taxid_field="taxid", rank="species") |
Traverses NCBI taxonomy tree to find a given rank (e.g., "order") for each taxid. |
AddAnnotationToHeader(source, annotation_key, separator="_", position="suffix") |
Adds an annotation value as prefix or suffix to the sequence header. |
Mutators
Filter, sample, rename, or transform the sequence stream.
| Class | Description |
|---|---|
Head(source, n) |
Yields the first n sequences. |
Tail(source, n) |
Yields the last n sequences. |
Sample(source, k, seed=None) |
Randomly samples k sequences using reservoir sampling. |
DeduplicateHeaders(source, separator="_", position="suffix", start=1) |
Renames duplicate headers by appending a counter (e.g., seq01, seq01_1, seq01_2). |
FilterByLen(source, is_, length) |
Filters sequences by length. is_ can be "greater", "greater_equal", "less", "less_equal", or "equal". |
Writers
Write sequences to output files or databases.
| Class | Description |
|---|---|
WriteFasta(source, output_path, wrap=80) |
Writes sequences to a FASTA file with configurable line wrapping. |
WriteTSV(source, output_path, sep="\t") |
Writes sequences to a TSV file with annotations as columns. |
WriteDB(source, db_path) |
Writes sequences to a SQLite database with normalized annotation tables. |
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastasma-0.1.5.tar.gz
(10.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
fastasma-0.1.5-py3-none-any.whl
(11.2 kB
view details)
File details
Details for the file fastasma-0.1.5.tar.gz.
File metadata
- Download URL: fastasma-0.1.5.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbe42c9985bcd6741b9d3610a0ecf4b89ffd58d41bf177a0ade4725f18490905
|
|
| MD5 |
a907ea7dd6c14bdd3531d069fadf352d
|
|
| BLAKE2b-256 |
e712e8652c3379b0471a62a20735f51841f4dd8815dafa037c6369b9d7c126f0
|
File details
Details for the file fastasma-0.1.5-py3-none-any.whl.
File metadata
- Download URL: fastasma-0.1.5-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d75acbd40ee2daae95648dbf58ff32bcd2edc4947d6c6fc136b0627b9953baa
|
|
| MD5 |
fe4358919f600dab3db6245b59ec9b1e
|
|
| BLAKE2b-256 |
2f87cd6ce5432247728abce36dcd2fd4c66bfe93df1bc2b61525826c9ac7e6a4
|