Ejemplo n.º 1
0
def addLibMetrics(genomeinfodict, ionstats_alignment, ionstats_basecaller, keyPeak, BaseCallerMetrics, res, extra):
    print 'addlibmetrics'

    if keyPeak != None:
        aveKeyCount = float(keyPeak.get('Library', 0.0))
    else:
        aveKeyCount = 0.0

    align_sample = 0
    if ionstats_alignment == None:
        align_sample = -1
    # check to see if this is a samled or full alignment
    # if libMetrics.has_key('Total number of Sampled Reads'):
    #    align_sample = 1
    if res.metaData.get('thumb', '0') == 1:
        align_sample = 2

    kwargs = {'report': res, 'aveKeyCounts': aveKeyCount, 'align_sample': align_sample}

    kwargs['Genome_Version'] = genomeinfodict['genome_version']
    kwargs['Index_Version'] = genomeinfodict['index_version']
    kwargs['genome'] = genomeinfodict['genome_name']
    kwargs['genomesize'] = genomeinfodict['genome_length']

    kwargs['totalNumReads'] = ionstats_basecaller['full']['num_reads']

    quallist = ['7', '10', '17', '20', '47']  # TODO Q30
    bplist = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600]
    if ionstats_alignment != None:
        kwargs['total_mapped_reads'] = ionstats_alignment['aligned']['num_reads']
        kwargs['total_mapped_target_bases'] = ionstats_alignment['aligned']['num_bases']

        for q in quallist:
            kwargs['q%s_longest_alignment' % q] = ionstats_alignment['AQ'+q]['max_read_length']
            kwargs['q%s_mean_alignment_length' % q] = ionstats_alignment['AQ'+q]['mean_read_length']
            kwargs['q%s_mapped_bases' % q] = ionstats_alignment['AQ'+q]['num_bases']
            kwargs['q%s_alignments' % q] = ionstats_alignment['AQ'+q]['num_reads']
            kwargs['q%s_coverage_percentage' % q] = 0.0  # 'N/A' # TODO
#           'Filtered %s Mean Coverage Depth' % q, '%.1f' % (float(ionstats_alignment['AQ'+q]['num_bases'])/float(3095693981)) ) TODO
            for bp in bplist:
                kwargs['i%sQ%s_reads' % (bp, q)] = sum(ionstats_alignment['AQ'+q]['read_length_histogram'][bp:])

        try:
            raw_accuracy = round((1 - float(sum(ionstats_alignment['error_by_position'])) / float(ionstats_alignment['aligned']['num_bases'])) * 100.0, 1)
            kwargs['raw_accuracy'] = raw_accuracy
        except:
            kwargs['raw_accuracy'] = 0.0
    else:
        kwargs['total_mapped_reads'] = 0
        kwargs['total_mapped_target_bases'] = 0

        for q in quallist:
            for bp in bplist:
                kwargs['i%sQ%s_reads' % (bp, q)] = 0
            kwargs['q%s_longest_alignment' % q] = 0
            kwargs['q%s_mean_alignment_length' % q] = 0
            kwargs['q%s_mapped_bases' % q] = 0
            kwargs['q%s_alignments' % q] = 0
            kwargs['q%s_coverage_percentage' % q] = 0.0
            kwargs['raw_accuracy'] = 0.0

    try:
        kwargs['sysSNR'] = ionstats_basecaller['system_snr']
        kwargs['cf'] = 100.0 * BaseCallerMetrics['Phasing']['CF']
        kwargs['ie'] = 100.0 * BaseCallerMetrics['Phasing']['IE']
        kwargs['dr'] = 100.0 * BaseCallerMetrics['Phasing']['DR']
    except:
        kwargs['sysSNR'] = 0.0
        kwargs['cf'] = 0.0
        kwargs['ie'] = 0.0
        kwargs['dr'] = 0.0

    if extra:
        kwargs["duplicate_reads"] = extra.get("duplicate_reads", None)

    libmetrics = res.libmetrics or models.LibMetrics()
    for key, value in kwargs.items():
        setattr(libmetrics, key, value)
    libmetrics.save()
    res.libmetrics = libmetrics
    res.save()
