miniFasta package

Module contents

class miniFasta.fasta_object(head: str, body: str, stype: str = 'any')[source]

Bases: fasta_object

write(file_path: str, mode='w')[source]

Writes this fasta_object to a file.

miniFasta.print_fasta(fasta) None[source]

Prints a single or a list of fasta_objects.

miniFasta.read(file_path: str, upper: bool = True, seq: bool = False) Iterator[fasta_object] | Iterator[str][source]

Reads a compressed or non-compressed fasta file and returns a Iterator of fasta_objects. Zip, tar, gz, tar.gz files are supported. Attention: Encoding characters (backslash) will work under certain conditions.

Parameters:
  • file_path (str) – Path to folder / file.

  • upper (bool, default: True) – Cast sequences to upper-case letters.

  • seq (bool, default: False) – Return only the sequences.

Returns:
fasta_objects: Iterator

Iterator of fasta_object or Iterator of strings.

miniFasta.reverse_comp(seq: str, d={'A': 'T', 'B': 'V', 'C': 'G', 'D': 'H', 'G': 'C', 'H': 'D', 'K': 'M', 'M': 'K', 'R': 'Y', 'S': 'S', 'T': 'A', 'U': 'A', 'V': 'B', 'W': 'W', 'Y': 'R'}) str[source]

Reverses complement of sequence. If no complement was found, the nucleotides remains unchanged.

Parameters:
  • seq (str) – Sequence to compute the reverse complement.

  • d (dict) – Complement dictionary.

Returns:

rev – Translated sequence

Return type:

str

miniFasta.translate_seq(seq: str, d={'AAA': 'K', 'AAC': 'N', 'AAG': 'K', 'AAT': 'N', 'ACA': 'T', 'ACC': 'T', 'ACG': 'T', 'ACT': 'T', 'AGA': 'R', 'AGC': 'S', 'AGG': 'R', 'AGT': 'S', 'ATA': 'I', 'ATC': 'I', 'ATG': 'M', 'ATT': 'I', 'CAA': 'Q', 'CAC': 'H', 'CAG': 'Q', 'CAT': 'H', 'CCA': 'P', 'CCC': 'P', 'CCG': 'P', 'CCT': 'P', 'CGA': 'R', 'CGC': 'R', 'CGG': 'R', 'CGT': 'R', 'CTA': 'L', 'CTC': 'L', 'CTG': 'L', 'CTT': 'L', 'GAA': 'E', 'GAC': 'D', 'GAG': 'E', 'GAT': 'D', 'GCA': 'A', 'GCC': 'A', 'GCG': 'A', 'GCT': 'A', 'GGA': 'G', 'GGC': 'G', 'GGG': 'G', 'GGT': 'G', 'GTA': 'V', 'GTC': 'V', 'GTG': 'V', 'GTT': 'V', 'TAA': '*', 'TAC': 'Y', 'TAG': '*', 'TAT': 'Y', 'TCA': 'S', 'TCC': 'S', 'TCG': 'S', 'TCT': 'S', 'TGA': '*', 'TGC': 'C', 'TGG': 'W', 'TGT': 'C', 'TTA': 'L', 'TTC': 'F', 'TTG': 'L', 'TTT': 'F'}) str[source]

Translates a DNA sequence to a AA sequence. Reading frame starts at position 0, tailing bases will be ignored. Attention: Will replace triplet with ~ if not found.

To translate a fasta_object use object.toAmino()

Parameters:
  • seq (str) – Sequence to translate.

  • d (dict) – Translation dictionary.

Returns:
translated: str

Translated sequence.

miniFasta.write(fasta_pairs, file_path: str, mode='w') None[source]

Writes a list of fasta_objects or a single one to a file. Takes fasta_objects as input.

Parameters:
  • fasta_pairs (List[fasta_object] or fasta_object) – List or single fasta_object to write.

  • file_path (str) – String or FilePath to file.