def bam_init(args=None,Ped=None,Snv=None,gen=None):
bams=[]
for f in args:
errFH(f)
try: pysam.AlignmentFile(f).check_index()
except ValueError:
sys.stderr.write('WARNING: {} is not indexed with samtools index. Skipping ...\n'.format(f))
continue
except AttributeError:
sys.stderr.write('WARNING: {} appears to be in SAM format. Convert to BAM with `samtools view -bh {}` and index with samtools index\n'.format(f,f))
continue
bam = Bam(f,Ped,gen)
if len(Snv)<1:
print 'FATAL ERROR: SNV file(s) were not formatted correctly. See https://github.com/dantaki/SV2/wiki/input#snv-vcf for details'
sys.stderr.write('FATAL ERROR: SNV file(s) were not formatted correctly. See https://github.com/dantaki/SV2/wiki/input#snv-vcf for details\n')
sys.exit(1)
for snv in Snv:
if snv.id.get(bam.id)!=None:
bam.Snv,bam.snv_index=snv,snv.id[bam.id]
if bam.id!=None and bam.Snv==None: sys.stderr.write('WARNING: BAM file {} sample name (@RG SM:<sample_id>):{} not found in SNV VCFs. Skipping {} ...\n'.format(f,bam.id,f))
if bam.id==None: sys.stderr.write('WARNING: Skipping BAM file {}. No sample name (@RG SM:<sample_id>). See https://github.com/dantaki/SV2/wiki/input#bam for details')
if bam.id!=None and bam.Snv!=None: bams.append(bam)
if len(bams)<1:
print 'FATAL ERROR: BAM file(s) were not formatted correctly. See https://github.com/dantaki/SV2/wiki/input#bam for details'
sys.stderr.write('FATAL ERROR: BAM file(s) were not formatted correctly. See https://github.com/dantaki/SV2/wiki/input#bam for details\n')
sys.exit(1)
return bams
评论列表
文章目录