def test_writing(self): networks_table, networks = read_networks(path.join(TEST_DIR, 'network_random')) tmp_dir = path.join(TEST_DIR, 'tmp') makedirs(tmp_dir, exist_ok=True) write_networks(tmp_dir, networks_table, networks) _networks_table, _networks = read_networks(tmp_dir) self.assertTrue(networks_table.equals(_networks_table)) guid = networks_table['GUID'][0] self.assertTrue(networks[guid]['node_table'].equals(_networks[guid]['node_table'])) self.assertTrue(networks[guid]['edge_table'].equals(_networks[guid]['edge_table'])) rmtree(tmp_dir)
def test_create_networkx_graph(self): networks_table, networks = read_networks(path.join(TEST_DIR, 'network_random')) graphs = nx.from_perseus(networks_table, networks) self.assertEqual(3, len(graphs)) for i, G in enumerate(graphs): self.assertEqual(150, G.number_of_edges(), G.graph['Name']) self.assertEqual(100, G.number_of_nodes())
def test_reading_single_network(self): networks_table, networks = read_networks(path.join(TEST_DIR, 'network_random')) self.assertEqual(3, networks_table.shape[0]) self.assertEqual(3, len(networks)) for guid, name in networks_table[['GUID', 'Name']].values: network = networks[guid] self.assertEqual(name, network['name']) node_table = network['node_table'] self.assertEqual(100, node_table.shape[0]) edge_table = network['edge_table'] self.assertEqual(150, edge_table.shape[0])
def test_networkx_graph_roundtrip(self): networks_table, networks = read_networks(path.join(TEST_DIR, 'network_random')) graphs = nx.from_perseus(networks_table, networks) _networks_table, _networks = nx.to_perseus(graphs) self.assertTrue(networks_table.sort_index(axis=1).equals(_networks_table.sort_index(axis=1))) for guid in networks_table['GUID']: node_table = networks[guid]['node_table'].sort_values('Node').reset_index(drop=True) _node_table = _networks[guid]['node_table'].sort_values('Node').reset_index(drop=True) edge_table = networks[guid]['edge_table'].sort_values(['Source','Target']).reset_index(drop=True) _edge_table = _networks[guid]['edge_table'].sort_values(['Source', 'Target']).reset_index(drop=True) self.assertTrue(node_table.equals(_node_table)) self.assertTrue(edge_table.equals(_edge_table))
#source https://github.com/jdrudolph/perseuspy import sys from perseuspy import pd from perseuspy.parameters import * _, paramfile, infile, outfile = sys.argv # read arguments from the command line parameters = parse_parameters(paramfile) # parse the parameters file df = pd.read_perseus(infile) # read the input matrix into a pandas.DataFrame some_value = doubleParam(parameters, 'some value') # extract a parameter value df2 = some_value / df.drop('Name', 1) df2.to_perseus(outfile) # write pandas.DataFrame in Perseus txt format import sys from perseuspy import nx, pd, read_networks, write_networks _, paramfile, infolder, outfolder = sys.argv # read arguments from the command line networks_table, networks = read_networks(infolder) # networks in tabular form graphs = nx.from_perseus(networks_table, networks) # graphs as networkx objects _networks_table, _networks = nx.to_perseus(graphs) # convert back into tabular form write_networks(tmp_dir, networks_table, networks) # write to folder import pandas as pd data = pd.read_table("C:/Users/animeshs/OneDrive - NTNU/OneDrive - NTNU/Jimita/txt48/proteinGroups.txt",sep='\t', index_col=0, header=0, lineterminator='\n') data.head() %matplotlib inline import matplotlib.pyplot as plt import numpy as np dataLFQlog2=np.log2(dataLFQ+1) dataLFQlog2.hist() label = pd.read_table("C:/Users/animeshs/OneDrive - NTNU/OneDrive - NTNU/Jimita/txt48/Groups.txt",sep='\t', index_col=0, header=0, lineterminator='\n')