-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrepseq_genomad_annotations.py
More file actions
executable file
·45 lines (35 loc) · 1.24 KB
/
repseq_genomad_annotations.py
File metadata and controls
executable file
·45 lines (35 loc) · 1.24 KB
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
43
44
45
#!/usr/bin/env python3
"""
Right now this script is slow. Will speed up later.
"""
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("votutable", help="vOTU table")
parser.add_argument("filelist", help="file containing list of sample genomad virus_summary.tsv files (one per line) from which to get the repseq annotations. sample name should be prefix")
args = parser.parse_args()
def read_summary(infile, repseqs):
"""reads in summary file and prints repseq lines
infile: *virus_summary.tsv file
repseqs: set of rep seqs to look for
"""
with open(infile, 'r') as f:
for line in f:
s = line.split()[0]
if s in repseqs:
print(line, end='')
## make set of repseqs
with open(args.votutable, 'r') as vt:
samples = vt.readline().rstrip().split()
samples = set(samples[1:])
repseqs = set()
for line in vt:
rep = line.split()[0]
repseqs.add(rep)
## get list of genomad virus summary files
with open(args.filelist, 'r') as fl:
files = fl.read().splitlines()
## print header
with open(files[0], 'r') as f:
print(f.readline(), flush=True, end="")
## go through summary files and print matching lines
[read_summary(x, repseqs) for x in files]