コード例 #1
0
def _prepare_calls(result_file, out_dir, data):
    """Write summary file of results of HLA typing by allele.
    """
    sample = dd.get_sample_name(data)
    out_file = os.path.join(out_dir, "%s-optitype.csv" % (sample))
    if not utils.file_uptodate(out_file, result_file):
        hla_truth = bwakit.get_hla_truthset(data)
        with file_transaction(data, out_file) as tx_out_file:
            with open(tx_out_file, "w") as out_handle:
                writer = csv.writer(out_handle)
                allele_info = _parse_result_file(result_file)
                if len(allele_info) == 1:
                    writer.writerow([
                        "sample", "locus", "alleles", "expected", "validates"
                    ])
                else:
                    writer.writerow(
                        ["sample", "local", "index", "alleles", "score"])
                for j, (alleles, score) in enumerate(allele_info):
                    for hla_locus, call_alleles in alleles:
                        truth_alleles = tz.get_in([sample, hla_locus],
                                                  hla_truth, [])
                        if len(allele_info) == 1:
                            writer.writerow([
                                sample, hla_locus, ";".join(call_alleles),
                                ";".join(truth_alleles),
                                bwakit.matches_truth(call_alleles,
                                                     truth_alleles, data)
                            ])
                        else:
                            writer.writerow([
                                sample, hla_locus, j, ";".join(call_alleles),
                                score
                            ])
    return out_file
コード例 #2
0
ファイル: optitype.py プロジェクト: DoaneAS/bcbio-nextgen
def _prepare_calls(result_file, hla_dir, data):
    """Write summary file of results of HLA typing by allele.
    """
    sample = dd.get_sample_name(data)
    out_file = os.path.join(hla_dir, "%s-optitype.csv" % (sample))
    if not utils.file_uptodate(out_file, result_file):
        hla_truth = bwakit.get_hla_truthset(data)
        with file_transaction(data, out_file) as tx_out_file:
            with open(tx_out_file, "w") as out_handle:
                writer = csv.writer(out_handle)
                allele_info = _parse_result_file(result_file)
                if len(allele_info) == 1:
                    writer.writerow(["sample", "locus", "alleles", "expected", "validates"])
                else:
                    writer.writerow(["sample", "local", "index", "alleles", "score"])
                for j, (alleles, score) in enumerate(allele_info):
                    for hla_locus, call_alleles in alleles:
                        truth_alleles = tz.get_in([sample, hla_locus], hla_truth, [])
                        if len(allele_info) == 1:
                            writer.writerow([sample, hla_locus,
                                             ";".join(call_alleles), ";".join(truth_alleles),
                                             bwakit.matches_truth(call_alleles, truth_alleles, data)])
                        else:
                            writer.writerow([sample, hla_locus, j, ";".join(call_alleles), score])
    return out_file
コード例 #3
0
def _combine_calls(hla_calls, hla_dir, data):
    """Write summary file of results of HLA typing by allele.
    """
    sample = dd.get_sample_name(data)
    out_file = os.path.join(hla_dir, "%s-optitype.csv" % (sample))
    if not utils.file_uptodate(out_file, hla_calls[0][1]):
        hla_truth = bwakit.get_hla_truthset(data)
        with file_transaction(data, out_file) as tx_out_file:
            with open(tx_out_file, "w") as out_handle:
                writer = csv.writer(out_handle)
                writer.writerow(["sample", "locus", "alleles", "expected", "validates"])
                for hla_locus, result_file in hla_calls:
                    truth_alleles = tz.get_in([sample, hla_locus], hla_truth, [])
                    call_alleles, score = _parse_result_file(result_file, hla_locus)
                    writer.writerow([sample, hla_locus,
                                     ";".join(call_alleles), ";".join(truth_alleles),
                                     bwakit.matches_truth(call_alleles, truth_alleles, data)])
    return out_file