-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_logos.py
42 lines (34 loc) · 1.14 KB
/
make_logos.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
37
38
39
40
41
42
"""
Make sequence logos from alignment files.
"""
import glob
from Bio.Align import MultipleSeqAlignment
from Bio import AlignIO
import logomaker
import pandas as pd
import matplotlib.pyplot as plt
def make_logo(alignment: MultipleSeqAlignment, output_file: str):
freqs = alignment.alignment.frequencies
matrix = pd.DataFrame.from_dict(freqs, orient="index").T
matrix = matrix[["A", "C", "G", "T"]]
fig, ax = plt.subplots(1, 1, figsize=[matrix.shape[0] / 7, 2])
# Remove axis and labels
ax.axis("off")
logomaker.Logo(matrix, ax=ax)
plt.savefig(output_file)
def main(alignment_files: list[str]):
for alignment_file in alignment_files:
alignment = AlignIO.read(alignment_file, "clustal")
output_file = alignment_file[:-4] + ".svg"
make_logo(alignment, output_file)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"--alignment-files",
nargs="+",
help="List of alignment files to process",
default=glob.glob("results/alignment/*.clu"),
)
args = parser.parse_args()
main(args.alignment_files)