def test_build_table__with_pandas_DataFrame(): df = pd.DataFrame(dict(a=[1, 2, 3], b=["c", "d", "e"])) table = build_table("test", "syn123", df) for i, row in enumerate(table): assert_equals(row[0], (i+1)) assert_equals(row[1], ["c", "d", "e"][i]) assert_equals(len(table), 3) headers = [ {'name': 'a', 'columnType': 'INTEGER'}, {'name': 'b', 'columnType': 'STRING'} ] assert_equals(headers, table.headers)
def test_build_table__with_pandas_DataFrame(): df = pd.DataFrame(dict(a=[1, 2, 3], b=["c", "d", "e"])) table = build_table("test", "syn123", df) for i, row in enumerate(table): assert row[0] == (i + 1) assert row[1] == ["c", "d", "e"][i] assert len(table) == 3 headers = [ {'name': 'a', 'columnType': 'INTEGER'}, {'name': 'b', 'columnType': 'STRING'} ] assert headers == table.headers
def test_build_table__with_pandas_DataFrame(): df = pd.DataFrame(dict(a=[1, 2, 3], b=["c", "d", "e"])) table = build_table("test", "syn123", df) for i, row in enumerate(table): assert_equals(row[0], (i + 1)) assert_equals(row[1], ["c", "d", "e"][i]) assert_equals(len(table), 3) headers = [{ 'name': 'a', 'columnType': 'INTEGER' }, { 'name': 'b', 'columnType': 'STRING' }] assert_equals(headers, table.headers)
def test_build_table__with_csv(): string_io = StringIOContextManager('a,b\n' '1,c\n' '2,d\n' '3,e') with patch.object(synapseclient.table, "as_table_columns", return_value=[Column(name="a", columnType="INTEGER"), Column(name="b", columnType="STRING")]),\ patch.object(io, "open", return_value=string_io): table = build_table("test", "syn123", "some_file_name") for col, row in enumerate(table): assert_equals(row[0], (col + 1)) assert_equals(row[1], ["c", "d", "e"][col]) assert_equals(len(table), 3) headers = [ {'name': 'a', 'columnType': 'INTEGER'}, {'name': 'b', 'columnType': 'STRING'} ] assert_equals(headers, table.headers)
def test_build_table__with_csv(): string_io = StringIOContextManager('a,b\n' '1,c\n' '2,d\n' '3,e') with patch.object(synapseclient.table, "as_table_columns", return_value=[Column(name="a", columnType="INTEGER"), Column(name="b", columnType="STRING")]),\ patch.object(io, "open", return_value=string_io): table = build_table("test", "syn123", "some_file_name") for col, row in enumerate(table): assert_equals(row[0], (col + 1)) assert_equals(row[1], ["c", "d", "e"][col]) assert_equals(len(table), 3) headers = [{ 'name': 'a', 'columnType': 'INTEGER' }, { 'name': 'b', 'columnType': 'STRING' }] assert_equals(headers, table.headers)
def main(): gfile = '../../data/igraphPPI.pkl' g = pickle.load(open(gfile, 'rb')) #hyp.make_graph_from_dict(gfile) args = parser.parse_args() beta = 0.5 proteomics_dictionary = significant_prots(data, 'AML sample', 'Gene', 'LogFoldChange') gene_dictionary = tumor_genes(data, 'AML sample', 'Gene', 'Tumor VAF') if args.fromFile is None: hyphae = dict() hyphae['mutations'] = hyphalNetwork(gene_dictionary, g.copy(), beta) hyphae['proteomics'] = hyphalNetwork(proteomics_dictionary, g.copy(), beta) for key, this_hyp in hyphae.items(): this_hyp._to_file(key + '_amlPatientData_hypha.pkl') else: hyphae = loadFromFile(args.fromFile) #now compute graph distances to ascertain fidelity if args.getDist: res = hyStats.compute_all_distances(hyphae) res.to_csv('amlNetworkdistances.csv') tab = table.build_table("AML Network Distances", 'syn22128879', res) syn.store(tab) nmi = hyStats.compute_all_nmi(hyphae, g) nmi.to_csv('amlNMI.csv') syn.store(File('amlNMI.csv', parent='syn22269875')) #store distances for key, this_hyp in hyphae.items(): node_stats = this_hyp.node_stats() node_stats.to_csv(key + '_nodelist.csv') tab = table.build_table("AML Network Nodes", 'syn22128879', node_stats) syn.store(tab) if args.doEnrich: if len(this_hyp.forest_enrichment) == 0: for_e = hyEnrich.go_enrich_forests(this_hyp) #SG, ncbi) this_hyp.assign_enrichment(for_e, type='forest') for_e.to_csv(key + 'enrichedForestGoTerms.csv') syn.store( File(key + 'enrichedForestGoTerms.csv', parent='syn22269875')) this_hyp._to_file(key + '_amlPatientData_hypha.pkl') if len(this_hyp.community_enrichment) == 0: com_e = hyEnrich.go_enrich_communities(this_hyp) this_hyp.assign_enrichment(com_e, type='community') com_e.to_csv(key + 'enrichedCommunityGOterms.csv') syn.store( File(key + 'enrichedCommunityGOterms.csv', parent='syn22269875')) this_hyp._to_file(key + '_amlPatientData_hypha.pkl') ##next: compare enrichment between patients mapped to communities this_hyp.community_stats(prefix=key).to_csv(key + '_communityStats.csv') this_hyp.forest_stats().to_csv(key + '_TreeStats.csv') for files in [ key + '_amlPatientData_hypha.pkl', key + '_communityStats.csv', key + '_TreeStats.csv' ]: syn.store(File(files, parent='syn22269875'))