An easy FASTA object handler, reader, writer and translator for small to medium size projects without dependencies.

Overview

miniFASTA

An easy FASTA object handler, reader, writer and translator for small to medium size projects without dependencies.

Test Badge Download Badge

Installation

Using pip / pip3:

pip install miniFasta

Or by source:

git clone [email protected]:not-a-feature/miniFASTA.git
cd miniFASTA
pip3 install .

How to use

miniFASTA offers easy to use functions for fasta handling. The five main parts are:

  • fasta_object()
  • read_fasta()
  • write_fasta()
  • translate_seq()
  • reverse_comp()

fasta_object()

The core component of miniFASTA is the fasta_object(). This object represents an entry in a FASTA file and consists of a head and body.

Atlantic dolphin", "CGGCCTTCTATCTTCTTC") print(fo.head) # >Atlantic dolphin print(fo.body) # CGGCCTTCTATCTTCTTC">
from miniFasta import miniFasta as fasta
fo = fasta.fasta_object(">Atlantic dolphin", "CGGCCTTCTATCTTCTTC")
print(fo.head) # >Atlantic dolphin
print(fo.body) # CGGCCTTCTATCTTCTTC

Following functions are defined on a fasta_object():

str()

str(fo) # will return:
# >Atlantic dolphin
# CGGCCTTCTATCTTCTTC

len()

len(fo) # will return 18, the length of the body

==

Same Body", "CGGCCTTCTATCTTCTTC") print(fo == fo_b) # True fo_c = fasta.fasta_object(">Different Body", "ZZZZAGCTAG") print(fo == fo_c) # False">
print(fo == fo) # True

fo_b = fasta.fasta_object(">Same Body", "CGGCCTTCTATCTTCTTC")
print(fo == fo_b) # True

fo_c = fasta.fasta_object(">Different Body", "ZZZZAGCTAG")
print(fo == fo_c) # False

toAmino(translation_dict)

Translates the body to an amino-acid sequence. See tranlate_seq() for more details.

fo.toAmino() 
print(fo.body) # Will return RPSIFF
d = {"CCG": "Z", "CTT": "A" ...}
fo.toAmino(d) 
print(fo.body) # Will return ZA...

toRevComp(complement_dict)

Converts the body to its reverse comlement. See reverse_comp() for more details.

fo.toRevComp() 
print(fo.body) # Will return GAAGAAGATAGAAGGCCG

Reading FASTA files

read_fasta() is a basic fasta reader. It reads a fasta-style file and returns a list of fasta_objects. The entries are usually casted to upper case letters. Set read_fasta("path.fasta", upper=False) to disable casting.

fos = fasta.read_fasta("dolphin.fasta") # List of fasta entries
fos = fasta.read_fasta("cat.fasta", upper=False)

Writing FASTA files

write_fasta() is a basic fasta reader. It takes a single or a list of fasta_objects and writes it to the given path.

The file is usually overwritten. Set write_fasta(fo, "path.fasta", mode="a") to append file.

fos = fasta.read_fasta("dolphin.fasta") # List of fasta entries
fasta.write_fasta(fos, "new.fasta")

Sequence translation

translate_seq() translates a sequence starting at position 0. Unless translation_dict is provided, the standart bacterial code is used. If the codon was not found, it will be replaced by an ~. Tailing bases that do not fit into a codon will be ignored.

fasta.translate_seq("CGGCCTTCTATCTTCTTC") # Will return RPSIFF

d = {"CGG": "Z", "CTT": "A"}
fasta.translate_seq("CGGCTT", d) # Will return ZA.

Reverse Complement

reverse_comp() converts a sequence to its reverse comlement. Unless complement_dict is provided, the standart complement is used. If no complement was found, the nucleotide remains unchanged.

fasta.reverse_comp("CGGCCTTCTATCTTCTTC") # Will return GAAGAAGATAGAAGGCCG

d = {"C": "Z", "T": "Y"}
fasta.reverse_comp("TC", d) # Will return ZY
You might also like...
Data Structures and Algorithms Python - Practice data structures and algorithms in python with few small projects

Data Structures and Algorithms All the essential resources and template code nee

Master Duel Card Translator Project

Master Duel Card Translator Project A tool for translating card effects in Yu-Gi-Oh! Master Duel. Quick Start (for Chinese version only) Download the

Python 3.9.4 Graphics and Compute Shader Framework and Primitives with no external module dependencies
Python 3.9.4 Graphics and Compute Shader Framework and Primitives with no external module dependencies

pyshader Python 3.9.4 Graphics and Compute Shader Framework and Primitives with no external module dependencies Fully programmable shader model (even

Beginner Projects A couple of beginner projects here

Beginner Projects A couple of beginner projects here, listed from easiest to hardest :) selector.py: simply a random selector to tell me who to faceti

Small projects for python beginners.

Python Mini Projects For Beginners I recently started doing the #100DaysOfCode Challenge in Python. I've used Python before, but I had switched to JS

poetry2nix turns Poetry projects into Nix derivations without the need to actually write Nix expressions

poetry2nix poetry2nix turns Poetry projects into Nix derivations without the need to actually write Nix expressions. It does so by parsing pyproject.t

edgetest is a tox-inspired python library that will loop through your project's dependencies, and check if your project is compatible with the latest version of each dependency

Bleeding edge dependency testing Full Documentation edgetest is a tox-inspired python library that will loop through your project's dependencies, and

Feature engineering library that helps you keep track of feature dependencies, documentation and schema

Feature engineering library that helps you keep track of feature dependencies, documentation and schema