Ejemplo n.º 2
0
def addLibMetrics(genomeinfodict, ionstats_alignment, ionstats_basecaller,
                  keyPeak, BaseCallerMetrics, res, extra):
    print 'addlibmetrics'
    metric_map = {
        'genomelength': 'Genomelength',
        'rNumAlignments': 'Filtered relaxed BLAST Alignments',
        'rMeanAlignLen': 'Filtered relaxed BLAST Mean Alignment Length',
        'rLongestAlign': 'Filtered relaxed BLAST Longest Alignment',
        'rCoverage': 'Filtered relaxed BLAST coverage percentage',
        'r50Q10': 'Filtered relaxed BLAST 50Q10 Reads',
        'r100Q10': 'Filtered relaxed BLAST 100Q10 Reads',
        'r200Q10': 'Filtered relaxed BLAST 200Q10 Reads',
        'r50Q17': 'Filtered relaxed BLAST 50Q17 Reads',
        'r100Q17': 'Filtered relaxed BLAST 100Q17 Reads',
        'r200Q17': 'Filtered relaxed BLAST 200Q17 Reads',
        'r50Q20': 'Filtered relaxed BLAST 50Q20 Reads',
        'r100Q20': 'Filtered relaxed BLAST 100Q20 Reads',
        'r200Q20': 'Filtered relaxed BLAST 200Q20 Reads',
        'sNumAlignments': 'Filtered strict BLAST Alignments',
        'sMeanAlignLen': 'Filtered strict BLAST Mean Alignment Length',
        'sCoverage': 'Filtered strict BLAST coverage percentage',
        'sLongestAlign': 'Filtered strict BLAST Longest Alignment',
        's50Q10': 'Filtered strict BLAST 50Q10 Reads',
        's100Q10': 'Filtered strict BLAST 100Q10 Reads',
        's200Q10': 'Filtered strict BLAST 200Q10 Reads',
        's50Q17': 'Filtered strict BLAST 50Q17 Reads',
        's100Q17': 'Filtered strict BLAST 100Q17 Reads',
        's200Q17': 'Filtered strict BLAST 200Q17 Reads',
        's50Q20': 'Filtered strict BLAST 50Q20 Reads',
        's100Q20': 'Filtered strict BLAST 100Q20 Reads',
        's200Q20': 'Filtered strict BLAST 200Q20 Reads',
        "q7_qscore_bases": "Filtered Mapped Q7 Bases",
        "q10_qscore_bases": "Filtered Mapped Q10 Bases",
        "q17_qscore_bases": "Filtered Mapped Q17 Bases",
        "q20_qscore_bases": "Filtered Mapped Q20 Bases",
        "q47_qscore_bases": "Filtered Mapped Q47 Bases",
        'total_number_of_sampled_reads': 'Total number of Sampled Reads',
        'sampled_q7_coverage_percentage':
        'Sampled Filtered Q7 Coverage Percentage',
        'sampled_q7_mean_coverage_depth':
        'Sampled Filtered Q7 Mean Coverage Depth',
        'sampled_q7_alignments': 'Sampled Filtered Q7 Alignments',
        'sampled_q7_mean_alignment_length':
        'Sampled Filtered Q7 Mean Alignment Length',
        'sampled_mapped_bases_in_q7_alignments':
        'Sampled Filtered Mapped Bases in Q7 Alignments',
        'sampled_q7_longest_alignment':
        'Sampled Filtered Q7 Longest Alignment',
        'sampled_50q7_reads': 'Sampled Filtered 50Q7 Reads',
        'sampled_100q7_reads': 'Sampled Filtered 100Q7 Reads',
        'sampled_200q7_reads': 'Sampled Filtered 200Q7 Reads',
        'sampled_300q7_reads': 'Sampled Filtered 300Q7 Reads',
        'sampled_400q7_reads': 'Sampled Filtered 400Q7 Reads',
        'sampled_q10_coverage_percentage':
        'Sampled Filtered Q10 Coverage Percentage',
        'sampled_q10_mean_coverage_depth':
        'Sampled Filtered Q10 Mean Coverage Depth',
        'sampled_q10_alignments': 'Sampled Filtered Q10 Alignments',
        'sampled_q10_mean_alignment_length':
        'Sampled Filtered Q10 Mean Alignment Length',
        'sampled_mapped_bases_in_q10_alignments':
        'Sampled Filtered Mapped Bases in Q10 Alignments',
        'sampled_q10_longest_alignment':
        'Sampled Filtered Q10 Longest Alignment',
        'sampled_50q10_reads': 'Sampled Filtered 50Q10 Reads',
        'sampled_100q10_reads': 'Sampled Filtered 100Q10 Reads',
        'sampled_200q10_reads': 'Sampled Filtered 200Q10 Reads',
        'sampled_300q10_reads': 'Sampled Filtered 300Q10 Reads',
        'sampled_400q10_reads': 'Sampled Filtered 400Q10 Reads',
        'sampled_q17_coverage_percentage':
        'Sampled Filtered Q17 Coverage Percentage',
        'sampled_q17_mean_coverage_depth':
        'Sampled Filtered Q17 Mean Coverage Depth',
        'sampled_q17_alignments': 'Sampled Filtered Q17 Alignments',
        'sampled_q17_mean_alignment_length':
        'Sampled Filtered Q17 Mean Alignment Length',
        'sampled_mapped_bases_in_q17_alignments':
        'Sampled Filtered Mapped Bases in Q17 Alignments',
        'sampled_q17_longest_alignment':
        'Sampled Filtered Q17 Longest Alignment',
        'sampled_50q17_reads': 'Sampled Filtered 50Q17 Reads',
        'sampled_100q17_reads': 'Sampled Filtered 100Q17 Reads',
        'sampled_200q17_reads': 'Sampled Filtered 200Q17 Reads',
        'sampled_300q17_reads': 'Sampled Filtered 300Q17 Reads',
        'sampled_400q17_reads': 'Sampled Filtered 400Q17 Reads',
        'sampled_q20_coverage_percentage':
        'Sampled Filtered Q20 Coverage Percentage',
        'sampled_q20_mean_coverage_depth':
        'Sampled Filtered Q20 Mean Coverage Depth',
        'sampled_q20_alignments': 'Sampled Filtered Q20 Alignments',
        'sampled_q20_mean_alignment_length':
        'Sampled Filtered Q20 Mean Alignment Length',
        'sampled_mapped_bases_in_q20_alignments':
        'Sampled Filtered Mapped Bases in Q20 Alignments',
        'sampled_q20_longest_alignment':
        'Sampled Filtered Q20 Longest Alignment',
        'sampled_50q20_reads': 'Sampled Filtered 50Q20 Reads',
        'sampled_100q20_reads': 'Sampled Filtered 100Q20 Reads',
        'sampled_200q20_reads': 'Sampled Filtered 200Q20 Reads',
        'sampled_300q20_reads': 'Sampled Filtered 300Q20 Reads',
        'sampled_400q20_reads': 'Sampled Filtered 400Q20 Reads',
        'sampled_q47_coverage_percentage':
        'Sampled Filtered Q47 Coverage Percentage',
        'sampled_q47_mean_coverage_depth':
        'Sampled Filtered Q47 Mean Coverage Depth',
        'sampled_q47_alignments': 'Sampled Filtered Q47 Alignments',
        'sampled_q47_mean_alignment_length':
        'Sampled Filtered Q47 Mean Alignment Length',
        'sampled_mapped_bases_in_q47_alignments':
        'Sampled Filtered Mapped Bases in Q47 Alignments',
        'sampled_q47_longest_alignment':
        'Sampled Filtered Q47 Longest Alignment',
        'sampled_50q47_reads': 'Sampled Filtered 50Q47 Reads',
        'sampled_100q47_reads': 'Sampled Filtered 100Q47 Reads',
        'sampled_200q47_reads': 'Sampled Filtered 200Q47 Reads',
        'sampled_300q47_reads': 'Sampled Filtered 300Q47 Reads',
        'sampled_400q47_reads': 'Sampled Filtered 400Q47 Reads',
        'extrapolated_from_number_of_sampled_reads':
        'Extrapolated from number of Sampled Reads',
        'extrapolated_q7_coverage_percentage':
        'Extrapolated Filtered Q7 Coverage Percentage',
        'extrapolated_q7_mean_coverage_depth':
        'Extrapolated Filtered Q7 Mean Coverage Depth',
        'extrapolated_q7_alignments': 'Extrapolated Filtered Q7 Alignments',
        'extrapolated_q7_mean_alignment_length':
        'Extrapolated Filtered Q7 Mean Alignment Length',
        'extrapolated_mapped_bases_in_q7_alignments':
        'Extrapolated Filtered Mapped Bases in Q7 Alignments',
        'extrapolated_q7_longest_alignment':
        'Extrapolated Filtered Q7 Longest Alignment',
        'extrapolated_50q7_reads': 'Extrapolated Filtered 50Q7 Reads',
        'extrapolated_100q7_reads': 'Extrapolated Filtered 100Q7 Reads',
        'extrapolated_200q7_reads': 'Extrapolated Filtered 200Q7 Reads',
        'extrapolated_300q7_reads': 'Extrapolated Filtered 300Q7 Reads',
        'extrapolated_400q7_reads': 'Extrapolated Filtered 400Q7 Reads',
        'extrapolated_q10_coverage_percentage':
        'Extrapolated Filtered Q10 Coverage Percentage',
        'extrapolated_q10_mean_coverage_depth':
        'Extrapolated Filtered Q10 Mean Coverage Depth',
        'extrapolated_q10_alignments': 'Extrapolated Filtered Q10 Alignments',
        'extrapolated_q10_mean_alignment_length':
        'Extrapolated Filtered Q10 Mean Alignment Length',
        'extrapolated_mapped_bases_in_q10_alignments':
        'Extrapolated Filtered Mapped Bases in Q10 Alignments',
        'extrapolated_q10_longest_alignment':
        'Extrapolated Filtered Q10 Longest Alignment',
        'extrapolated_50q10_reads': 'Extrapolated Filtered 50Q10 Reads',
        'extrapolated_100q10_reads': 'Extrapolated Filtered 100Q10 Reads',
        'extrapolated_200q10_reads': 'Extrapolated Filtered 200Q10 Reads',
        'extrapolated_300q10_reads': 'Extrapolated Filtered 300Q10 Reads',
        'extrapolated_400q10_reads': 'Extrapolated Filtered 400Q10 Reads',
        'extrapolated_q17_coverage_percentage':
        'Extrapolated Filtered Q17 Coverage Percentage',
        'extrapolated_q17_mean_coverage_depth':
        'Extrapolated Filtered Q17 Mean Coverage Depth',
        'extrapolated_q17_alignments': 'Extrapolated Filtered Q17 Alignments',
        'extrapolated_q17_mean_alignment_length':
        'Extrapolated Filtered Q17 Mean Alignment Length',
        'extrapolated_mapped_bases_in_q17_alignments':
        'Extrapolated Filtered Mapped Bases in Q17 Alignments',
        'extrapolated_q17_longest_alignment':
        'Extrapolated Filtered Q17 Longest Alignment',
        'extrapolated_50q17_reads': 'Extrapolated Filtered 50Q17 Reads',
        'extrapolated_100q17_reads': 'Extrapolated Filtered 100Q17 Reads',
        'extrapolated_200q17_reads': 'Extrapolated Filtered 200Q17 Reads',
        'extrapolated_300q17_reads': 'Extrapolated Filtered 300Q17 Reads',
        'extrapolated_400q17_reads': 'Extrapolated Filtered 400Q17 Reads',
        'extrapolated_q20_coverage_percentage':
        'Extrapolated Filtered Q20 Coverage Percentage',
        'extrapolated_q20_mean_coverage_depth':
        'Extrapolated Filtered Q20 Mean Coverage Depth',
        'extrapolated_q20_alignments': 'Extrapolated Filtered Q20 Alignments',
        'extrapolated_q20_mean_alignment_length':
        'Extrapolated Filtered Q20 Mean Alignment Length',
        'extrapolated_mapped_bases_in_q20_alignments':
        'Extrapolated Filtered Mapped Bases in Q20 Alignments',
        'extrapolated_q20_longest_alignment':
        'Extrapolated Filtered Q20 Longest Alignment',
        'extrapolated_50q20_reads': 'Extrapolated Filtered 50Q20 Reads',
        'extrapolated_100q20_reads': 'Extrapolated Filtered 100Q20 Reads',
        'extrapolated_200q20_reads': 'Extrapolated Filtered 200Q20 Reads',
        'extrapolated_300q20_reads': 'Extrapolated Filtered 300Q20 Reads',
        'extrapolated_400q20_reads': 'Extrapolated Filtered 400Q20 Reads',
        'extrapolated_q47_coverage_percentage':
        'Extrapolated Filtered Q47 Coverage Percentage',
        'extrapolated_q47_mean_coverage_depth':
        'Extrapolated Filtered Q47 Mean Coverage Depth',
        'extrapolated_q47_alignments': 'Extrapolated Filtered Q47 Alignments',
        'extrapolated_q47_mean_alignment_length':
        'Extrapolated Filtered Q47 Mean Alignment Length',
        'extrapolated_mapped_bases_in_q47_alignments':
        'Extrapolated Filtered Mapped Bases in Q47 Alignments',
        'extrapolated_q47_longest_alignment':
        'Extrapolated Filtered Q47 Longest Alignment',
        'extrapolated_50q47_reads': 'Extrapolated Filtered 50Q47 Reads',
        'extrapolated_100q47_reads': 'Extrapolated Filtered 100Q47 Reads',
        'extrapolated_200q47_reads': 'Extrapolated Filtered 200Q47 Reads',
        'extrapolated_300q47_reads': 'Extrapolated Filtered 300Q47 Reads',
        'extrapolated_400q47_reads': 'Extrapolated Filtered 400Q47 Reads',
        'duplicate_reads': 'Count of Duplicate Reads',
    }

    if keyPeak != None:
        aveKeyCount = float(keyPeak.get('Library', 0.0))
    else:
        aveKeyCount = 0.0

    align_sample = 0
    if ionstats_alignment == None:
        align_sample = -1
    #check to see if this is a samled or full alignment
    #if libMetrics.has_key('Total number of Sampled Reads'):
    #    align_sample = 1
    if res.metaData.get('thumb', '0') == 1:
        align_sample = 2

    kwargs = {
        'report': res,
        'aveKeyCounts': aveKeyCount,
        'align_sample': align_sample
    }

    for dbname, key in metric_map.iteritems():
        kwargs[dbname] = set_type('0')

    kwargs['Genome_Version'] = genomeinfodict['genome_version']
    kwargs['Index_Version'] = genomeinfodict['index_version']
    kwargs['genome'] = genomeinfodict['genome_name']
    kwargs['genomesize'] = genomeinfodict['genome_length']

    quallist = ['7', '10', '17', '20', '47']  #TODO Q30
    bplist = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600]
    if ionstats_alignment != None:
        kwargs['totalNumReads'] = ionstats_alignment['full']['num_reads']
        kwargs['total_mapped_reads'] = ionstats_alignment['aligned'][
            'num_reads']
        kwargs['total_mapped_target_bases'] = ionstats_alignment['aligned'][
            'num_bases']

        for q in quallist:
            kwargs['q%s_longest_alignment' %
                   q] = ionstats_alignment['AQ' + q]['max_read_length']
            kwargs['q%s_mean_alignment_length' %
                   q] = ionstats_alignment['AQ' + q]['mean_read_length']
            kwargs['q%s_mapped_bases' % q] = ionstats_alignment['AQ' +
                                                                q]['num_bases']
            kwargs['q%s_alignments' % q] = ionstats_alignment['AQ' +
                                                              q]['num_reads']
            kwargs['q%s_coverage_percentage' % q] = 0.0  #'N/A' # TODO
            #           'Filtered %s Mean Coverage Depth' % q, '%.1f' % (float(ionstats_alignment['AQ'+q]['num_bases'])/float(3095693981)) ) TODO
            for bp in bplist:
                kwargs['i%sQ%s_reads' % (bp, q)] = sum(
                    ionstats_alignment['AQ' + q]['read_length_histogram'][bp:])

        try:
            raw_accuracy = round(
                (1 - float(sum(ionstats_alignment['error_by_position'])) /
                 float(ionstats_alignment['aligned']['num_bases'])) * 100.0, 1)
            kwargs['raw_accuracy'] = raw_accuracy
        except:
            kwargs['raw_accuracy'] = 0.0
    else:
        kwargs['totalNumReads'] = 0
        kwargs['total_mapped_reads'] = 0
        kwargs['total_mapped_target_bases'] = 0

        for q in quallist:
            for bp in bplist:
                kwargs['i%sQ%s_reads' % (bp, q)] = 0
            kwargs['q%s_longest_alignment' % q] = 0
            kwargs['q%s_mean_alignment_length' % q] = 0
            kwargs['q%s_mapped_bases' % q] = 0
            kwargs['q%s_alignments' % q] = 0
            kwargs['q%s_coverage_percentage' % q] = 0.0
            kwargs['raw_accuracy'] = 0.0

    try:
        kwargs['sysSNR'] = ionstats_basecaller['system_snr']
        kwargs['cf'] = 100.0 * BaseCallerMetrics['Phasing']['CF']
        kwargs['ie'] = 100.0 * BaseCallerMetrics['Phasing']['IE']
        kwargs['dr'] = 100.0 * BaseCallerMetrics['Phasing']['DR']
    except:
        kwargs['sysSNR'] = 0.0
        kwargs['cf'] = 0.0
        kwargs['ie'] = 0.0
        kwargs['dr'] = 0.0

    if extra:
        kwargs["duplicate_reads"] = extra.get("duplicate_reads", None)

    libmetrics = res.libmetrics or models.LibMetrics()
    for key, value in kwargs.items():
        setattr(libmetrics, key, value)
    libmetrics.save()
    res.libmetrics = libmetrics
    res.save()
