Example #1
0
def update_gosupportevidence(nex_session, annotation_id, gosupport,
                             annotation_id_to_support_evidences, date_created,
                             created_by, annotation_type,
                             annotation_update_log, fw):

    key_to_support = {}
    if annotation_id in annotation_id_to_support_evidences:
        key_to_support = annotation_id_to_support_evidences[annotation_id]

    groups = gosupport.split('|')
    seen_this_group = {}
    group_id = 0
    for group in groups:
        if group in seen_this_group:
            continue
        seen_this_group[group] = 1
        if group.startswith('With:Not_supplied'):
            break
        dbxref_ids = group.split(',')
        group_id = group_id + 1
        seen_this_id = {}
        for dbxref_id in dbxref_ids:
            if dbxref_id in seen_this_id:
                continue
            seen_this_id[dbxref_id] = 1
            if dbxref_id.startswith('EcoGene:') or dbxref_id.startswith(
                    'UniPathway:'):
                continue
            link = get_go_extension_link(dbxref_id)
            if link.startswith('Unknown'):
                print("Unknown ID: ", dbxref_id)
                continue
            evidence_type = 'with'
            if dbxref_id.startswith('GO:'):
                evidence_type = 'from'

            key = (group_id, evidence_type, dbxref_id)

            if key in key_to_support:
                # print "GO supporting evidence ", key, " is in the database"
                x = key_to_support.pop(key)
                if x.obj_url != link:
                    x.obj_url = link
                    nex_session.add(x)
                    nex_session.flush()
            else:
                # print "NEW GO supporting evidence ", key
                thisSupport = Gosupportingevidence(annotation_id=annotation_id,
                                                   group_id=group_id,
                                                   dbxref_id=dbxref_id,
                                                   obj_url=link,
                                                   evidence_type=evidence_type,
                                                   date_created=date_created,
                                                   created_by=created_by)

                fw.write("NEW GOSUPPORTINGEVIDENCE: key=" + str(key) + "\n")
                nex_session.add(thisSupport)
                key = (annotation_type, 'supportevidence_added')
                annotation_update_log[key] = annotation_update_log[key] + 1

    to_be_deleted = list(key_to_support.values())

    for row in to_be_deleted:

        # print "DELETE GO supporting evidence ", row.annotation_id, row.group_id, row.evidence_type, row.dbxref_id

        fw.write("DELETE GOSUPPORTINGEVIDENCE: row=" + str(row) + "\n")
        nex_session.delete(row)
        key = (annotation_type, 'supportevidence_deleted')
        annotation_update_log[key] = annotation_update_log[key] + 1
    nex_session.commit()
Example #2
0
def update_goextension(nex_session, annotation_id, goextension,
                       annotation_id_to_extensions, date_created, created_by,
                       annotation_type, annotation_update_log, fw):

    key_to_extension = {}
    if annotation_id in annotation_id_to_extensions:
        key_to_extension = annotation_id_to_extensions[annotation_id]

    groups = goextension.split('|')
    seen_this_group = {}
    group_id = 0
    for group in groups:
        if group in seen_this_group:
            continue
        seen_this_group[group] = 1
        members = group.split(',')
        group_id = group_id + 1
        seen_this_member = {}
        for member in members:
            if member in seen_this_member:
                continue
            seen_this_member[member] = 1
            pieces = member.split('(')
            role = pieces[0].replace('_', ' ')
            ro_id = get_relation_to_ro_id(role)
            if ro_id is None:
                print(role, " is not in RO table.")
                continue

            dbxref_id = pieces[1][:-1]
            if dbxref_id.startswith('EcoGene:') or dbxref_id.startswith(
                    'UniPathway:'):
                continue
            link = get_go_extension_link(dbxref_id)
            if link.startswith('Unknown'):
                if dbxref_id.startswith('IntAct:'):
                    continue
                else:
                    print("Unknown ID: ", dbxref_id)
                    continue

            key = (group_id, ro_id, dbxref_id)
            if key in key_to_extension:
                # print "GO extension ", key, " is in the database."
                x = key_to_extension.pop(key)
                if x.obj_url != link:
                    x.obj_url = link
                    nex_session.add(x)
                    nex_session.flush()
            else:

                # print "NEW GO extension ", key

                thisExtension = Goextension(annotation_id=annotation_id,
                                            group_id=group_id,
                                            dbxref_id=dbxref_id,
                                            obj_url=link,
                                            ro_id=ro_id,
                                            date_created=date_created,
                                            created_by=created_by)
                fw.write("NEW GOEXTENSION: key=" + str(key) + "\n")
                nex_session.add(thisExtension)
                key = (annotation_type, 'extension_added')
                annotation_update_log[key] = annotation_update_log[key] + 1
    to_be_deleted = list(key_to_extension.values())

    for row in to_be_deleted:

        # print "DELETE GO extension: ", row.annotation_id, row.group_id, row.ro_id, row.dbxref_id

        fw.write("DELETE GOEXTENSION: row=" + str(row) + "\n")
        nex_session.delete(row)
        key = (annotation_type, 'extension_deleted')
        annotation_update_log[key] = annotation_update_log[key] + 1
    nex_session.commit()