Example #1
0
def integrator(request, memory=True, header=False):

    main(memory=memory, header=header)
    pathToFile = os.path.join(settings.PROJECT_ROOT, 'apps', 'interactions',
                              'merged.txt')
    fields = ('id_a', 'id_b', 'alias_a', 'alias_b', 'system', 'type', 'method',
              'modification', 'taxid_a', 'taxid_b', 'pmid', 'source', 'score')

    # Raw sql triggered direct insertion of the file:
    sql = "load data infile '%s' into table %s_%s columns terminated by '\t'"\
     "lines terminated by '\n'(%s);"\
          % (pathToFile,'interactions','interaction'"", ", ".join(fields))

    #234567891123456789212345678931234567894123456789512345678961234567897123456789

    cursor = connection.cursor()
    cursor.execute('TRUNCATE TABLE interactions_interaction;')
    cursor.execute(sql)
    #row = cursor.fetchone()
    #print row

    print sql
    query = Interaction.objects.raw(sql)
    #    print query

    # Reading and inserting via Django ORM (works, but is too slow):
    #    f = fileinput.input(os.path.join(settings.PROJECT_ROOT, 'apps', 'interactions', 'merged.txt'))
    #    interactions = []
    #    for line in f:
    #        if header:
    #            header = False
    #            continue
    #        values = line.replace('\n', '').split('\t')
    #        #print values
    #        input = dict(zip(fields, values))
    #        interaction = Interaction()
    #        interaction.__dict__.update(input)
    #        #interaction.save()
    #        interactions.append(interaction)
    #    f.close()
    #    Interaction.objects.bulk_create(interactions)

    # Alternative direct insertion via python-MySQLdb:
    #    import MySQLdb as mysql
    #    mydb = mysql.connect(user='******', db='denigma')
    #    cursor = mydb.cursor()
    #    handle = cursor.execute(sql)
    #    print handle

    msg = "Successfully integrated interactions"
    messages.add_message(request, messages.SUCCESS, msg)
    return redirect('/interactions/')


#234567891123456789212345678931234567893
Example #2
0
def integrator(request, memory=True, header=False):

    main(memory=memory, header=header)
    pathToFile = os.path.join(settings.PROJECT_ROOT, 'apps', 'interactions', 'merged.txt')
    fields = ('id_a', 'id_b',
              'alias_a', 'alias_b',
              'system', 'type', 'method', 'modification',
              'taxid_a', 'taxid_b',
              'pmid', 'source', 'score')

    # Raw sql triggered direct insertion of the file:
    sql = "load data infile '%s' into table %s_%s columns terminated by '\t'"\
     "lines terminated by '\n'(%s);"\
          % (pathToFile,'interactions','interaction'"", ", ".join(fields))


#234567891123456789212345678931234567894123456789512345678961234567897123456789

    cursor = connection.cursor()
    cursor.execute('TRUNCATE TABLE interactions_interaction;')
    cursor.execute(sql)
    #row = cursor.fetchone()
    #print row

    print sql
    query = Interaction.objects.raw(sql)
    #    print query


    # Reading and inserting via Django ORM (works, but is too slow):
#    f = fileinput.input(os.path.join(settings.PROJECT_ROOT, 'apps', 'interactions', 'merged.txt'))
#    interactions = []
#    for line in f:
#        if header:
#            header = False
#            continue
#        values = line.replace('\n', '').split('\t')
#        #print values
#        input = dict(zip(fields, values))
#        interaction = Interaction()
#        interaction.__dict__.update(input)
#        #interaction.save()
#        interactions.append(interaction)
#    f.close()
#    Interaction.objects.bulk_create(interactions)





     # Alternative direct insertion via python-MySQLdb:
#    import MySQLdb as mysql
#    mydb = mysql.connect(user='******', db='denigma')
#    cursor = mydb.cursor()
#    handle = cursor.execute(sql)
#    print handle

    msg = "Successfully integrated interactions"
    messages.add_message(request, messages.SUCCESS, msg)
    return redirect('/interactions/')
#234567891123456789212345678931234567893
Example #3
0
def update(request, db="BioGRID"):
    exec("from %s import main" % db)
    main()
    return redirect('/interactions/')
Example #4
0
def update(request, db="BioGRID"):
    exec("from %s import main" % db)
    main()
    return redirect('/interactions/')