-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path12_get-breakpoints-initialMR.py
More file actions
195 lines (142 loc) · 5.87 KB
/
12_get-breakpoints-initialMR.py
File metadata and controls
195 lines (142 loc) · 5.87 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import sys
import genutils
import brkptalign
import os.path
# starts with trying to get breakpoint from miropeats
from optparse import OptionParser
###############################################################################
USAGE = """12_get-breakpoints-initialMR.py --ref <reference genome fasta, must be indexed> --tmp <tmp dir>
--assembase <base directory for assembly output>
--miropeats_base <miropeats base dir>
--in <input file with getcontig>
--out <output file for initial miropeats results>
"""
parser = OptionParser(USAGE)
parser.add_option('--ref',dest='refFasta', help = 'reference genome fasta')
parser.add_option('--tmp',dest='tmpDir', help = 'directory for temp files')
parser.add_option('--assembase',dest='assemBaseDir', help = 'base directory for assembly')
parser.add_option('--miropeats_base',dest='mrDir', help = 'directory for temp files')
parser.add_option('--in',dest='inFileName', help = 'input file with getcontig results')
parser.add_option('--out',dest='outFileName', help = 'out file for initial miropeats results')
(options,args)=parser.parse_args()
if options.refFasta is None:
parser.error('refFasta file not given')
if options.tmpDir is None:
parser.error('tmp dir not given')
if options.mrDir is None:
parser.error('mrDir dir not given')
if options.assemBaseDir is None:
parser.error('assembly base dir not given')
if options.inFileName is None:
parser.error('input file name with get contig results not given')
if options.outFileName is None:
parser.error('output file name with initial miropeats results not given')
#############################################################################
if options.assemBaseDir[-1] != '/':
options.assemBaseDir += '/'
if options.mrDir[-1] != '/':
options.mrDir += '/'
if options.tmpDir[-1] != '/':
options.tmpDir += '/'
refGenomeFasta = options.refFasta
workingDirBase = options.mrDir
assemBaseDir = options.assemBaseDir
outResFile = options.inFileName
outResFile2 = options.outFileName
# hardcoded in base scripts dir
# set scriptDir to location where scripts are installed
#scriptDir = 'scripts/'
scriptDir = '../'
regDelta = 2000
minINS = 50
minStart = 30
minStart = 60
inFile = open(outResFile,'r')
outTable = open(outResFile2,'w')
header = ['siteID','chromosome','ContigName','ContigOreintation','ContigLen','chromFragStart','chromFragEnd','leftChromEnd','leftContigEnd','rightChromStart','rightContigStart','chromTSDSize','contigInsSize']
header = '\t'.join(header) + '\n'
outTable.write(header)
numDid = 0
for line in inFile:
line = line.rstrip()
line = line.split()
siteID = line[0]
if siteID == 'siteID':
continue
if line[1] == 'NO_CANDIDATE':
continue
print line
data = {}
data['tmpDir'] = options.tmpDir
if os.path.isdir(data['tmpDir']) is False:
cmd = 'mkdir ' + data['tmpDir']
print 'making tmp dir'
print cmd
genutils.runCMD(cmd)
data['refGenomeFasta'] = refGenomeFasta
data['siteID'] = siteID
chrom = siteID.split('_')
chrom = chrom[0:-1]
chrom = '_'.join(chrom)
p = int(siteID.split('_')[-1])
startBp = p - regDelta
endBp = p + regDelta
data['chromName'] = chrom
data['chromFragStart'] =startBp
data['chromFragEnd'] = endBp
data['contigName'] = line[1]
data['contigDir'] = line[2]
originalContigsDir = assemBaseDir + data['chromName'] + '/' + data['siteID']
data['originalContigsDir'] = originalContigsDir
alignOutDir = workingDirBase + data['chromName'] + '/' + data['siteID']
cmd = 'mkdir -p ' + alignOutDir
genutils.runCMD(cmd)
data['alignOutDir'] = alignOutDir
brkptalign.get_contig_seq(data)
brkptalign.get_genome_frag(data)
brkptalign.get_contig_gaps(data,run=True)
nl = [data['siteID'],data['chromName'],data['contigName'],data['contigDir']]
nl.append(str(data['contigLen']))
nl.append(str(data['chromFragStart']))
nl.append(str(data['chromFragEnd']))
brkptalign.run_miropeats(data)
brkptalign.parse_miropeats_hits(data)
nl.append(str(data['leftChromFragEnd']))
nl.append(str(data['leftContigEnd']))
nl.append(str(data['rightChromFragStart']))
nl.append(str(data['rightContigStart']))
if data['leftChromFragEnd'] == 'NA':
data['chromTSDSize'] = 'NA'
data['contigInsSize'] = 'NA'
else:
data['chromTSDSize'] = data['leftChromFragEnd'] - data['rightChromFragStart'] + 1
data['contigInsSize'] = data['rightContigStart'] - data['leftContigEnd'] + 1
nl.append(str(data['chromTSDSize']))
nl.append(str(data['contigInsSize']))
brkptalign.run_rm(data,run=True)
# run initial parse make image
if data['miroOutPS'] != 'FAILURE':
cmd = 'python ' + scriptDir + 'annotate-miropeats.py '
cmd += ' --miroin ' + data['miroOutPS']
cmd += ' --topRM ' + data['genomeFragFileNameRM']
cmd += ' --bottomRM ' + data['contigSeqFileNameRM']
cmd += ' --clonebreak ' + str(data['rightContigStart']) + ',' + str(data['leftContigEnd'])
cmd += ' --chrombreak ' + str(data['leftChromFragEnd']) + ',' + str(data['rightChromFragStart'])
cmd += ' --siteID ' + data['siteID']
cmd += ' --tsd ' + str(data['chromTSDSize'])
cmd += ' --ins ' + str(data['contigInsSize'])
cmd += ' --clonegap ' + data['contigSeqGapsFileName']
print cmd
genutils.runCMD(cmd)
data['psAnnotated'] = data['miroOutPS'] + '.annotated.ps'
data['psAnnotatedPDF'] = data['alignOutDir'] + '/' + data['siteID'] + '.initialMR.annotated.pdf'
if os.path.isfile(data['psAnnotatedPDF']) is True:
cmd = 'rm ' + data['psAnnotatedPDF']
genutils.runCMD(cmd)
cmd = 'ps2pdf %s %s' % (data['psAnnotated'],data['psAnnotatedPDF'])
print cmd
genutils.runCMD(cmd)
nl = '\t'.join(nl) + '\n'
outTable.write(nl)
inFile.close()
outTable.close()