-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathnonRedundantResolver.py
61 lines (39 loc) · 2.05 KB
/
nonRedundantResolver.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
57
58
59
60
61
import os
import alignerRobot
import IORobot
import houseKeeper
# ## 0) Preprocess by removing embedded contigs (I: contigs.fasta ; O : noEmbed.fasta)
def removeEmbedded(folderName , mummerLink):
print "removeEmbedded"
thres = 10
command= r'''perl -pe 's/>[^\$]*$/">Seg" . ++$n ."\n"/ge' ''' + folderName + "raw_reads.fasta > " + folderName + houseKeeper.globalReadName
os.system(command)
command= r'''perl -pe 's/>[^\$]*$/">Seg" . ++$n ."\n"/ge' ''' + folderName + "contigs.fasta > " + folderName + houseKeeper.globalContigName
os.system(command)
if True:
alignerRobot.useMummerAlignBatch(mummerLink, folderName, [["self", houseKeeper.globalContigName, houseKeeper.globalContigName, ""]], houseKeeper.globalParallel)
# alignerRobot.useMummerAlign(mummerLink, folderName, "self", "contigs.fasta", "contigs.fasta")
# outputName, referenceName, queryName, specialName
dataList = alignerRobot.extractMumData(folderName, "selfOut")
dataList = alignerRobot.transformCoor(dataList)
lenDic = IORobot.obtainLength(folderName, houseKeeper.globalContigName)
removeList = []
for eachitem in dataList:
match1, match2, name1, name2 = eachitem[4], eachitem[5], eachitem[7], eachitem[8]
if name1 != name2:
l1, l2 = lenDic[name1], lenDic[name2]
if abs(l1 - match1) < thres and abs(l2 - match2) > thres:
removeList.append(name1)
elif abs(l1 - match1) > thres and abs(l2 - match2) < thres:
removeList.append(name2)
elif abs(l1 - match1) < thres and abs(l2 - match2) < thres:
print "Both shortembedd", eachitem
nameList = []
for eachitem in lenDic:
nameList.append(eachitem)
print len(nameList)
for eachitem in removeList:
if eachitem in nameList:
nameList.remove(eachitem)
print len(nameList)
IORobot.putListToFileO(folderName, houseKeeper.globalContigName, "noEmbed", nameList)