Example #1
0
# Uncorrected p's for the nodes
from copy import deepcopy
node_property_dict['uncorrected_p'] = deepcopy(hyperedge_score_dict['p'])
node_property_dict['dir'] = deepcopy(hyperedge_score_dict['dir'])
transcript_uncorrected_p = {}
for the_transcript_id in the_transcript_pval_dict.keys():
    node_property_dict['uncorrected_p'][the_transcript_id] = deepcopy(the_transcript_pval_dict[the_transcript_id]['p'])
    node_property_dict['dir'][the_transcript_id] = deepcopy(the_transcript_pval_dict[the_transcript_id]['dir'])
    transcript_uncorrected_p[the_transcript_id] = deepcopy(the_transcript_pval_dict[the_transcript_id]['p'])

# Corrected p's.  Note reporters are already corrected by their null distribution.
# We will split transcript and reaction p's for bh adjustment since we
# have a distinct fdr correction for each nodetype and for the edges
from nampy.statistics import networkstatistics
node_property_dict['corrected_p_reporter'] = deepcopy(the_reporter_dict['p_values'])
node_property_dict['corrected_p_gene'] = (networkstatistics.mtcorrect(transcript_uncorrected_p, method = 'BH'))
node_property_dict['corrected_p_reaction'] = (networkstatistics.mtcorrect(hyperedge_score_dict['p'], method = 'BH'))
the_reactions = node_property_dict['corrected_p_reaction'].keys()
the_metabolites = node_property_dict['corrected_p_reporter'].keys()

# -log10 p's are nice to help with visualization
node_property_dict['dir_x_-log10(corrected_p_reaction)'] = {}
node_property_dict['dir_x_-log10(corrected_p_gene)'] = {}
nodes_to_calculate = set([x for x in (node_property_dict['corrected_p_gene'].keys() + node_property_dict['corrected_p_reaction'].keys())]).intersection(set([x for x in node_property_dict['dir'].keys()]))
for the_node_id in nodes_to_calculate:
    the_dir = node_property_dict['dir'][the_node_id]
    if the_dir == '-':
        the_dir = -1.
    else:
        the_dir = 1.
    if the_node_id in node_property_dict['corrected_p_gene']:
Example #2
0
the_result, the_permutations = prince.prince(humannet, n_permutations = 100, verbose = True)

# The propagation scores are stored in the_result.  Here is how to save/load
# filename = 'test_apms_propagations'
# prince.save_prince_result(humannet, the_result, the_permutations, filename)
# networkio.pickle_network(humannet, 'humannet')
# humannet = networkio.load_pickled_network('humannet')
# the_result, the_permutations = prince.load_prince_result(humannet, filename)

from nampy.statistics import networkstatistics
ttp_dict_apms, side_dict_apms = networkstatistics.get_pvalue_from_scores(the_result, the_permutations, verbose = True)

otp_dict_apms = networkstatistics.ttp_to_otp(ttp_dict_apms, side_dict_apms)

# This is the dict of p-values from the propagations...
otp_dict_corrected_apms = networkstatistics.mtcorrect(otp_dict_apms, method = 'BH')
 
# We are done with the APMS propagation.  Clear the permutations, which can utilize a lot of memory.
del the_permutations


###
# Now, repeat the analysis with the RNAi data
hiv_rnai_file = data_dir + 'published_hiv_host_restriction_factors.txt'
rnai_source = networkio.create_source_dict_from_textfile(hiv_rnai_file)

# Query for more ID's, though this isn't strictly needed since Entrez ID's
# were used for the nodes in HumanNet
rnai_source_dict = idmapping.get_more_source_dict_ids(rnai_source, "Entrez Gene (GeneID)", mapping_types = ["Entrez Gene (GeneID)", "UniProtKB ACC", "UniProtKB ID"])
# We can check the recovery of the Entrez ID's from the query.
counter = 0