report.py 文件源码

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

项目:vaxrank 作者: hammerlab 项目源码 文件源码
def make_minimal_neoepitope_report(
        ranked_variants_with_vaccine_peptides,
        num_epitopes_per_peptide=None,
        excel_report_path=None):
    """
    Creates a simple Excel spreadsheet containing one neoepitope per row

    Parameters
    ----------
    ranked_variants_with_vaccine_peptides : 
      Ranked list of (variant, list of its vaccine peptides)

    num_epitopes_per_peptide : int
      The number of epitopes to include for each vaccine peptide; these are sorted before cutoff.
      If None, all epitopes will be included in the output

    excel_report_path : str
      Path to which to write the output Excel file
    """
    rows = []
    # each row in the spreadsheet is a neoepitope
    for (variant, vaccine_peptides) in ranked_variants_with_vaccine_peptides:
        for vaccine_peptide in vaccine_peptides:
            # only include mutant epitopes
            for epitope_prediction in vaccine_peptide.mutant_epitope_predictions:
                row = OrderedDict([
                    ('Allele', epitope_prediction.allele),
                    ('Mutant peptide sequence', epitope_prediction.peptide_sequence),
                    ('Score', vaccine_peptide.mutant_epitope_score),
                    ('Predicted mutant pMHC affinity', '%.2f nM' % epitope_prediction.ic50),
                    ('Variant allele RNA read count',
                        vaccine_peptide.mutant_protein_fragment.n_alt_reads),
                    ('Wildtype sequence', epitope_prediction.wt_peptide_sequence),
                    ('Predicted wildtype pMHC affinity',
                        '%.2f nM' % epitope_prediction.wt_ic50),
                    ('Gene name', vaccine_peptide.mutant_protein_fragment.gene_name),
                    ('Genomic variant', variant.short_description),
                ])
                rows.append(row)

    if len(rows) > 0:
        df = pd.DataFrame.from_dict(rows)
        writer = pd.ExcelWriter(excel_report_path, engine='xlsxwriter')
        df.to_excel(writer, sheet_name='Neoepitopes', index=False)

        # resize columns to be not crappy
        worksheet = writer.sheets['Neoepitopes']
        worksheet.set_column('%s:%s' % ('B', 'B'), 23)
        worksheet.set_column('%s:%s' % ('D', 'D'), 27)
        worksheet.set_column('%s:%s' % ('E', 'E'), 26)
        worksheet.set_column('%s:%s' % ('F', 'F'), 17)
        worksheet.set_column('%s:%s' % ('G', 'G'), 30)
        worksheet.set_column('%s:%s' % ('H', 'H'), 9)
        worksheet.set_column('%s:%s' % ('I', 'I'), 18)
        writer.save()
        logger.info('Wrote XLSX neoepitope report file to %s', excel_report_path)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号