-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_for_overlapping_seqs_in_fastas.py
More file actions
46 lines (42 loc) · 1.08 KB
/
check_for_overlapping_seqs_in_fastas.py
File metadata and controls
46 lines (42 loc) · 1.08 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
46
import os
import sys
from Bio import SeqIO
directory = (sys.argv[1]) #PATH to Directory
filelist = []
donelist = []
mergelist = []
for filename in os.listdir(directory):
if "fasta" in filename:
filelist.append(directory+filename)
else:
pass
for file1 in filelist:
for file2 in filelist:
if file1 == file2:
pass
else:
thisround = []
thisround.append(file1)
thisround.append(file2)
thisround.sort()
if thisround in donelist:
pass
else:
donelist.append(thisround)
total = []
overlap = []
with open(file1, 'r') as fa1:
for rec1 in SeqIO.parse(fa1, "fasta"):
total.append(rec1.id)
with open(file2, 'r') as fa2:
for rec2 in SeqIO.parse(fa2, "fasta"):
if rec2.id in total:
overlap.append(rec2.id)
else:
total.append(rec2.id)
#print(len(total))
perc_overlap = len(overlap)/len(total)*100
if perc_overlap == 0:
pass
else:
print(file1.split('/')[-1] + " and " + file2.split('/')[-1] + " share " + str(len(overlap)) + " sequences for a total of " + str("%.2f" % perc_overlap) + "%" )