예제 #1
0
def insert_all_nodes():
    """
    reading and inserting all the nodes line by line
    """
    with open(r'projectI_hetionet\nodes.tsv')as tsvfile:
        tsvreader = csv.reader(tsvfile, delimiter="\t")
        tsv_headings = next(tsvreader)
        for line in tsvreader:
            aline = aline + 1
            if "Anatomy" in line:
                createAnatomy_node = f"""CREATE   ( Anatomy : Anatomy {{ id : "{line[0]}",  name : "{line[1]}", kind : "{line[2]}" }})"""
                a_query = f"""insert into hetionet.anatomy1(id, kind, name) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(a_query)
                insert_query(createAnatomy_node)

            if "Compound" in line:
                createCompound_node = f"""CREATE  ( Compound : Compound {{ id : "{line[0]}",  name : "{line[1]}", kind : "{line[2]}"  }})"""
                c_query = f"""insert into hetionet.compound1(id, kind, name) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(c_query)
                insert_query(createCompound_node)

            if "Disease" in line:
                createDisease_node = f"""CREATE  ( Disease : Disease {{ id : "{line[0]}",  name : "{line[1]}", kind : "{line[2]}"  }})"""
                d_query = f"""insert into hetionet.disease1(id, kind, name) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(d_query)
                insert_query(createDisease_node)

            if"Gene" in line:
                createGene_node = f"""CREATE  ( Gene : Gene {{ id : "{line[0]}",  name : "{line[1]}", kind : "{line[2]}"  }})"""
                q_query = f"""insert into hetionet.gene1(id, kind, name) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(q_query)
                insert_query(createGene_node)

        print("Numbers of nodes => ", aline, "\nNodes inserted successfully!")
def add_node():
    """
    http://127.0.0.1:5000/add_node?id=nodeID&name=nodeName&kind=nodekind
    :param: id
    :param: name
    :param: kind
    :return:
    """
    id = request.args.get('id')
    name = request.args.get('name')
    kind = request.args.get('kind')

    new_node = f"""CREATE   ( new : {kind} {{ id : "{id}",  name : "{name}", kind : "{kind}" }})"""
    insert_query(new_node)
    return json.dumps({"success": True})
def add_edges():
    """
    http://127.0.0.1:5000/add_edges?source=nodesource&metaedge=nodemetaedge&target=nodetarget
    :param: source
    :param: metaedge
    :param: target
    :return:
    """
    source = request.args.get('source')
    metaedge = request.args.get('metaedge')
    target = request.args.get('target')

    new_edge = f"""MATCH(dummy1 : {source}), (dummy2: {source}) WHERE dummy1={source} and dummy2={target}
                   CREATE (dummy1) - [:{metaedge}] -> (dummy2)
                   RETURN dummy1, dummy2 """
    insert_query(new_edge)
    return json.dumps({"success": True})