Ejemplo n.º 3
0
def addLibMetrics(
    genomeinfodict,
    ionstats_alignment,
    ionstats_basecaller,
    keyPeak,
    BaseCallerMetrics,
    res,
    extra,
):
    print("addlibmetrics")

    if keyPeak != None:
        aveKeyCount = float(keyPeak.get("Library", 0.0))
    else:
        aveKeyCount = 0.0

    align_sample = 0
    if ionstats_alignment == None:
        align_sample = -1
    # check to see if this is a samled or full alignment
    # if libMetrics.has_key('Total number of Sampled Reads'):
    #    align_sample = 1
    if res.metaData.get("thumb", "0") == 1:
        align_sample = 2

    kwargs = {
        "report": res,
        "aveKeyCounts": aveKeyCount,
        "align_sample": align_sample
    }

    kwargs["Genome_Version"] = genomeinfodict["genome_version"]
    kwargs["Index_Version"] = genomeinfodict["index_version"]
    kwargs["genome"] = genomeinfodict["genome_name"]
    kwargs["genomesize"] = genomeinfodict["genome_length"]

    kwargs["totalNumReads"] = ionstats_basecaller["full"]["num_reads"]

    quallist = ["7", "10", "17", "20", "47"]  # TODO Q30
    bplist = [50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600]
    if ionstats_alignment != None:
        kwargs["total_mapped_reads"] = ionstats_alignment["aligned"][
            "num_reads"]
        kwargs["total_mapped_target_bases"] = ionstats_alignment["aligned"][
            "num_bases"]

        for q in quallist:
            kwargs["q%s_longest_alignment" %
                   q] = ionstats_alignment["AQ" + q]["max_read_length"]
            kwargs["q%s_mean_alignment_length" %
                   q] = ionstats_alignment["AQ" + q]["mean_read_length"]
            kwargs["q%s_mapped_bases" % q] = ionstats_alignment["AQ" +
                                                                q]["num_bases"]
            kwargs["q%s_alignments" % q] = ionstats_alignment["AQ" +
                                                              q]["num_reads"]
            kwargs["q%s_coverage_percentage" % q] = 0.0  # 'N/A' # TODO
            #           'Filtered %s Mean Coverage Depth' % q, '%.1f' % (float(ionstats_alignment['AQ'+q]['num_bases'])/float(3095693981)) ) TODO
            for bp in bplist:
                kwargs["i%sQ%s_reads" % (bp, q)] = sum(
                    ionstats_alignment["AQ" + q]["read_length_histogram"][bp:])

        try:
            raw_accuracy = round(
                (1 - float(sum(ionstats_alignment["error_by_position"])) /
                 float(ionstats_alignment["aligned"]["num_bases"])) * 100.0,
                2,
            )
            kwargs["raw_accuracy"] = raw_accuracy
        except Exception:
            kwargs["raw_accuracy"] = 0.0
    else:
        kwargs["total_mapped_reads"] = 0
        kwargs["total_mapped_target_bases"] = 0

        for q in quallist:
            for bp in bplist:
                kwargs["i%sQ%s_reads" % (bp, q)] = 0
            kwargs["q%s_longest_alignment" % q] = 0
            kwargs["q%s_mean_alignment_length" % q] = 0
            kwargs["q%s_mapped_bases" % q] = 0
            kwargs["q%s_alignments" % q] = 0
            kwargs["q%s_coverage_percentage" % q] = 0.0
            kwargs["raw_accuracy"] = 0.0

    try:
        kwargs["sysSNR"] = ionstats_basecaller["system_snr"]
        kwargs["cf"] = 100.0 * BaseCallerMetrics["Phasing"]["CF"]
        kwargs["ie"] = 100.0 * BaseCallerMetrics["Phasing"]["IE"]
        kwargs["dr"] = 100.0 * BaseCallerMetrics["Phasing"]["DR"]
    except Exception:
        kwargs["sysSNR"] = 0.0
        kwargs["cf"] = 0.0
        kwargs["ie"] = 0.0
        kwargs["dr"] = 0.0

    if extra:
        kwargs["duplicate_reads"] = extra.get("duplicate_reads", None)

    libmetrics = res.libmetrics or models.LibMetrics()
    for key, value in list(kwargs.items()):
        setattr(libmetrics, key, value)
    libmetrics.save()
    res.libmetrics = libmetrics
    res.save()