-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_redondant_contigs.py
executable file
·56 lines (45 loc) · 1.44 KB
/
find_redondant_contigs.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python
"""
User Commands
SYNOPSIS:
Takes a blast+ output (format 6) from a blast of the contigs
on the same contigs and creates an output file with the names
of the contigs that blast against other ones. It returns a
list of "redundant" contigs with the contigs to which they
blast.
In other words, it verifies if there is contigs that are very
similar in a file of many apparently different contigs (from a
de novo assembly for example).
USAGE:
%program <blast_fmt_6> <output_redundant_contigs>
CREDITS:
Doctor Pants 2012 \m/
"""
import sys
try:
blast_input = open(sys.argv[1], "rU")
list_output = sys.argv[2]
except:
print __doc__
sys.exit(1)
contigs = []
redundant = {}
for line in blast_input:
line = line.strip()
if line != "":
contig = line.split()[0]
if contig in contigs:
asso_contig = line.split()[1]
if contig in redundant:
redundant[contig].append(asso_contig)
else:
redundant[contig] = []
redundant[contig].append(asso_contig)
else:
contigs.append(contig)
with open(list_output, "w") as out_f:
for prim_contig in redundant:
out_f.write(prim_contig)
for sec_contig in redundant[prim_contig]:
out_f.write("\t" + sec_contig)
out_f.write("\n")