Bam.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:SV2 作者: dantaki 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号