Identify unused production dependencies and avoid a bloated virtual environment.

creosote Identify unused production dependencies and avoid a bloated virtual environment. Quickstart # Install creosote in separate virtual environmen

Comments
Releases(v3.0.2)
  • v3.0.2(Nov 8, 2022)

    What's Changed

    • Add support of py3.11 and update gh actions by @not-a-feature in https://github.com/not-a-feature/miniFASTA/pull/22

    Full Changelog: https://github.com/not-a-feature/miniFASTA/compare/v3.0.1...v3.0.2

    Source code(tar.gz)
    Source code(zip)
  • v3.0.1(Oct 12, 2022)

    What's Changed

    • Update README.md by @not-a-feature in https://github.com/not-a-feature/miniFASTA/pull/18
    • Merge by @not-a-feature in https://github.com/not-a-feature/miniFASTA/pull/19
    • switch to iterator by @not-a-feature in https://github.com/not-a-feature/miniFASTA/pull/20
    • Add dataclass decorator by @not-a-feature in https://github.com/not-a-feature/miniFASTA/pull/21

    Full Changelog: https://github.com/not-a-feature/miniFASTA/compare/v2.4.1...v3.0.1

    Source code(tar.gz)
    Source code(zip)
  • v2.4.1(Sep 24, 2022)

    What's Changed

    • add py3.7 support by @not-a-feature in https://github.com/not-a-feature/miniFASTA/pull/17

    Full Changelog: https://github.com/not-a-feature/miniFASTA/compare/v2.4.0...v2.4.1

    Source code(tar.gz)
    Source code(zip)
  • v2.4.0(Jul 4, 2022)

    What's Changed

    • Update README.md by @not-a-feature in https://github.com/not-a-feature/miniFASTA/pull/15
    • add option to read only the body by @not-a-feature in https://github.com/not-a-feature/miniFASTA/pull/16

    Full Changelog: https://github.com/not-a-feature/miniFASTA/compare/v2.3.2...v2.4.0

    Source code(tar.gz)
    Source code(zip)
  • v2.3.2(Mar 11, 2022)

    What's Changed

    • Black code formatting by @not-a-feature in https://github.com/not-a-feature/miniFASTA/pull/14

    Full Changelog: https://github.com/not-a-feature/miniFASTA/compare/v2.3.1...v2.3.2

    Source code(tar.gz)
    Source code(zip)
  • v2.3.1(Feb 23, 2022)

    What's Changed

    • Add type information and update readme by @not-a-feature in https://github.com/not-a-feature/miniFASTA/pull/13

    Full Changelog: https://github.com/not-a-feature/miniFASTA/compare/v2.3.0...v2.3.1

    Source code(tar.gz)
    Source code(zip)
  • v2.3.0(Feb 23, 2022)

    What's Changed

    • Dev by @not-a-feature in https://github.com/not-a-feature/miniFASTA/pull/11
    • add iter and getter methods by @not-a-feature in https://github.com/not-a-feature/miniFASTA/pull/12

    Full Changelog: https://github.com/not-a-feature/miniFASTA/compare/v2.2.1...v2.3.0

    Source code(tar.gz)
    Source code(zip)
Owner
Jules Kreuer
Jules Kreuer
Built with Python programming language and QT library and Guess the number in three easy, medium and hard rolls

password-generator Built with Python programming language and QT library and Guess the number in three easy, medium and hard rolls Password generator

Amir Hussein Sharifnezhad 3 Oct 9, 2021
A command-line utility that creates projects from cookiecutters (project templates), e.g. Python package projects, VueJS projects.

Cookiecutter A command-line utility that creates projects from cookiecutters (project templates), e.g. creating a Python package project from a Python

null 18.6k Jan 2, 2023
An assistant to guess your pip dependencies from your code, without using a requirements file.

Pip Sala Bim is an assistant to guess your pip dependencies from your code, without using a requirements file. Pip Sala Bim will tell you which packag

Collage Labs 15 Nov 19, 2022
A fluid medium for storing, relating, and surfacing thoughts.

Conceptarium A fluid medium for storing, relating, and surfacing thoughts. Read more... Instructions The conceptarium takes up about 1GB RAM when runn

null 115 Dec 19, 2022
Python project that aims to discover CDP neighbors and map their Layer-2 topology within a shareable medium like Visio or Draw.io.

Python project that aims to discover CDP neighbors and map their Layer-2 topology within a shareable medium like Visio or Draw.io.

null 3 Feb 11, 2022
Sequence clustering and database creation using mmseqs, from local fasta files

Sequence clustering and database creation using mmseqs, from local fasta files

Ana Julia Velez Rueda 3 Oct 27, 2022
Linux GUI app to codon optimize many single-fasta files with coding sequences , using many taxonomy ids

codon_optimize_cds_with_many_taxids_singlefasta Linux GUI app to codon optimize many single-fasta files with coding sequences, using many taxonomy ids

Olga Tsiouri 1 Jan 23, 2022
Penelope Shell Handler

penelope Penelope is an advanced shell handler. Its main aim is to replace netcat as shell catcher during exploiting RCE vulnerabilities. It works on

null 293 Dec 30, 2022
Architectural Patterns implementation by using notification handler module prototype

This repository covers singleton, indirection, factory, adaptor, mediator patterns in python language by using university hypothetical notification module prototype. The code is just for demonstrating the pattern implementation not modules working

Muhammad Umair 2 Jan 8, 2022
An optional component handler for hikari, inspired by discord.py's views.

hikari-miru An optional component handler for hikari, inspired by discord.py's views.

null 43 Dec 26, 2022