@@ -1370,10 +1370,11 @@ def minimap2_idxstats(inBam, refFasta, outBam=None, outStats=None,
1370
1370
1371
1371
assert outBam or outStats , "Either outBam or outStats must be specified"
1372
1372
1373
+ bam_aligned = util .file .mkstempfname ('.aligned.bam' )
1373
1374
if outBam is None :
1374
- bam_aligned = mkstempfname ('.aligned .bam' )
1375
+ bam_filtered = mkstempfname ('.filtered .bam' )
1375
1376
else :
1376
- bam_aligned = outBam
1377
+ bam_filtered = outBam
1377
1378
1378
1379
samtools = tools .samtools .SamtoolsTool ()
1379
1380
mm2 = tools .minimap2 .Minimap2 ()
@@ -1382,21 +1383,24 @@ def minimap2_idxstats(inBam, refFasta, outBam=None, outStats=None,
1382
1383
shutil .copyfile (refFasta , ref_indexed )
1383
1384
1384
1385
mm2 .align_bam (inBam , ref_indexed , bam_aligned )
1385
-
1386
+
1386
1387
if filterReadsAfterAlignment :
1387
1388
samtools .filter_to_proper_primary_mapped_reads (bam_aligned ,
1388
1389
bam_filtered ,
1389
1390
require_pairs_to_be_proper = not doNotRequirePairsToBeProper ,
1390
1391
reject_singletons = not keepSingletons )
1392
+ os .unlink (bam_aligned )
1391
1393
else :
1392
- bam_filtered = bam_aligned
1394
+ shutil . move ( bam_aligned , bam_filtered )
1393
1395
1394
1396
if outStats is not None :
1395
1397
samtools .idxstats (bam_filtered , outStats )
1396
1398
1397
1399
if outBam is None :
1398
1400
os .unlink (bam_filtered )
1399
1401
1402
+
1403
+
1400
1404
def parser_minimap2_idxstats (parser = argparse .ArgumentParser ()):
1401
1405
parser .add_argument ('inBam' , help = 'Input unaligned reads, BAM format.' )
1402
1406
parser .add_argument ('refFasta' , help = 'Reference genome, FASTA format, pre-indexed by Picard and Novoalign.' )
@@ -1435,10 +1439,11 @@ def bwamem_idxstats(inBam, refFasta, outBam=None, outStats=None,
1435
1439
1436
1440
assert outBam or outStats , "Either outBam or outStats must be specified"
1437
1441
1442
+ bam_aligned = util .file .mkstempfname ('.aligned.bam' )
1438
1443
if outBam is None :
1439
- bam_aligned = mkstempfname ('.aligned .bam' )
1444
+ bam_filtered = mkstempfname ('.filtered .bam' )
1440
1445
else :
1441
- bam_aligned = outBam
1446
+ bam_filtered = outBam
1442
1447
1443
1448
samtools = tools .samtools .SamtoolsTool ()
1444
1449
bwa = tools .bwa .Bwa ()
@@ -1456,8 +1461,9 @@ def bwamem_idxstats(inBam, refFasta, outBam=None, outStats=None,
1456
1461
bam_filtered ,
1457
1462
require_pairs_to_be_proper = not doNotRequirePairsToBeProper ,
1458
1463
reject_singletons = not keepSingletons )
1464
+ os .unlink (bam_aligned )
1459
1465
else :
1460
- bam_filtered = bam_aligned
1466
+ shutil . move ( bam_aligned , bam_filtered )
1461
1467
1462
1468
if outStats is not None :
1463
1469
samtools .idxstats (bam_filtered , outStats )
0 commit comments