scripts/support/update_go_terms.py
def update_desc_go_terms(go_term_list, desc_file_path):
    """
    Modifies a valid family DESC file, by adding GO terms listed in go_term_list

    go_term_list: A list of GO term/description tuples to include in the DESC file
    desc_file_path: The path to a valid Rfam DESC file

    return: void
    """

    desc_fp = open(desc_file_path, 'r')
    desc_lines = desc_fp.readlines()
    desc_fp.close()

    new_desc_fp = open(os.path.join(os.path.split(desc_file_path)[0], "DESC_new"), 'w')

    idx = 0
    # loop once until we reach DR lines
    while idx < len(desc_lines):

        # break the loop if DR line found
        if desc_lines[idx][0:2] == 'DR':
            break

        new_desc_fp.write(desc_lines[idx])
        idx += 1

    # loop over all DR lines
    while idx < len(desc_lines):
        # break the loop if DR line found
        if desc_lines[idx][0:2] != 'DR':
            break

        # skip all GO terms
        elif desc_lines[idx].find('GO') == -1:
            new_desc_fp.write(desc_lines[idx])

        idx += 1

    # add new GO lines (e.g. GO; 0006396; RNA processing;)
    for go_pair in go_term_list:
        new_desc_fp.write('DR   GO; ' + go_pair[0].replace('GO:', '') + '; ' + go_pair[1] + ';\n')

    # write the remaining DESC lines
    while idx < len(desc_lines):
        new_desc_fp.write(desc_lines[idx])

        idx += 1

    new_desc_fp.close()

    # delete old DESC
    os.remove(desc_file_path)

    # rename DESC_new to DESC
    os.rename(os.path.join(os.path.split(desc_file_path)[0], "DESC_new"),
              os.path.join(os.path.split(desc_file_path)[0], "DESC"))

    Modifies a valid family DESC file, by adding GO terms listed in go_term_list

    go_term_list: A list of GO term/description tuples to include in the DESC file
    desc_file_path: The path to a valid Rfam DESC file

    return: void
    
Modifies a valid family DESC file, by adding GO terms listed in go_term_list
go_term_list: A list of GO term/description tuples to include in the DESC file
desc_file_path: The path to a valid Rfam DESC file

void
Modifies a valid family DESC file by adding GO terms listed in go_term_list go_term_list : A list of GO term / description tuples to include in the DESC file desc_file_path : The path to a valid Rfam DESC file void
def update_desc_go_terms(go_term_list, desc_file_path):
    desc_fp = open(desc_file_path, 'r')
    desc_lines = desc_fp.readlines()
    desc_fp.close()
    new_desc_fp = open(os.path.join(os.path.split(desc_file_path)[0], "DESC_new"), 'w')
    idx = 0
    while idx < len(desc_lines):
        if desc_lines[idx][0:2] == 'DR':
            break
        new_desc_fp.write(desc_lines[idx])
        idx += 1
    while idx < len(desc_lines):
        if desc_lines[idx][0:2] != 'DR':
            break
        elif desc_lines[idx].find('GO') == -1:
            new_desc_fp.write(desc_lines[idx])
        idx += 1
    for go_pair in go_term_list:
        new_desc_fp.write('DR   GO; ' + go_pair[0].replace('GO:', '') + '; ' + go_pair[1] + ';\n')
    while idx < len(desc_lines):
        new_desc_fp.write(desc_lines[idx])
        idx += 1
    new_desc_fp.close()
    os.remove(desc_file_path)
    os.rename(os.path.join(os.path.split(desc_file_path)[0], "DESC_new"),
              os.path.join(os.path.split(desc_file_path)[0], "DESC"))
def update_desc_go_terms ( go_term_list , desc_file_path ) : desc_fp = open ( desc_file_path , 'r' ) desc_lines = desc_fp . readlines ( ) desc_fp . close ( ) new_desc_fp = open ( os . path . join ( os . path . split ( desc_file_path ) [ 0 ] , "DESC_new" ) , 'w' ) idx = 0 while idx < len ( desc_lines ) : if desc_lines [ idx ] [ 0 : 2 ] == 'DR' : break new_desc_fp . write ( desc_lines [ idx ] ) idx += 1 while idx < len ( desc_lines ) : if desc_lines [ idx ] [ 0 : 2 ] != 'DR' : break elif desc_lines [ idx ] . find ( 'GO' ) == - 1 : new_desc_fp . write ( desc_lines [ idx ] ) idx += 1 for go_pair in go_term_list : new_desc_fp . write ( 'DR   GO; ' + go_pair [ 0 ] . replace ( 'GO:' , '' ) + '; ' + go_pair [ 1 ] + ';\n' ) while idx < len ( desc_lines ) : new_desc_fp . write ( desc_lines [ idx ] ) idx += 1 new_desc_fp . close ( ) os . remove ( desc_file_path ) os . rename ( os . path . join ( os . path . split ( desc_file_path ) [ 0 ] , "DESC_new" ) , os . path . join ( os . path . split ( desc_file_path ) [ 0 ] , "DESC" ) )
Modifies a valid family DESC file, by adding GO terms listed in go_term_list
go_term_list: A list of GO term/description tuples to include in the DESC file
desc_file_path: The path to a valid Rfam DESC file
Modifies a valid family DESC file by adding GO terms listed in go_term_list go_term_list : A list of GO term / description tuples to include in the DESC file desc_file_path : The path to a valid Rfam DESC file
"""
    Modifies a valid family DESC file, by adding GO terms listed in go_term_list

    go_term_list: A list of GO term/description tuples to include in the DESC file
    desc_file_path: The path to a valid Rfam DESC file

    return: void
    """ # loop once until we reach DR lines # break the loop if DR line found # loop over all DR lines # break the loop if DR line found # skip all GO terms # add new GO lines (e.g. GO; 0006396; RNA processing;) # write the remaining DESC lines # delete old DESC # rename DESC_new to DESC
go_term_list
desc_file_path