def metaphlan2_transformer(all_rank_summary, output_rank_summaries, ranks):
    all_ranks = pd.read_csv(all_rank_summary, sep='\t', skiprows=3)

    def last_entry(x):
        return x.split('|')[(- 1)]
    all_ranks['last_clade'] = all_ranks['#clade_name'].map(last_entry)
    all_ranks['@@TAXID'] = all_ranks['NCBI_tax_id'].map(last_entry)
    all_ranks['RANK'] = all_ranks['last_clade'].map((lambda x: greengenes_rank_dict[x[:3]]))
    all_ranks['TAXNAME'] = all_ranks['last_clade'].map((lambda x: x[3:]))
    all_ranks['PERCENTAGE'] = all_ranks['relative_abundance']
    keep_cols = ['@@TAXID', 'RANK', 'TAXNAME', 'PERCENTAGE']
    for (output_, rank) in zip(output_rank_summaries, ranks):
        sub_df = all_ranks.loc[(all_ranks['RANK'] == rank)]
        sub_df_matching = sub_df[keep_cols]
        sub_df_matching.to_csv(output_, sep='\t', index=False)
def metaphlan2_transformer(all_rank_summary, output_rank_summaries, ranks):
    all_ranks = pd.read_csv(all_rank_summary, sep='\t', skiprows=3)

    def last_entry(x):
        return x.split('|')[(- 1)]
    all_ranks['last_clade'] = all_ranks['#clade_name'].map(last_entry)
    all_ranks['@@TAXID'] = all_ranks['NCBI_tax_id'].map(last_entry)
    all_ranks['RANK'] = all_ranks['last_clade'].map((lambda x: greengenes_rank_dict[x[:3]]))
    all_ranks['TAXNAME'] = all_ranks['last_clade'].map((lambda x: x[3:]))
    all_ranks['PERCENTAGE'] = all_ranks['relative_abundance']
    keep_cols = ['@@TAXID', 'RANK', 'TAXNAME', 'PERCENTAGE']
    for (output_, rank) in zip(output_rank_summaries, ranks):
        sub_df = all_ranks.loc[(all_ranks['RANK'] == rank)]
        sub_df_matching = sub_df[keep_cols]
        sub_df_matching.to_csv(output_, sep='\t', index=False)