Source code for icepop.species_cell_proportion

#!/usr/bin/env python
""" 
This modules has interface to let user
choose which species they want. And return
the cell population weight accordingly.
Additional option include choosing between
Pandas dataframe or standard nested dictionary.
It behaves as the extension of ``cell_proportion`` module.
"""
__author__    = "Edward Wijaya <ewijaya@gmail.com>"
__copyright__ = "Copyright 2015"
import csv
import json
import os
import pandas as pd
import pickle
from clock import clockit
import input_reader as ir #import read_hdf, read_hdf_pheno


[docs]def normalize_tables(exp_pheno_df, cellpop_pheno_name_table_df): """ Expression normalization routines """ # Weight by row, at the end of this step # the rows sum up to 1 nexp_pheno_df = exp_pheno_df.set_index("Genes") nexp_pheno_df["sum"] = nexp_pheno_df.sum(axis=1) weight_pheno_df = nexp_pheno_df.loc[:,:].div(nexp_pheno_df["sum"],axis=0) weight_pheno_df.drop('sum',axis=1,inplace=True) # Weight by column, at the end of this step # At the end of this step the column sum up to 100 weight_pheno_df = (weight_pheno_df/weight_pheno_df.sum()) * 100 cellpop_pheno_df = weight_pheno_df.reset_index() return cellpop_pheno_df, cellpop_pheno_name_table_df
[docs]def get_pheno_prop_immgen(): """ Similar with the output generated by scp.get_prop(). It returns cell type proportion, but at phenotype level. Also returns a table that list the phenotype correspondence with cell type and organ. Specifically for ImmGen only. """ exp_pheno_df, cellpop_pheno_name_table_df = ir.read_immgen_hdf_pheno() cellpop_pheno_df, cellpop_pheno_name_table_df = normalize_tables(exp_pheno_df, cellpop_pheno_name_table_df) return cellpop_pheno_df, cellpop_pheno_name_table_df
[docs]def get_pheno_prop_iris(): """ Similar with the output generated by scp.get_prop(). It returns cell type proportion, but at phenotype level. Also returns a table that list the phenotype correspondence with cell type and organ. Specifically for IRIS only. """ exp_pheno_df, cellpop_pheno_name_table_df = ir.read_iris_hdf_pheno() cellpop_pheno_df, cellpop_pheno_name_table_df = normalize_tables(exp_pheno_df, cellpop_pheno_name_table_df) return cellpop_pheno_df, cellpop_pheno_name_table_df
[docs]def choose_organ(cp_organ_df, organ_name): """ Description of choose_organ """ cp_organ_df = cp_organ_df.loc[:, organ_name] cp_organ_df.reset_index(level=0,inplace=True) cp_organ_df = cp_organ_df.rename(columns = {'cell':"Genes"}) return cp_organ_df
[docs]def get_prop(species="mouse",mode=""): """ Get cell type proportion. :param species: string('mouse','human') mouse (default) obtained from ImmGen database and human from IRIS. :param mode: string('pandas_df','dict') :returns: function to read persistence file. Usage: >>> from icepop import species_cell_proportion as scp >>> cellpop_df = scp.get_prop(species="mouse",mode="pandas_df") """ if (species=="mouse" or species=="human") and mode=="pandas_df": return ir.read_hdf(species=species) elif species=="mouse" and mode=="dict": return read_pickle() else: pass
# IRIS to be added
[docs]def main(): """Used to execute this file.""" # outdf = get_prop(species="mouse",mode="pandas_df") outdf = get_prop(species="human",mode="pandas_df") print outdf.head()
# outdict = get_prop(species="mouse",mode="dict") # print json.dumps(outdict, indent=4) if __name__ == '__main__': main()