-
Notifications
You must be signed in to change notification settings - Fork 2
/
xome_blender
executable file
·596 lines (551 loc) · 28.9 KB
/
xome_blender
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
#! /usr/bin/env python
from random import randint, shuffle
import os, argparse, sys, re, multiprocessing, shutil
from subprocess import Popen, PIPE
import pysam
import xomeblender.logging_module
from xomeblender.logging_module import log
class Consumer(multiprocessing.Process):
def __init__(self, task_queue, result_queue, main='.'):
multiprocessing.Process.__init__(self)
self.task_queue = task_queue
self.result_queue = result_queue
self.main = main
def run(self):
proc_name = self.name
while True:
next_task = self.task_queue.get()
if next_task is None:
self.task_queue.task_done()
break
next_task.main = self.main
next_task.sub = proc_name
answer = next_task()
self.task_queue.task_done()
self.result_queue.put(answer)
return
class subsamp(object):
def __init__(self, samplingdata):
self.samplingdata = samplingdata
def __call__(self):
if len(self.samplingdata) > 4:
seed, outputfile, nodelfile, sampfile, tmpbed, chrome = self.samplingdata
if not os.path.isfile(outputfile):
log.debug("[subsamp] - Start creation of clonal file %s..." % outputfile)
log.debug('[subsamp] - samtools view -hb -s %s -o %s %s -U %s -L %s %s' % (seed, outputfile, sampfile, nodelfile, tmpbed, chrome))
samplingline = Popen(['samtools', 'view', '-hb', '-s', seed, sampfile, chrome], stdout=PIPE)
splittingline = Popen(['samtools', 'view', '-hb', '-o', outputfile, '-', '-U', nodelfile, '-L', tmpbed], stdin=samplingline.stdout, stdout=PIPE).wait()
doubledel = os.popen("awk '{if ($4=='2') print $0}' " + tmpbed).read()
if doubledel != '':
singledel = os.popen("awk '{if ($4=='1') print $0}' " + tmpbed).read()
if singledel != '':
single_del_path = tmpbed.replace('_del.bed', '_double_del.bed')
with open(single_del_path, 'w') as file:
file.write(singledel)
outputfile2 = outputfile[:-4] + '_2.bam'
splittingline = Popen(['samtools', 'view', '-hb', '-o', outputfile2, outputfile, '-L', single_del_path], stdout=PIPE).wait()
os.remove(outputfile)
os.rename(outputfile2, outputfile)
log.debug('[subsamp] - samtools index %s' % outputfile)
pysam.index(outputfile, catch_stdout=False)
log.debug('[subsamp] - samtools index %s' % nodelfile)
pysam.index(nodelfile, catch_stdout=False)
log.debug("[subsamp] - Finish creation of clonal file %s..." % outputfile)
else:
seed, outputfile, sampfile, chrome = self.samplingdata
if not os.path.isfile(outputfile):
log.debug("[subsamp] - Start creation of clonal file %s..." % outputfile)
log.debug('[subsamp] - samtools view -hb -s %s -o %s %s %s' % (seed, outputfile, sampfile, chrome))
pysam.view('-hb', '-s%s' % seed, "-o%s" % outputfile, sampfile, chrome, catch_stdout=False)
log.debug("[subsamp] - Finish creation of clonal file %s..." % outputfile)
return outputfile
class add_intervals(object):
def __init__(self, samregline, variant_files, wdir, ):
self.samregline = samregline
self.variant_files = variant_files
self.wdir = wdir
def __call__(self):
import random
inputfile, region, samplename, ev_type, copnum = self.samregline
log.debug('[add_intervals] - Creation of %s in position %s for sample %s...' % (ev_type, region, inputfile)) # Extract reads for duplications
if type(self.variant_files) == str:
self.variant_files = [self.variant_files]
varfile = os.path.join(str(self.wdir), list(filter(lambda x: samplename in x, self.variant_files))[0])
if not os.path.isfile(inputfile + '.bai'):
pysam.index(inputfile, catch_stdout=False)
bamfile = pysam.AlignmentFile(inputfile, "rb")
vcf_in = pysam.VariantFile(varfile)
BamRegion = bamfile.fetch(str(region.split(':')[0]), int(str(region.split(':')[1]).split('-')[0]),
int(str(region.split(':')[1]).split('-')[1])) # Open vcf variant file
etheroreads = []
homoreads = []
countpos = 0
try:
for rec in vcf_in.fetch(str(region.split(':')[0]), int(str(region.split(':')[1]).split('-')[0]),
int(str(region.split(':')[1]).split('-')[1])):
countpos += 1
except Exception:
log.debug('[add_intervals] - No somatic events found in region %s' % (region))
pass
if countpos > 0:
log.debug('[add_intervals] - Iterating over variants in region %s of file %s' % (region, varfile)) # If reads fall onto small event in region
for rec in vcf_in.fetch(str(region.split(':')[0]), int(str(region.split(':')[1]).split('-')[0]),
int(str(region.split(':')[1]).split('-')[1])):
for read in bamfile.fetch(str(region.split(':')[0]), int(str(rec).split()[1]),
int(str(rec).split()[1]) + 1):
if read.query_sequence is not None:
aligned_positions = read.get_aligned_pairs(with_seq=True)
pos = int(str(rec).split()[1]) - 1
if pos in zip(*aligned_positions)[1]:
idx = list(zip(*aligned_positions))[1].index(pos)
read_pos, reference_pos, base = aligned_positions[idx]
if base is not None and base in "acgt":
etheroreads.append(read.tostring(bamfile))
elif base is not None and base in "ACTG":
homoreads.append(read.tostring(bamfile))
else:
homoreads.append(read.tostring(bamfile))
else:
log.warning("[add_intervals] - cannot get infos about reads in position %s for sample %s " % (str(region.split(':')[1]), varfile))
continue
else:
for read in bamfile.fetch(str(region.split(':')[0]), int(str(region.split(':')[1]).split('-')[0]), # If no reads fall onto small event in region
int(str(region.split(':')[1]).split('-')[1])):
homoreads.append(read.tostring(bamfile))
log.debug("[add_intervals] - count pos is equal to %s for region %s" % (str(countpos), region))
NamesList = list(map(lambda x: x.split('\t')[0], homoreads)) + list(map(lambda x: x.split('\t')[0], etheroreads))
for reads in BamRegion:
if reads.query_name not in NamesList:
homoreads.append(reads.tostring(bamfile))
bamfile.close()
vcf_in.close()
if len(etheroreads) > 5 or ev_type != 'Dup':
log.debug("[add_intervals] - taking 0.5 reads for region %s event %s" % (region, ev_type))
homoreads50 = list(map(lambda x: homoreads[x],
random.sample(range(len(homoreads)), int(round(len(homoreads) / 2.)))))
else:
homoreads50 = homoreads
if ev_type == 'Dup':
intinfos = [etheroreads*int(copnum), homoreads50*int(copnum)]
else:
intinfos = [etheroreads, homoreads50]
log.debug(
'[add_intervals] - Finished creation of %s in position %s for sample %s! %s ethero reads and %s homo reads found on %s variants!' % (
ev_type, region, inputfile, len(etheroreads), len(homoreads50), countpos)) # Ethero reads are present only if a somatic snp or del falls in cnv region
return intinfos
def samwriter(file_out, template, ev_reads, outlabel):
log.debug('[samwriter] - Event bam generation...') # Creates events.bam containing duplicated reads
tempfile = pysam.AlignmentFile(template, "rb")
head = tempfile.text
file = open(file_out, 'w')
for hl in head.split('\n'):
if hl != '':
if hl.startswith('@RG'):
fixline = re.sub('SM:(.*?)\t', 'SM:' + outlabel + '\t', hl)
file.write(fixline + '\n')
else:
file.write(hl + '\n')
for l in ev_reads:
if l != '':
file.write(l + '\n')
file.close()
tempfile.close()
outputfilebam = file_out[:-4] + '.bam'
outputfilebamsorted = file_out[:-10] + '.bam'
pysam.view("-Sb", "-@%s" % str(th), file_out, "-o%s" % outputfilebam, catch_stdout=False)
os.remove(file_out)
pysam.sort(outputfilebam, "-@%s" % str(th), "-o%s" % outputfilebamsorted, catch_stdout=False)
os.remove(outputfilebam)
pysam.index(outputfilebamsorted, "-@%s" % str(th), catch_stdout=False)
log.debug('[samwriter] - Event bam ready!')
def copynumbergen(copyfile, idir):
log.info('CNV adding...') # Creates reads lists for duplications bam aka events.bam
ethreads = []
homreads = []
Q = multiprocessing.JoinableQueue()
R = multiprocessing.Queue()
consumers = [Consumer(Q, R)
for ix in range(th)]
for w in consumers:
w.start()
for line in open(copyfile, 'r').readlines():
if line != '':
int_chr, int_start, int_stop, int_type, int_cn, int_samp, int_ref = line.split()
if int_type == 'Del':
if 1 <= int(int_cn) <= 2:
int_file_vec = list(map(lambda n:
os.path.join(idir, list(filter(lambda x: n in x, [f for f in os.listdir(os.path.join(workdir, idir)) if f.endswith('regions.bam')]))[0]),
list(map(lambda t: t + '_' + int_chr + '_', int_samp.split('-')))
))
else:
log.error('[copynumbergen] - Deletion value must be 1 or 2! It is %s.' % str(int_cn))
sys.exit(1)
else:
if 1 <= int(int_cn) <= 5:
int_file_vec = list(map(lambda n:
os.path.join(idir, list(filter(lambda x: n in x, [f for f in os.listdir(os.path.join(workdir, idir)) if not f.endswith('regions.bam') and f.endswith('.bam')]))[0]),
list(map(lambda t: t + '_' + int_chr + '_', int_samp.split('-')))
))
else:
log.error('[copynumbergen] - Duplication value must be between 1 and 5! It is %s.' % str(int_cn))
sys.exit(1)
region = str(int_chr) + ':' + str(int_start) + '-' + str(int_stop)
for ll, i in enumerate(int_file_vec):
samregline = [str(i), str(region), str(int_samp.split('-')[ll]), str(int_type), str(int_cn)]
log.info(samregline)
Q.put(add_intervals(samregline, var_files, workdir))
for ix in range(th):
Q.put(None)
Q.join()
while not Q.empty():
Q.get()
for r in range(R.qsize()):
result = R.get()
if result is not None:
ethreads.extend(result[0])
homreads.extend(result[1])
retlist = [ethreads, homreads]
return (retlist)
def CNVJobSplitter(filecopynumber, cfiles, idir, snamelist, finalcovlist):
delregions = {os.path.join(workdir, idir, k): [] for k in cfiles[1:]} # Link each event to its relative tumoral sample. keys=sample, values=events
for line in open(filecopynumber, 'r').readlines():
if line != '':
int_chr, int_start, int_stop, int_type, int_copyn, int_samp, int_ref = line.split()
int_file_vec = list(map(lambda n: os.path.join(idir, list(filter(lambda x: n in x, cfiles))[0]), int_samp.split('-')))
region = str(int_chr) + ':' + str(int_start) + '-' + str(int_stop)
for i in int_file_vec:
if str(int_type) == 'Del':
delregions[str(os.path.join(workdir, i))].append(str(int_chr + '\t' + int_start + '\t' + int_stop + '\t' + int_copyn))
jobojects = []
if any(delregions.values()) is True:
for cnvk, cnvv in delregions.items():
fpath, samp = os.path.split(cnvk)
ncov = dict(zip(snamelist, finalcovlist)).get(samp[:-4])
tmpbed = os.path.join(workdir, idir, samp[:-4] + '_' + str(ncov) + '_del.bed')
with open(tmpbed, 'w') as f:
for coords in cnvv:
chrstr = coords.split()[0]
seed = '.' + str(ncov)
if len(str(ncov)) == 1:
seed = '.0' + str(ncov)
jobline = [str(randint(0, 90000)) + seed,
os.path.join(workdir, idir, samp[:-4]) + '_' + str(chrstr) + '_' + str(
ncov) + '_regions.bam',
os.path.join(workdir, idir, samp[:-4]) + '_' + str(chrstr) + '_' + str(
ncov) + '_nodel.bam', cnvk, tmpbed, str(chrstr)] # [Sampling percentage, output name regions, output name nodel, input file, chr] Line to generate affected chr bam for each subsample
if jobline[1:] not in map(lambda x: x[1:], jobojects):
jobojects.append(jobline)
f.write(coords + '\n')
log.debug('[CNVJobSplitter] - Coordinate bed file generation, for sample %s...' % samp)
chromosmes = list(range(1, 23)) + ['X', 'Y']
if chromextformat == True:
chromosmes = list(map(lambda x: 'chr' + str(x), chromosmes))
for kfile, v in delregions.items():
fpath, samplename = os.path.split(kfile)
if not type(chromosmes[0]) == str:
chromosmes = list(map(str, chromosmes))
uniquechrs = [e for e in chromosmes if e not in list(map(lambda x: str(x.split('\t')[0]), v))] # No event chromosomes for subsamples
ncov = dict(zip(snamelist, finalcovlist)).get(samplename[:-4])
for c in uniquechrs:
seed = '.' + str(ncov)
if len(str(ncov)) == 1:
seed = '.0' + str(ncov)
jobojects.append([str(randint(0, 90000)) + seed,
os.path.join(workdir, idir, samplename[:-4]) + '_' + str(c) + '_' + str(ncov) + '.bam',
str(kfile), str(c)]) # Line to generate no affected chr bam for each subsample
for c in chromosmes:
kfile = cfiles[0]
ncov = dict(zip(snamelist, finalcovlist)).get(os.path.split(kfile)[1][:-4])
seed = '.' + str(ncov)
if len(str(ncov)) == 1:
seed = '.0' + str(ncov)
jobojects.append([str(randint(0, 90000)) + seed,
os.path.join(workdir, idir, os.path.split(kfile)[1][:-4]) + '_' + str(c) + '_' + str(
ncov) + '.bam', str(kfile), str(c)]) # Line to generate no affected chr bam for control
shuffle(jobojects)
return jobojects
def subsampler(outcovlist, analysisdir, labelvec):
log.info('Subclone preparation...')
clonefilelist = []
Q = multiprocessing.JoinableQueue()
R = multiprocessing.Queue()
chromosmes = list(range(1, 23)) + ['X', 'Y']
if cnvfile != '':
jl = CNVJobSplitter(cnvfile, baminputs, analysisdir, labelvec, outcovlist)
else:
jl = []
for ii, bi in enumerate(baminputs):
if chromextformat == True:
chromosmes = map(lambda x: 'chr' + str(x), chromosmes)
for c in chromosmes:
seed = '.' + str(outcovlist[ii])
if len(str(outcovlist[ii])) == 1:
seed = '.0' + str(outcovlist[ii])
jl.append([str(randint(0, 90000)) + seed,
os.path.join(workdir, analysisdir, labelvec[ii]) + '_' + str(c) + '_' + str(
outcovlist[ii]) + '.bam', str(bi), str(c)])
shuffle(jl)
consumers = [Consumer(Q, R)
for ix in range(th)]
for w in consumers:
w.start()
for j in jl:
Q.put(subsamp(j))
for ix in range(th):
Q.put(None)
Q.join()
while not Q.empty():
Q.get()
for r in list(range(R.qsize())):
res = R.get()
if res is not None and 'regions' in res:
clonefilelist.append(res)
return clonefilelist
def merger(bampath, outlabel):
log.info('Subclone finalization...')
tempfile = pysam.AlignmentFile(baminputs[0], "rb")
head = tempfile.text
rgfile = os.path.join(bampath, 'rg.txt')
file = open(rgfile, 'w')
for line in head.split('\n'):
if line.startswith('@RG'):
fixline = re.sub('SM:(.*?)\t', 'SM:' + outlabel + '\t', line)
file.write(fixline + '\n')
file.close()
tempfile.close()
merginglist = [i for i in os.listdir(bampath) if i.endswith('.bam') and 'regions' not in i]
finalfile = os.path.join(bampath, (outlabel + '.bam'))
bam2merge = map(lambda x: os.path.join(bampath, x), merginglist)
bamsfile = os.path.join(bampath, 'to_merge.txt')
file = open(bamsfile, 'w')
for line in bam2merge:
file.write(line + '\n')
file.close()
log.debug('[merger] - samtools merge -cp -h%s -b%s %s -@%s' % (rgfile, bamsfile, finalfile, str(th)))
pysam.merge("-cp", "-h%s" % rgfile, "-b%s" % bamsfile, finalfile, "-@%s" % str(th), catch_stdout=False)
log.debug('[merger] - samtools index %s -@%s' % (finalfile, str(th)))
pysam.index(finalfile, "-@%s" % str(th), catch_stdout=False)
if not os.path.exists(os.path.join(workdir, out_dir)):
os.makedirs(os.path.join(workdir, out_dir))
try:
shutil.move(finalfile, os.path.join(workdir, out_dir, outlabel + '.bam'))
except shutil.Error:
log.error("Unable to move %s" % finalfile)
try:
shutil.move(finalfile + '.bai', os.path.join(workdir, out_dir, outlabel + '.bam.bai'))
except shutil.Error:
log.error("Unable to move %s" % (finalfile + '.bai'))
if os.path.isfile(os.path.join(workdir, out_dir, os.path.split(finalfile)[1])):
shutil.rmtree(os.path.join(workdir, invisibledir), ignore_errors=True)
def Worker(analysisdir, outcovlist, copynvfile):
labels = [prefix + '_C'] + list(map(lambda x: prefix + '_S' + str(x), range(1, len(percentageVec))))
outlab = '_'.join([prefix, '_'.join(map(lambda x: x.split(prefix + '_')[1], labels)), '_'.join(map(str, percentageVec))])
clonefiles = subsampler(outcovlist, analysisdir, labels)
if copynvfile != '':
copygen = copynumbergen(copynvfile, analysisdir)
fileout = os.path.join(workdir, invisibledir, 'event_reads_unsrt.sam')
samwriter(fileout, os.path.join(workdir, invisibledir, clonefiles[0]), copygen[0] + copygen[1], outlab)
merger(os.path.join(workdir, invisibledir), outlab)
def lineReader(arguments):
list_file = arguments.list[0]
ref = arguments.reference
th = arguments.threads
try:
with open(list_file, 'r') as f:
for line in f:
args = parser.parse_args()
if len(line.split('\t')) == 7:
linesplit = line.strip().split('\t')
args.inputs = linesplit[0].split(' ')
args.label = [linesplit[1]]
args.starting_coverage = [linesplit[2]]
args.percentages = linesplit[3].split(' ')
args.final_coverage = [linesplit[4]]
args.variants = linesplit[5].split(' ')
args.cnv = [linesplit[6]]
args.ref = ref
args.th = th
MainReader(args)
else:
linesplit = line.strip().split('\t')
args.inputs = linesplit[0].split(' ')
args.label = [linesplit[1]]
args.starting_coverage = [linesplit[2]]
args.percentages = linesplit[3].split(' ')
args.final_coverage = [linesplit[4]]
args.variants = linesplit[5].split(' ')
args.ref = ref
args.th = th
MainReader(args)
except IOError:
log.error('Could not read file: %s' % list_file)
def chrcheck(chrfile):
bamfile = pysam.AlignmentFile(chrfile, "rb")
chrbait = bamfile.header['SQ'][0]['SN']
bamfile.close()
return str(chrbait)
def MainReader(args):
global filesfolder
global workdir
global baminputs
global ref
global prefix
global percentageVec
global out_cov
global start_cov
global var_files
global cnvfile
global out_dir
global invisibledir
global th
global chromextformat
workdir = os.getcwd()
filesfolder = os.path.abspath(os.path.dirname(sys.argv[0]))
ver = args.verbose
verbosity(ver)
if args.output_dir is not None:
out_dir = str(args.output_dir[0])
else:
out_dir = 'Xome-Blender_Results'
baminputs = ' '.join(map(str, args.inputs)).split()
ref = args.reference
prefix = str(args.label[0])
if '-' in prefix:
log.error('Hyphens are not allowed for labels. Please, replace it!')
sys.exit(1)
percentageVec = list(map(int, ' '.join(map(str, args.percentages)).split()))
if sum(map(int, percentageVec)) != 100:
log.error('The sum of your percentages is not equal to 100, fix it!')
out_cov = str(args.final_coverage[0])
start_cov = str(args.starting_coverage[0])
var_files = ' '.join(map(str, args.variants)).split()
th = args.threads
if not (len(baminputs) - 1 == len(percentageVec) - 1 == len(var_files)):
log.error('The number of values per input does not match, fix it!')
sys.exit(1)
new_perc_list = []
for i in percentageVec:
New_percentage = int(round(float(out_cov) / float(start_cov) * (i)))
New_cov = int(round((float(out_cov) * (i)) / 100.))
if New_percentage == 0:
New_percentage = 1
if New_cov > int(start_cov):
log.error('I cannot reach the desidered coverage for the output with this inputs!')
sys.exit(1)
else:
new_perc_list.append(New_percentage)
invisibledir = '.NewCoverageBam' + str(randint(0, 90000))
if not os.path.exists(invisibledir):
os.makedirs(os.path.join(workdir, invisibledir))
if args.cnv is not None:
cnvfile = str(args.cnv[0])
else:
cnvfile = ''
chromextformat = False
bamchr = chrcheck(baminputs[0])
if 'chr' in str(bamchr):
chromextformat = True
Worker(invisibledir, new_perc_list, cnvfile)
def verbosity(ver):
if ver == 0:
xomeblender.logging_module.log.setLevel(xomeblender.logging_module.logging.WARN)
elif ver == 1:
xomeblender.logging_module.log.setLevel(xomeblender.logging_module.logging.INFO)
elif ver == 2:
xomeblender.logging_module.log.setLevel(xomeblender.logging_module.logging.DEBUG)
elif ver == 3:
sys.stdout = open(os.devnull, 'w')
xomeblender.logging_module.log.setLevel(xomeblender.logging_module.logging.DEBUG)
xomeblender.logging_module.ch.setLevel(xomeblender.logging_module.logging.DEBUG)
######################
## Argument Parsing ##
######################
parser = argparse.ArgumentParser(add_help=False,
prog='Xome-Blender',
usage='''\r \n
\033[1m _ _
\ \ / / ___ _ ___
\ \/ / / _ \ | |_______ / _ \
/ /\ \ | (_) || _ _ \| __/
/_/ \_\ \___/ |_| |_| |_| \___|
___ _ _
| . \| | ___ _ | | ___ _ _
| _/| | / _ \| |___ _| | / _ \| '_/
| . \| || __/| _ \/ . || __/| |
|___/|_| \___||_| |_|\___| \___||_| \033[0m
________________________________________________________________________________________________________________________
Xome-Blender allows to generate synthetic cancer genomes with user defined features, such as number of subclones, number
of somatic variants and the presence of CNV.
\033[1m________________________________________________________________________________________________________________________\033[0m
usage: %(prog)s [-i <c.bam s1.bam>] [-la <label>] [-r <ref.fa>] [-p 10 90] [-sc 70] [-fc 70] [-v <s1.vcf>] [options]
________________________________________________________________________________________________________________________''',
epilog='''
________________________________________________________________________________________________________________________
Xome-Blender. Written by Roberto Semeraro, Department of Clinical and Sperimental Medicine, University of Florence. For
bug reports or suggestion write to [email protected]''',
formatter_class=argparse.RawDescriptionHelpFormatter,
)
g = parser.add_argument_group(title=' mandatory arguments',
description=''' -i, --inputs control and subclone bam files
-r, --reference indexed reference sequence file
-la, --label the same label used for InXalizer
-p, --percentages the desidered percentage of each sample
-fc, --final_coverage coverage of final bam file
-sc, --starting_coverage coverage of input bam file
-v, --variants vcf files generated with InXalizer, one for subsample
''')
g.add_argument('-i', '--inputs', action='store', metavar='',
nargs='*', help=argparse.SUPPRESS)
g.add_argument('-r', '--reference', action='store', metavar='',
nargs=1, help=argparse.SUPPRESS)
g.add_argument('-la', '--label', action='store', metavar='',
nargs=1, help=argparse.SUPPRESS)
g.add_argument('-p', '--percentages', action='store', metavar='',
nargs='*', help=argparse.SUPPRESS)
g.add_argument('-fc', '--final_coverage', action="store", type=int,
nargs=1, metavar='', help=argparse.SUPPRESS)
g.add_argument('-sc', '--starting_coverage', action="store", type=int,
nargs=1, metavar='', help=argparse.SUPPRESS)
g.add_argument('-v', '--variants', action='store', metavar='',
nargs='*', help=argparse.SUPPRESS)
g1 = parser.add_argument_group(title=' alternative usage',
description=''' -l, --list text file containing instructions for multiple analyses (see README)
''')
g.add_argument('-l', '--list', action='store', metavar='',
nargs=1, help=argparse.SUPPRESS)
f = parser.add_argument_group(title=' options',
description=''' -cnv, --cnv a CNV file generated with InXalizer
-o, --output_dir if omitted, generates a results directory in the current position
-t, --threads_number number of processing threads [1]
-vb, --verbose increase verbosity: 0 = only warnings, 1 = info, 2 = debug, 3 = debug
on terminal. No number means info. Default is no verbosity
-h, --help show this help message and exit
''')
f.add_argument('-cnv', '--cnv', action='store', metavar='',
nargs=1, help=argparse.SUPPRESS)
f.add_argument('-o', '--output_dir', action="store", nargs=1, metavar='',
help=argparse.SUPPRESS)
f.add_argument('-t', '--threads', action="store", type=int, default=1, metavar='',
help=argparse.SUPPRESS)
f.add_argument('-vb', '--verbose', const=1, default=1, type=int, nargs="?",
help=argparse.SUPPRESS, choices=range(0, 4))
f.add_argument('-h', '--help', action="help",
help=argparse.SUPPRESS)
try:
args = parser.parse_args()
if args.list is None:
if not args.inputs or not args.reference or not args.label or not args.percentages or not args.final_coverage or not args.starting_coverage or not args.variants:
parser.print_help()
log.error('Missing mandatory arguments!')
sys.exit(1)
else:
MainReader(args)
else:
if not args.reference:
parser.print_help()
log.error('Missing mandatory arguments!')
sys.exit(1)
else:
lineReader(args)
except IOError as msg:
parser.error(str(msg))