def is_one_gene(p): '''Test to see if most mutations are due to single gene''' counts = hit_matrix.ix[run.gene_sets[p]].sum(1).dropna().order() with_top = hit_matrix.ix[run.gene_sets[p]].sum().clip_upper(1).sum() without = hit_matrix.ix[run.gene_sets[p] - {counts.idxmax()}].sum().clip_upper(1).sum() return ((with_top - without) / without) > .5 meta_matrix = meta_matrix[size_filter(meta_matrix)] s = Series({p: is_one_gene(p) for p in meta_matrix.index}) meta_matrix = meta_matrix.ix[s==False] hit_matrix = hit_matrix[size_filter(hit_matrix)] '''Add passing features to the Data Object''' mut.features = meta_matrix.append(hit_matrix) mut.compress() mut.uncompress() '''Save updated Data Object (with additional features field''' mut.save() mut.uncompress() '''Draw pathway_plots for pathway level features''' meta_features = [f for f in mut.features.index if f in run.gene_sets] pathway_plot_folder = mut.path + '/Figures/PathwayPlots/' if not os.path.isdir(pathway_plot_folder): os.makedirs(pathway_plot_folder) for i,p in enumerate(meta_features): df = mut.df.ix[run.gene_sets[p]]
from Processing.Helpers import merge_redundant report_path = sys.argv[1] cancer_type = sys.argv[2] data_type = sys.argv[3] data_type = data_type[3:] '''Load in run and CN data''' run = pickle.load(open(report_path + '/RunObject.p', 'rb')) cancer = run.load_cancer(cancer_type) if data_type == 'broad': data = Dataset(cancer, run, 'CN_broad') data.features = data.df data.save() sys.exit(0) data = Dataset(cancer, run, 'CN') data.path = '_'.join([data.path, data_type]) if data_type == 'deletion': data.hit_val = -2 elif data_type == 'amplification': data.hit_val = 2 elif data_type == 'amplification_low': data.df = data.df.replace(1,2) data.hit_val = 2 hit_matrix = (data.df==data.hit_val).astype(float)