def test_preprocess_main_simple(self): exp, conv_table = preprocess.main('testdata/exp_data-001.csv', 'testdata/conv_table-001.tsv') self.assertEquals((10, 3), exp.shape) for i in range(3): for j in range(3): self.assertAlmostEquals(exp.values[i, j], -0.8164965809277261)
def test_preprocess_main_simple2(self): ref_exp = pd.read_csv('testdata/expected_pp_exp_data-002.csv', index_col=0, header=0) exp, conv_table = preprocess.main('testdata/exp_data-002.csv', 'testdata/conv_table-002.tsv') #exp.to_csv('testdata/expected_pp_exp_data-002.csv') self.assertTrue(np.isclose(ref_exp, exp).all())
def test_cluster(self): exp, conv_table = preprocess.main('testdata/exp_data-002.csv', 'testdata/conv_table-002.tsv') expected_clusters = [] with open('testdata/expected_clusters-002.csv', 'r') as infile: for line in infile: expected_clusters.append(line.strip().split(',')) clusters = coexpression.cluster(exp) self.assertEquals(7, len(clusters)) self.assertEquals(expected_clusters, clusters)
def test_membership_to_incidence(self): exp_data, conv_table = preprocess.main( 'testdata/ref_exp-000.csv', 'testdata/identifier_mappings.txt') with open('testdata/ref_ovx_membs-001.json') as infile: ovx_membs = json.load(infile) ref_ovx_matrix = pd.read_csv('testdata/ref_ovx_matrix-001.csv', index_col=0, header=0) ovx_matrix = biclusters.membership_to_incidence(ovx_membs, exp_data) #ovx_matrix.to_csv('testdata/ref_ovx_matrix-001.csv') self.assertTrue(np.isclose(ref_ovx_matrix, ovx_matrix).all())
def test_get_principal_df(self): exp_data, conv_table = preprocess.main('testdata/ref_exp-000.csv', 'testdata/identifier_mappings.txt') with open('testdata/coexpressionDictionary-001.json') as infile: revised_clusters = json.load(infile) ref_principal_df = pd.read_csv('testdata/ref_principal_df-001.csv', index_col=0, header=0) axes = mechinf.get_principal_df(revised_clusters, exp_data, subkey=None, min_number_genes=1) #axes.to_csv('testdata/ref_principal_df-001.csv', header=True, index=True) self.assertTrue(np.isclose(ref_principal_df, axes).all())
def test_enrichment(self): exp_data, conv_table = preprocess.main('testdata/ref_exp-000.csv', 'testdata/identifier_mappings.txt') with open('testdata/coexpressionDictionary-001.json') as infile: revised_clusters = json.load(infile) axes = pd.read_csv('testdata/ref_principal_df-001.csv', index_col=0, header=0) database_path = os.path.join('miner2/data', "tfbsdb_tf_to_genes.pkl") with open('testdata/ref_mechout-001.json') as infile: ref_mechout = json.load(infile) mechout = mechinf.enrichment(axes, revised_clusters, exp_data, correlation_threshold=0.2, num_cores=5, database_path=database_path) #with open('testdata/ref_mechout-001.json', 'w') as outfile: # json.dump(mechout, outfile) self.compare_dicts(ref_mechout, mechout)
def test_cluster(self): ref_exp = pd.read_csv('testdata/expected_pp_exp_data-002.csv', index_col=0, header=0) exp, conv_table = preprocess.main('testdata/exp_data-002.csv', 'testdata/conv_table-002.tsv') self.assertTrue(np.isclose(ref_exp, exp).all()) # just to make sure expected_clusters = [] with open('testdata/expected_clusters-002.csv', 'r') as infile: for line in infile: expected_clusters.append(line.strip().split(',')) clusters = coexpression.cluster(exp) #with open('testdata/expected_clusters-002.csv', 'w') as outfile: # for cluster in clusters: # outfile.write('%s\n' % (','.join(cluster))) self.assertEquals(len(expected_clusters), len(clusters)) self.assertEquals(expected_clusters, clusters)