예제 #4
0
def insert_all_edges():
    with open(r'projectI_hetionet\edges.tsv')as tsvfile:
        """
        reading and appending all types of edges in list
        """
        tsvreader = csv.reader(tsvfile, delimiter="\t")
        tsv_headings = next(tsvreader)
        # appending all types of edges to list
        #['GiG', 'CrC', 'DdG', 'DlA', 'CtD', 'CbG', 'CuG', 'DrD', 'DaG', 'CpD', 'AdG', 'AuG', 'GcG', 'Gr>G', 'CdG', 'DuG', 'AeG']

        # for line in tsvreader:
        #     list = []
        #     if line[1] not in list:
        #         list.append(line[1])

        for line in tsvreader:

            if "CrC" in line:  # 6486
                print("Compound resembles Compound")
                CrC_realation = f"""MATCH (a:Compound), (b:Compound)where a.id="{line[0]}" and b.id="{line[2]}"
                                CREATE (a)-[r: {line[1]}]-> (b)
                                RETURN a, b"""
                crc = f"""insert into hetionet.relation_crc(source, metaedge, target) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(crc)
                insert_query(CrC_realation)
            if "CtD" in line:                    # 755
                print("Compound treat Disease")
                CtD_realation = f"""MATCH (a:Compound), (b:Disease)where a.id="{line[0]}" and b.id="{line[2]}"
                                CREATE (a)-[r: {line[1]}]-> (b)
                                RETURN a, b"""
                ctd = f"""insert into hetionet.relation_ctd(source, metaedge, target) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(ctd)
                insert_query(CtD_realation)
            if "CpD" in line:                      # 390
                print("Compound palliates Disease")
                CpD_realation = f"""MATCH (a:Compound), (b:Disease)where a.id="{line[0]}" and b.id="{line[2]}"
                                CREATE (a)-[r: {line[1]}]-> (b)
                                RETURN a, b"""
                cpd = f"""insert into hetionet.relation_cpd(source, metaedge, target) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                print(cpd)
                cqlsh(cpd)
                insert_query(CpD_realation)
            if "CuG" in line:                       # 18756
                print("Compound upregulates Gene")
                CuG_realation = f"""MATCH (a:Compound), (b:Gene)where a.id="{line[0]}" and b.id="{line[2]}"
                                CREATE (a)-[r: {line[1]}]-> (b)
                                RETURN a, b"""
                cug = f"""insert into hetionet.relation_cug(source, metaedge, target) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(cug)
                insert_query(CuG_realation)
            if "CbG" in line:                      # 11571
                print("Compound binds Gene")
                CbG_realation = f"""MATCH (a:Compound), (b:Gene)where a.id="{line[0]}" and b.id="{line[2]}"
                                CREATE (a)-[r: {line[1]}]-> (b)
                                RETURN a, b"""
                cbg = f"""insert into hetionet.relation_cbg(source, metaedge, target) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(cbg)
                insert_query(CbG_realation)
            if "CdG" in line:                      # 21102
                print("Compound downregulates Gene")
                CdG_realation = f"""MATCH (a:Compound), (b:Gene)where a.id="{line[0]}" and b.id="{line[2]}"
                                CREATE (a)-[r: {line[1]}]-> (b)
                                RETURN a, b"""
                cdg = f"""insert into hetionet.relation_cdg(source, metaedge, target) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(cdg)
                insert_query(CdG_realation)



            if "DrD" in line:                       # 543
                print("Disease resembles Disease")
                DrD_realation = f"""MATCH (a:Disease), (b:Disease)where a.id="{line[0]}" and b.id="{line[2]}"
                                CREATE (a)-[r: {line[1]}]-> (b)
                                RETURN a, b"""
                drd = f"""insert into hetionet.relation_drd(source, metaedge, target) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(drd)
                insert_query(DrD_realation)
            if "DuG" in line:                         # 7731
                print("Disease upregulates Gene")
                DuG_realation = f"""MATCH (a:Disease), (b:Gene)where a.id="{line[0]}" and b.id="{line[2]}"
                                CREATE (a)-[r: {line[1]}]-> (b)
                                RETURN a, b"""
                dug = f"""insert into hetionet.relation_dug(source, metaedge, target) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(dug)
                insert_query(DuG_realation)
            if "DaG" in line:                         # 12623
                print("Disease associates Gene")
                DaG_realation = f"""MATCH (a:Disease), (b:Gene)where a.id="{line[0]}" and b.id="{line[2]}"
                                CREATE (a)-[r: {line[1]}]-> (b)
                                RETURN a, b"""
                dag = f"""insert into hetionet.relation_dag(source, metaedge, target) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(dag)
                insert_query(DaG_realation)
            if "DdG" in line:                        # 7623
                print("Disease downregulates Gene")
                DdG_realation = f"""MATCH (a:Disease), (b:Gene)where a.id="{line[0]}" and b.id="{line[2]}"
                                CREATE (a)-[r: {line[1]}]-> (b)
                                RETURN a, b"""
                ddg = f"""insert into hetionet.relation_ddg(source, metaedge, target) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(ddg)
                insert_query(DdG_realation)
            if "DlA" in line:                       # 3602
                print("disease localizes Anatomy")
                DlA_realation = f"""MATCH (a:Disease), (b:Anatomy)where a.id="{line[0]}" and b.id="{line[2]}"
                                CREATE (a)-[r: {line[1]}]-> (b)
                                RETURN a, b"""
                dla = f"""insert into hetionet.relation_dla(source, metaedge, target) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(dla)
                insert_query(DlA_realation)


            if "AuG" in line:                  # 97848
                print("Anatomy upregulates Gene")
                AuG_realation = f"""MATCH (a:Anatomy), (b:Gene)where a.id="{line[0]}" and b.id="{line[2]}"
                                CREATE (a)-[r: {line[1]}]-> (b)
                                RETURN a, b"""
                aug = f"""insert into hetionet.relation_aug(source, metaedge, target) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(aug)
                insert_query(AuG_realation)
            if "AeG" in line:                   # 526407
                print("Anatomy express Gene")
                AeG_realation = f"""MATCH (a:Anatomy), (b:Gene)where a.id="{line[0]}" and b.id="{line[2]}"
                                CREATE (a)-[r: {line[1]}]-> (b)
                                RETURN a, b"""
                aeg = f"""insert into hetionet.relation_aeg(source, metaedge, target) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(aeg)
                insert_query(AeG_realation)
            if "AdG" in line:                     # 102240
                # print("Anatomy downregulates Gene")
                AdG_realation = f"""MATCH (a:Anatomy), (b:Gene)where a.id="{line[0]}" and b.id="{line[2]}"
                                CREATE (a)-[r: {line[1]}]-> (b)
                                RETURN a, b"""
                adg = f"""insert into hetionet.relation_adg(source, metaedge, target) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(adg)
                insert_query(AdG_realation)



            if "GiG" in line:                 # 147164
                print("Gene interacts Gene")
                GiG_realation = f"""MATCH (a:Gene), (b:Gene)where a.id="{line[0]}" and b.id="{line[2]}"
                                CREATE (a)-[r: {line[1]}]-> (b)
                                RETURN a, b"""
                gig = f"""insert into hetionet.relation_gig(source, metaedge, target) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(gig)
                insert_query(GiG_realation)
            if "GcG" in line:                 # 61690
                print("Gene covaries Gene")
                GcG_realation = f"""MATCH (a:Gene), (b:Gene)where a.id="{line[0]}" and b.id="{line[2]}"
                                CREATE (a)-[r: {line[1]}]-> (b)
                                RETURN a, b"""
                gcg = f"""insert into hetionet.relation_gcg(source, metaedge, target) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(gcg)
                insert_query(GcG_realation)
            if "Gr>G" in line:                     # 265672
                print("Gene regulates Gene")
                Gr_G_realation = f"""MATCH (a:Gene), (b:Gene)where a.id="{line[0]}" and b.id="{line[2]}"
                                CREATE (a)-[r: Gr_G]-> (b)
                                RETURN a, b"""
                grg = f"""insert into hetionet.relation_grg(source, metaedge, target) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(grg)
                insert_query(Gr_G_realation)
예제 #5
0
import csv
from Cassandra.CQLsh import cqlsh
from Neo4j.query import insert_query


"""Creating dummy relationship: "KNOWS"  to check DB connection"""
dummy_edge = """MATCH  (dummy1: dummy), (dummy2: dummy) where dummy1.name="dummy" and dummy2.name="dummy"
                CREATE (dummy1) - [KNOWS : KNOWS ] -> (dummy2)
                RETURN dummy1, dummy2"""
insert_query(dummy_edge)


def insert_all_edges():
    with open(r'projectI_hetionet\edges.tsv')as tsvfile:
        """
        reading and appending all types of edges in list
        """
        tsvreader = csv.reader(tsvfile, delimiter="\t")
        tsv_headings = next(tsvreader)
        # appending all types of edges to list
        #['GiG', 'CrC', 'DdG', 'DlA', 'CtD', 'CbG', 'CuG', 'DrD', 'DaG', 'CpD', 'AdG', 'AuG', 'GcG', 'Gr>G', 'CdG', 'DuG', 'AeG']

        # for line in tsvreader:
        #     list = []
        #     if line[1] not in list:
        #         list.append(line[1])

        for line in tsvreader:

            if "CrC" in line:  # 6486
                print("Compound resembles Compound")
예제 #6
0
import csv
from Cassandra.CQLsh import cqlsh
from Neo4j.query import insert_query

"""Dummy insertion to check DB connection"""
dummy_node = """CREATE (dummy_node: dummy{name: "dummy"})"""
insert_query(dummy_node)


aline = 0  # line counter


def insert_all_nodes():
    """
    reading and inserting all the nodes line by line
    """
    with open(r'projectI_hetionet\nodes.tsv')as tsvfile:
        tsvreader = csv.reader(tsvfile, delimiter="\t")
        tsv_headings = next(tsvreader)
        for line in tsvreader:
            aline = aline + 1
            if "Anatomy" in line:
                createAnatomy_node = f"""CREATE   ( Anatomy : Anatomy {{ id : "{line[0]}",  name : "{line[1]}", kind : "{line[2]}" }})"""
                a_query = f"""insert into hetionet.anatomy1(id, kind, name) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(a_query)
                insert_query(createAnatomy_node)

            if "Compound" in line:
                createCompound_node = f"""CREATE  ( Compound : Compound {{ id : "{line[0]}",  name : "{line[1]}", kind : "{line[2]}"  }})"""
                c_query = f"""insert into hetionet.compound1(id, kind, name) values( '{line[0]}' , '{line[1]}' , '{line[2]}');"""
                cqlsh(c_query)