示例#1
0
 def test_read_pickled_and_run_reporter(self):
     from nampy.multipartiteanalysis import reporterfeatures
     from nampy.networkio import networkio
     the_network = networkio.load_pickled_network(test_reporter_input_network_filename)
     the_network.convert_to_multipartite()
     p_values_dict = {}
     for the_reaction in the_network.nodetypes.get_by_id('reaction').nodes:
         p_values_dict[the_reaction.id] = 1E-3
     the_reporter_dict = reporterfeatures.calculate_reporter_scores(the_network, p_values_dict, 'metabolite', 'reaction', number_of_randomizations = 100, verbose = False)
     self.assertEqual(len(the_reporter_dict['p_values']), len(the_network.nodetypes.get_by_id('metabolite').nodes))
示例#2
0
the_probe_key_gene_value_dict = networkio.read_table_file_to_dict(data_dir + 'HT_HG_U133A_na34_annot_abbrev_140204.txt', force_to_float = False, comment_char = '#')
for the_probe_id in the_probe_key_gene_value_dict.keys():
    the_line = the_probe_key_gene_value_dict[the_probe_id]['Entrez Gene']
    the_line = the_line.split(' /// ')
    the_probe_key_gene_value_dict[the_probe_id] = the_line

# Combine p-values for 1 gene : many probe-sets using Stouffer's method
aggregated_pvalue_dict = networkstatistics.aggregate_probe_statistics_to_gene(probe_stats_dict, the_probe_key_gene_value_dict, aggregation_type = 'stouffer')

# Let's work with recon 1 from:
# Duarte, N. C., Becker, S. a, Jamshidi, N., Thiele, I., Mo, M. L., Vo, T. D., … Palsson, B. Ø. (2007). 
# Global reconstruction of the human metabolic network based on genomic and bibliomic data. 
# PNAS, 104(6), 1777–82. doi:10.1073/pnas.0610772104
# Note if we want to be more sophisticated we
# could build a cell-line specific model to work with.
the_network = networkio.load_pickled_network(data_dir + 'recon_1_nampy_v01')
the_network.convert_to_multipartite()

# We don't have the RefSeq  mRNA mappings. 
# Assign p-values to each gene-level entrez id, 
# which can then be mapped back to transcripts.
the_entrez_ids = list(set([x.id.split('.')[0] for x in the_network.nodetypes.get_by_id("gene").nodes]))

# Pick out the model genes that successfully mapped
the_model_gene_pval_dict = {}
for the_gene_id in the_entrez_ids:
    # This indicates spontaneous reactions in some COBRA
    # models, we can ignore it if we like
    if the_gene_id != 's0001':
        if the_gene_id in aggregated_pvalue_dict['mapped'].keys():
            the_model_gene_pval_dict[the_gene_id] = aggregated_pvalue_dict['mapped'][the_gene_id]