-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsto2fasta.py
executable file
·36 lines (28 loc) · 1.01 KB
/
sto2fasta.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Simple utility script heavily based on Biopython used to convert .sto files to .fasta alignment format.
"""
__author__ = "Jakub Barylski"
__maintainer__ = "Jakub Barylski"
__license__ = "GNU GENERAL PUBLIC LICENSE"
__email__ = "[email protected]"
from pathlib import Path
import click
from Bio import SeqIO
@click.command(no_args_is_help=True)
@click.option("-s", "--stockholm",
required=True,
type=click.Path(exists=True, path_type=Path),
help='stockholm (sto) alignment file to convert')
def convert_and_save(stockholm: Path):
"""
Convert stockholm file to fasta format and write to a new file in the same directory
Usage example: sto2fasta.py -s alignment.sto
"""
out_file = stockholm.with_suffix('.fasta')
records = SeqIO.parse(stockholm, "stockholm")
SeqIO.write(records, out_file, "fasta")
print(f'Fasta file written to {out_file}')
if __name__ == '__main__':
convert_and_save()