forked from APDLS/CVLFilter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCVLFilter.py
36 lines (31 loc) · 952 Bytes
/
CVLFilter.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
import sys
from sys import argv
if len(argv)==4:
File=argv[1]
with open(File) as infile:
data=infile.readlines()
length=argv[2]
coverage=argv[3]
else:
File=raw_input("Enter the name of the scaffolds/contig input file: ")
with open(File) as infile:
data=infile.readlines()
length=input("Enter the minimum contig length to retain: ")
print "retaining contigs of length "+str(length)+" and up"
coverage=input("Enter the minimum contig coverage to retain: ")
print "retaining contigs of coverage "+str(coverage)+" and up"
outfile=open(File.replace(".fasta","_filtered.fasta"),"w")
x=0
print "Working..."
while x < len(data):
if ">" in data[x]:
stats=data[x].split("_")
if int(stats[3]) >= int(length) and float(stats[5]) >= float(coverage):
outfile.write(data[x])
while ">" not in data[x+1]:
x=x+1
outfile.write(data[x])
x=x+1
print "Done"
print "Filtered scaffolds output to the file: "+str(outfile)
outfile.close()