def load_pairsinfo(self, pairs_filename):
        row_count, table_data = ming_fileio_library.parse_table_with_headers(
            pairs_filename)

        if "CLUSTERID1" in table_data:
            for i in range(row_count):
                node1 = table_data["CLUSTERID1"][i]
                node2 = table_data["CLUSTERID2"][i]
                cosine = table_data["Cosine"][i]
                deltamz = table_data["DeltaMZ"][i]
                pair = NetworkPair(node1, node2, cosine, deltamz)
                self.pairs.append(pair)
        else:
            row_count, table_data = ming_fileio_library.parse_table_without_headers(
                pairs_filename)
            for i in range(row_count):
                node1 = table_data[0][i]
                node2 = table_data[1][i]
                cosine = table_data[4][i]
                deltamz = table_data[2][i]
                pair = NetworkPair(node1, node2, cosine, deltamz)
                self.pairs.append(pair)

        #Make stuff consistent, specifically adding adjacency list
        for pair in self.pairs:
            node1 = pair.node1
            node2 = pair.node2

            if not (node1 in self.index_to_neighbors):
                self.index_to_neighbors[node1] = []

            if not (node2 in self.index_to_neighbors):
                self.index_to_neighbors[node2] = []

            self.index_to_neighbors[node1].append(node2)
            self.index_to_neighbors[node2].append(node1)
	def load_pairsinfo(self, pairs_filename):
		row_count, table_data = ming_fileio_library.parse_table_with_headers(pairs_filename)

		if "CLUSTERID1" in table_data:
			for i in range(row_count):
				node1 = table_data["CLUSTERID1"][i]
				node2 = table_data["CLUSTERID2"][i]
				cosine = table_data["Cosine"][i]
				deltamz = table_data["DeltaMZ"][i]
				pair = NetworkPair(node1, node2, cosine, deltamz)
				self.pairs.append(pair)
		else:
			row_count, table_data = ming_fileio_library.parse_table_without_headers(pairs_filename)
			for i in range(row_count):
				node1 = table_data[0][i]
				node2 = table_data[1][i]
				cosine = table_data[4][i]
				deltamz = table_data[2][i]
				pair = NetworkPair(node1, node2, cosine, deltamz)
				self.pairs.append(pair)



		#Make stuff consistent, specifically adding adjacency list
		for pair in self.pairs:
			node1 = pair.node1
			node2 = pair.node2

			if not(node1 in self.index_to_neighbors):
				self.index_to_neighbors[node1] = []

			if not(node2 in self.index_to_neighbors):
				self.index_to_neighbors[node2] = []

			self.index_to_neighbors[node1].append(node2)
			self.index_to_neighbors[node2].append(node1)
Пример #3
0
def loading_network(filename, hasHeaders=False, edgetype="Cosine"):
    node1_list = []
    node2_list = []

    mass_difference = []
    property1 = []
    cosine_score = []
    explained_intensity = []
    edge_annotation = []

    if hasHeaders == True:
        row_count, table_data = ming_fileio_library.parse_table_with_headers(filename)

        if row_count == -1:
            return nx.MultiGraph()

        node1_list = table_data["CLUSTERID1"]
        node2_list = table_data["CLUSTERID2"]

        mass_difference = table_data["DeltaMZ"]
        property1 = table_data["MEH"]
        cosine_score = None
        if "Cosine" in table_data:
            cosine_score = table_data["Cosine"]
        if "COSINE" in table_data:
            cosine_score = table_data["COSINE"]
        
        if "OtherScore" in table_data:
            explained_intensity = table_data["OtherScore"]

        if len(property1)  != len(node1_list):
            property1 = node1_list
        if len(explained_intensity)  != len(node1_list):
            explained_intensity = node1_list
        if "EdgeAnnotation" in table_data:
            edge_annotation = table_data["EdgeAnnotation"]
        else:
            edge_annotation = [" "] * len(node1_list)

    else:
        row_count, table_data = ming_fileio_library.parse_table_without_headers(filename)

        if row_count == -1:
            return nx.MultiGraph()

        node1_list = table_data[0]
        node2_list = table_data[1]

        mass_difference = table_data[2]
        property1 = table_data[3]
        cosine_score = table_data[4]
        explained_intensity = table_data[5]
        edge_annotation = [" "] * len(node1_list)

    edge_property_map = {}
    edge_object_list = []
    intermediate_graph_nodes = set()
    intermediate_edges_to_add = []
    for i in range(row_count):
        edge_object = {}
        edge_object["node1"] = node1_list[i]
        edge_object["node2"] = node2_list[i]
        edge_object["mass_difference"] = mass_difference[i]
        edge_object["property1"] = property1[i]
        edge_object["cosine_score"] = float(cosine_score[i])
        edge_object["explained_intensity"] = float(explained_intensity[i])
        edge_object["component"] = -1
        edge_object["EdgeType"] = edgetype
        edge_object["EdgeAnnotation"] = edge_annotation[i].rstrip()
        edge_object["EdgeScore"] = float(cosine_score[i])

        edge_key = node1_list[i] + "-" + node2_list[i]

        edge_property_map[edge_key] = edge_object

        intermediate_graph_nodes.add(edge_object["node1"])
        intermediate_graph_nodes.add(edge_object["node2"])

        # set key to edgetype for options to remove edge later in case multiple edges are present
        edge_key_for_dict = CONST.EDGE.COSINE_TYPE
        intermediate_edges_to_add.append((edge_object["node1"], edge_object["node2"], edge_key_for_dict, edge_object))

    G=nx.MultiGraph()
    G.add_nodes_from(intermediate_graph_nodes)
    G.add_edges_from(intermediate_edges_to_add)

    return G
