def test_gm(log_files, source_dataframe): print "Testing gene map and network map" ni = NetworkInfo( "net_info_table","c2.cp.biocarta.v4.0.symbols.gmt") genes = [] for p in ni.get_pathways(): genes.append(set(ni.get_genes(p))) for log in log_files: with open(log, 'r') as l: for run_json in l: run = json.loads( run_json ) for allele in run['alleles']: source_allele = "%s-%s" % ( run['file_id'], allele ) working_dir = find_working( run['data_matrices'][source_allele] ) gm_file = join( working_dir, run['data_matrices'][ source_allele ]['gm']) nm_file = join( working_dir, run['data_matrices'][ source_allele ]['nm']) gm = np.load(gm_file) nm = np.load(nm_file) for i in range(1, len(nm)): start = nm[i-1] end = nm[i] if start < end: base_set = genes[i-1] my_net = gm[2*start:2*end] my_net_genes = source_dataframe.index[my_net] gene_set = set(my_net_genes) assert gene_set.issubset(base_set), "Genes do not match network genes" assert (end - start) == scipy.misc.comb(len(gene_set),2, exact=1), "Wrong number of genes" print "Gene map and network map tests ... PASSED"
def networks(self): if self._pathways is None: ni = NetworkInfo( *self.net_info ) self._pathways = ni.get_pathways() self.logger.debug("Got Networks") return self._pathways
def deprecated_networks(self): if self._pathways is None: print self.net_info ni = NetworkInfo( *self.net_info ) self._pathways = ni.get_pathways() return self._pathways