-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPanlineal.py
127 lines (102 loc) · 5.04 KB
/
Panlineal.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python
# Copyright (C) <2020> PMBL;South China Agricultural University. All rights reserved
__author__ = "Write by Fangping Li"
__version__ = '0.1.0'
import argparse
import sys
import os
def get_options():
example = "Panlineal.py -l location.lg -p example.pair.cfg -t 20 -all yes -o refquery -f 1000 -clean yes "
description = "Create one-by-one read-pairs and sv compare example: " + example
parser = argparse.ArgumentParser(description = description,prog = 'Panlineal.py')
parser.add_argument('-p', '--pairguide', action='store',type=str,help='input your pairguide file')
parser.add_argument('-t', '--threads', action='store',type=int,help='how many thread do you want to use')
parser.add_argument('-all', '--runall', action='store',default="yes",choices=('yes','no'),
type=str,help='if yes: run multiple sequence of whole process, generate the pan genome file; if no:just splice; default yes')
parser.add_argument('-o', '--output', action='store',type=str,
help='name of the pan-genome output: <-o>.fasta',default="output")
parser.add_argument('-f', '--flitersize', action='store',type=int,
help="fliter size of SV; default 1000",default=1000)
parser.add_argument('-l', '--location', action='store',type=str,
help='location of software "mummer" "lastz" and "svmu',default="location.lg")
parser.add_argument('-r', '--rangefliter', action='store',type=int,help='SVs distance between red and query; default 3000000',default=3000000)
parser.add_argument('-merge', '--merge', action='store',type=str,choices=('yes','no'),
help='merge .goc and generate the final location file; default yes',default="yes")
parser.add_argument('-clean', '--clean', action='store',type=str,choices=('yes','no'),
help='Clean all of the middle file!; default no',default="no")
parser.add_argument('--version', action='version',version='%(prog)s '+__version__+" "+__author__)
return parser.parse_args()
gosome = get_options()
location = gosome.location
parame = open(location,"r") #mum lastz svmu samtools bowtie2 location
parameline = list(parame.readlines())
parame.close()
pairguide = gosome.pairguide
threads = gosome.threads
runall = gosome.runall
output = gosome.output
flitersize = gosome.flitersize
clean = gosome.clean
rangefliter = gosome.rangefliter
#sys.argv[2] #Secondgenome
ref = parameline[5].split("=")[1].strip()#sys.argv[1] #Firstgenome
print(ref)
querylist = parameline[6].split("=")[1].strip().split(",")
roundcountn = 0
roundcount = open("roundcount","w")
print(roundcountn)
print(str(roundcountn) ,file = roundcount)
roundcount.close()
if len(querylist) > 1:
for query in querylist:
roundcount = open("roundcount","w")
roundcountn += 1
print(roundcountn,file = roundcount)
roundcount.close()
commandpair = "awk '{print $1,$"+str(roundcountn+1)+"}' "+ pairguide+"> "+pairguide+".cyc"
print(commandpair)
os.system(commandpair)
pairguidec = pairguide+".cyc"
command = "multiple.py -1 "+ref+" -2 "+query+" -p "+pairguidec+" -t "+str(threads)+" -all "+runall+" -o temp"+str(roundcountn)+".fasta -f "+str(flitersize)+" -t "+str(threads)+" -l "+ location+" -clean "+ clean +" -r "+str(rangefliter)
print(command)
os.system(command)
ref = "temp"+str(roundcountn)+".fasta"
os.system("mv temp"+str(roundcountn)+".fasta "+output+".fasta")
else:
print(querylist)
query=querylist[0]
roundcount = open("roundcount","w")
roundcountn += 1
command = "multiple.py -1 "+ref+" -2 "+query+" -p "+pairguide+" -t "+str(threads)+" -all "+runall+" -o temp"+str(roundcountn)+".fasta -f "+str(flitersize)+" -t "+str(threads)+" -l "+ location+" -clean "+ clean +" -r "+str(rangefliter)
os.system(command)
print(roundcountn,file = roundcount)
roundcount.close()
if gosome.merge == "yes":
print("Auto merge!")
roundcount = open("roundcount","r")
roundcountn = list(roundcount.readlines())[0]
roundcount.close()
k = int(roundcountn)
for i in range(k-1):
if i == 0:
f = i
p = i + 1
o = i + 2
goin1 = "temp"+str(p)+".fasta.goc"
goin2 = "temp"+str(o)+".fasta.goc"
goout = "temp"+str(f)+"temp.fasta.goc"
commandgather = "Gathergoc.py "+goin1+" "+goin2+" "+goout
print(commandgather)
os.system(commandgather)
else:
f = i
goin1 = goout
goout = "temp"+str(f)+"temp.fasta.goc"
o = i + 2
goin2 = "temp"+str(o)+".fasta.goc"
commandgather = "Gathergoc.py "+goin1+" "+goin2+" "+goout
print(commandgather)
os.system(commandgather)
os.system("mv temp"+str(i)+"temp.fasta.goc "+output+".fasta.goc")
print("Your output is "+output+".fasta")
print("Your output is "+output+".fasta.goc")