Beispiel #1
0
def assign_genotype_to_variant(variant, sample, genotype_result):
    variant_id = genotype_result['variant.id']
    sample_name = genotype_result['sample.name']
    outcome = genotype_result['genotype']

    if (variant.var_id != variant_id) or (sample.name != sample_name):
        msg = ("Error: assign_genotype: "
               "Variant/Sample ({}/{}) to genotype result ({}/{}) "
               "mismatch!").format(variant.var_id, sample.name, variant_id, sample_name)
        die(msg)

    if bool(outcome) is False:
        variant.genotype(sample.name).set_format('GT', './.')
    else:
        variant.qual += outcome['qual']
        variant.genotype(sample.name).set_format('GT', outcome['formats']['GT'])
        variant.genotype(sample.name).set_format('GQ', outcome['formats']['GQ'])
        variant.genotype(sample.name).set_format('SQ', outcome['formats']['SQ'])
        variant.genotype(sample.name).set_format('GL', outcome['formats']['GL'])
        variant.genotype(sample.name).set_format('DP', outcome['formats']['DP'])
        variant.genotype(sample.name).set_format('AO', outcome['formats']['AO'])
        variant.genotype(sample.name).set_format('RO', outcome['formats']['RO'])
        # if detailed:
        variant.genotype(sample.name).set_format('AS',  outcome['formats']['AS'])
        variant.genotype(sample.name).set_format('ASC', outcome['formats']['ASC'])
        variant.genotype(sample.name).set_format('RS',  outcome['formats']['RS'])
        variant.genotype(sample.name).set_format('AP',  outcome['formats']['AP'])
        variant.genotype(sample.name).set_format('RP',  outcome['formats']['RP'])
        variant.genotype(sample.name).set_format('QR',  outcome['formats']['QR'])
        variant.genotype(sample.name).set_format('QA',  outcome['formats']['QA'])
        variant.genotype(sample.name).set_format('AB',  outcome['formats']['AB'])
    return variant
Beispiel #2
0
def open_alignment_file(afile, reference_fasta):
    fd = None
    if afile.endswith('.bam'):
        fd = pysam.AlignmentFile(afile, mode='rb')
    elif afile.endswith('.cram'):
        fd = pysam.AlignmentFile(afile, mode='rc', reference_filename=reference_fasta)
    else:
        die('Error: %s is not a valid alignment file (*.bam or *.cram)\n' % afile)

    return fd
Beispiel #3
0
def open_alignment_file(afile, reference_fasta):
    fd = None
    if afile.endswith('.bam'.encode('ascii')):
        fd = pysam.AlignmentFile(afile, mode='rb')
    elif afile.endswith('.cram'.encode('ascii')):
        fd = pysam.AlignmentFile(afile,
                                 mode='rc',
                                 reference_filename=reference_fasta)
    else:
        die('Error: %s is not a valid alignment file (*.bam or *.cram)\n' %
            afile)

    return fd
Beispiel #4
0
def assign_genotype_to_variant(variant, sample, genotype_result):
    variant_id = genotype_result['variant.id']
    sample_name = genotype_result['sample.name']
    outcome = genotype_result['genotype']

    if (variant.var_id != variant_id) or (sample.name != sample_name):
        msg = ("Error: assign_genotype: "
               "Variant/Sample ({}/{}) to genotype result ({}/{}) "
               "mismatch!").format(variant.var_id, sample.name, variant_id,
                                   sample_name)
        die(msg)

    if bool(outcome) is False:
        variant.genotype(sample.name).set_format('GT', './.')
    else:
        variant.qual += outcome['qual']
        variant.genotype(sample.name).set_format('GT',
                                                 outcome['formats']['GT'])
        variant.genotype(sample.name).set_format('GQ',
                                                 outcome['formats']['GQ'])
        variant.genotype(sample.name).set_format('SQ',
                                                 outcome['formats']['SQ'])
        variant.genotype(sample.name).set_format('GL',
                                                 outcome['formats']['GL'])
        variant.genotype(sample.name).set_format('DP',
                                                 outcome['formats']['DP'])
        variant.genotype(sample.name).set_format('AO',
                                                 outcome['formats']['AO'])
        variant.genotype(sample.name).set_format('RO',
                                                 outcome['formats']['RO'])
        # if detailed:
        variant.genotype(sample.name).set_format('AS',
                                                 outcome['formats']['AS'])
        variant.genotype(sample.name).set_format('ASC',
                                                 outcome['formats']['ASC'])
        variant.genotype(sample.name).set_format('RS',
                                                 outcome['formats']['RS'])
        variant.genotype(sample.name).set_format('AP',
                                                 outcome['formats']['AP'])
        variant.genotype(sample.name).set_format('RP',
                                                 outcome['formats']['RP'])
        variant.genotype(sample.name).set_format('QR',
                                                 outcome['formats']['QR'])
        variant.genotype(sample.name).set_format('QA',
                                                 outcome['formats']['QA'])
        variant.genotype(sample.name).set_format('AB',
                                                 outcome['formats']['AB'])
    return variant
Beispiel #5
0
def ensure_valid_alignment_file(afile):
    if not (afile.endswith('.bam'.encode('ascii'))
            or afile.endswith('.cram'.encode('ascii'))):
        die('Error: %s is not a valid alignment file (*.bam or *.cram)\n' %
            afile)
Beispiel #6
0
def ensure_valid_alignment_file(afile):
    if not (afile.endswith('.bam') or afile.endswith('.cram')):
        die('Error: %s is not a valid alignment file (*.bam or *.cram)\n' % afile)