def loading_network(filename, hasHeaders=False):
    node1_list = []
    node2_list = []

    mass_difference = []
    property1 = []
    cosine_score = []
    explained_intensity = []
    edge_annotation = []

    if hasHeaders == True:
        row_count, table_data = ming_fileio_library.parse_table_with_headers(filename)

        if row_count == -1:
            return nx.MultiGraph()

        node1_list = table_data["CLUSTERID1"]
        node2_list = table_data["CLUSTERID2"]

        mass_difference = table_data["DeltaMZ"]
        property1 = table_data["MEH"]
        cosine_score = None
        if "Cosine" in table_data:
            cosine_score = table_data["Cosine"]
        if "COSINE" in table_data:
            cosine_score = table_data["COSINE"]
        explained_intensity = table_data["OtherScore"]

        if len(property1)  != len(node1_list):
            property1 = node1_list
        if len(explained_intensity)  != len(node1_list):
            explained_intensity = node1_list
        if "EdgeAnnotation" in table_data:
            edge_annotation = table_data["EdgeAnnotation"]
        else:
            edge_annotation = [" "] * len(node1_list)

    else:
        row_count, table_data = ming_fileio_library.parse_table_without_headers(filename)

        if row_count == -1:
            return nx.MultiGraph()

        node1_list = table_data[0]
        node2_list = table_data[1]

        mass_difference = table_data[2]
        property1 = table_data[3]
        cosine_score = table_data[4]
        explained_intensity = table_data[5]
        edge_annotation = [" "] * len(node1_list)

    edge_property_map = {}
    edge_object_list = []
    intermediate_graph_nodes = set()
    intermediate_edges_to_add = []
    for i in range(row_count):
        edge_object = {}
        edge_object["node1"] = node1_list[i]
        edge_object["node2"] = node2_list[i]
        edge_object["mass_difference"] = mass_difference[i]
        edge_object["property1"] = property1[i]
        edge_object["cosine_score"] = float(cosine_score[i])
        edge_object["explained_intensity"] = float(explained_intensity[i])
        edge_object["component"] = -1
        edge_object["EdgeType"] = "Cosine"
        edge_object["EdgeAnnotation"] = edge_annotation[i].rstrip()
        edge_object["EdgeScore"] = float(cosine_score[i])

        edge_key = node1_list[i] + "-" + node2_list[i]

        edge_property_map[edge_key] = edge_object

        intermediate_graph_nodes.add(edge_object["node1"])
        intermediate_graph_nodes.add(edge_object["node2"])

        intermediate_edges_to_add.append((edge_object["node1"], edge_object["node2"], edge_object))

    G=nx.MultiGraph()
    G.add_nodes_from(intermediate_graph_nodes)
    G.add_edges_from(intermediate_edges_to_add)

    return G
Пример #5
0
def loading_network(filename, hasHeaders=False):
    node1_list = []
    node2_list = []

    mass_difference = []
    property1 = []
    cosine_score = []
    explained_intensity = []

    if hasHeaders == True:
        row_count, table_data = ming_fileio_library.parse_table_with_headers(
            filename)

        if row_count == -1:
            return nx.Graph()

        node1_list = table_data["CLUSTERID1"]
        node2_list = table_data["CLUSTERID2"]

        mass_difference = table_data["DeltaMZ"]
        property1 = table_data["MEH"]
        cosine_score = None
        if "Cosine" in table_data:
            cosine_score = table_data["Cosine"]
        if "COSINE" in table_data:
            cosine_score = table_data["COSINE"]
        explained_intensity = table_data["OtherScore"]

        if len(property1) != len(node1_list):
            property1 = node1_list
        if len(explained_intensity) != len(node1_list):
            explained_intensity = node1_list
    else:
        row_count, table_data = ming_fileio_library.parse_table_without_headers(
            filename)

        if row_count == -1:
            return nx.Graph()

        node1_list = table_data[0]
        node2_list = table_data[1]

        mass_difference = table_data[2]
        property1 = table_data[3]
        cosine_score = table_data[4]
        explained_intensity = table_data[5]

    edge_property_map = {}
    edge_object_list = []
    intermediate_graph_nodes = set()
    intermediate_edges_to_add = []
    for i in range(row_count):
        edge_object = {}
        edge_object["node1"] = node1_list[i]
        edge_object["node2"] = node2_list[i]
        edge_object["mass_difference"] = mass_difference[i]
        edge_object["property1"] = property1[i]
        edge_object["cosine_score"] = float(cosine_score[i])
        edge_object["explained_intensity"] = float(explained_intensity[i])
        edge_object["component"] = -1

        edge_key = node1_list[i] + "-" + node2_list[i]

        edge_property_map[edge_key] = edge_object

        intermediate_graph_nodes.add(edge_object["node1"])
        intermediate_graph_nodes.add(edge_object["node2"])

        intermediate_edges_to_add.append(
            (edge_object["node1"], edge_object["node2"], edge_object))

    G = nx.Graph()
    G.add_nodes_from(intermediate_graph_nodes)
    G.add_edges_from(intermediate_edges_to_add)

    return G