utils/db_utils.py
def load_clan_seqs_from_db(clan_acc):  # tested
    """
    Loads specific clan family sequences from full_region table and returns
    a dictionary structure as {Rfam_acc:{Rfseq_acc:[start, end, evalue]}}
    for clan competition.

    This has been modified to accommodate sequence duplicates

    clan_acc: Clan accession as in Rfam
    """

    fam_seqs = {}

    # connect to db
    cnx = RfamDB.connect()

    # get a new buffered cursor
    cursor = cnx.cursor(raw=True)

    # Fetch clan specific family full_region data
    query = ("SELECT full_region.rfam_acc, full_region.rfamseq_acc, \
      full_region.seq_start, full_region.seq_end, full_region.evalue_score\n"
      "FROM full_region\n"
      "JOIN (SELECT rfam_acc FROM clan_membership WHERE clan_acc=\'%s\') as CLAN_FAMS\n"
      "ON CLAN_FAMS.rfam_acc=full_region.rfam_acc") % (clan_acc)

    # execute the query
    cursor.execute(query)

    # build family dictionary of sequences
    for row in cursor:

      if str(row[RFAM_ACC]) in fam_seqs.keys():

        if str(row[SEQ_ACC]) in fam_seqs[str(row[RFAM_ACC])].keys():

          fam_seqs[str(row[RFAM_ACC])][str(row[SEQ_ACC])].append(
            (int(row[START]), int(row[END]), float(row[EVAL])))
        else:
            fam_seqs[str(row[RFAM_ACC])][str(row[SEQ_ACC])] = [(int(row[START]),
            int(row[END]), float(row[EVAL]))]
      else:
          fam_seqs[str(row[RFAM_ACC])] = {
          str(row[SEQ_ACC]): [(int(row[START]), int(row[END]), float(row[EVAL]))]}

    # close cursor and DB connection
    cursor.close()
    RfamDB.disconnect(cnx)

    return fam_seqs

    Loads specific clan family sequences from full_region table and returns
    a dictionary structure as {Rfam_acc:{Rfseq_acc:[start, end, evalue]}}
    for clan competition.

    This has been modified to accommodate sequence duplicates

    clan_acc: Clan accession as in Rfam
    
Loads specific clan family sequences from full_region table and returns
a dictionary structure as {Rfam_acc:{Rfseq_acc:[start, end, evalue]}}
for clan competition.

This has been modified to accommodate sequence duplicates

Clan accession as in Rfam
Loads specific clan family sequences from full_region table and returns a dictionary structure as { Rfam_acc : { Rfseq_acc : [ start end evalue ] }} for clan competition . This has been modified to accommodate sequence duplicates Clan accession as in Rfam
def load_clan_seqs_from_db(clan_acc):  
    fam_seqs = {}
    cnx = RfamDB.connect()
    cursor = cnx.cursor(raw=True)
    query = ("SELECT full_region.rfam_acc, full_region.rfamseq_acc, \
      full_region.seq_start, full_region.seq_end, full_region.evalue_score\n"
      "FROM full_region\n"
      "JOIN (SELECT rfam_acc FROM clan_membership WHERE clan_acc=\'%s\') as CLAN_FAMS\n"
      "ON CLAN_FAMS.rfam_acc=full_region.rfam_acc") % (clan_acc)
    cursor.execute(query)
    for row in cursor:
      if str(row[RFAM_ACC]) in fam_seqs.keys():
        if str(row[SEQ_ACC]) in fam_seqs[str(row[RFAM_ACC])].keys():
          fam_seqs[str(row[RFAM_ACC])][str(row[SEQ_ACC])].append(
            (int(row[START]), int(row[END]), float(row[EVAL])))
        else:
            fam_seqs[str(row[RFAM_ACC])][str(row[SEQ_ACC])] = [(int(row[START]),
            int(row[END]), float(row[EVAL]))]
      else:
          fam_seqs[str(row[RFAM_ACC])] = {
          str(row[SEQ_ACC]): [(int(row[START]), int(row[END]), float(row[EVAL]))]}
    cursor.close()
    RfamDB.disconnect(cnx)
    return fam_seqs
def load_clan_seqs_from_db ( clan_acc ) : fam_seqs = { } cnx = RfamDB . connect ( ) cursor = cnx . cursor ( raw = True ) query = ( "SELECT full_region.rfam_acc, full_region.rfamseq_acc, \
      full_region.seq_start, full_region.seq_end, full_region.evalue_score\n" "FROM full_region\n" "JOIN (SELECT rfam_acc FROM clan_membership WHERE clan_acc=\'%s\') as CLAN_FAMS\n" "ON CLAN_FAMS.rfam_acc=full_region.rfam_acc" ) % ( clan_acc ) cursor . execute ( query ) for row in cursor : if str ( row [ RFAM_ACC ] ) in fam_seqs . keys ( ) : if str ( row [ SEQ_ACC ] ) in fam_seqs [ str ( row [ RFAM_ACC ] ) ] . keys ( ) : fam_seqs [ str ( row [ RFAM_ACC ] ) ] [ str ( row [ SEQ_ACC ] ) ] . append ( ( int ( row [ START ] ) , int ( row [ END ] ) , float ( row [ EVAL ] ) ) ) else : fam_seqs [ str ( row [ RFAM_ACC ] ) ] [ str ( row [ SEQ_ACC ] ) ] = [ ( int ( row [ START ] ) , int ( row [ END ] ) , float ( row [ EVAL ] ) ) ] else : fam_seqs [ str ( row [ RFAM_ACC ] ) ] = { str ( row [ SEQ_ACC ] ) : [ ( int ( row [ START ] ) , int ( row [ END ] ) , float ( row [ EVAL ] ) ) ] } cursor . close ( ) RfamDB . disconnect ( cnx ) return fam_seqs
Loads specific clan family sequences from full_region table and returns
a dictionary structure as {Rfam_acc:{Rfseq_acc:[start, end, evalue]}}
for clan competition.
Loads specific clan family sequences from full_region table and returns a dictionary structure as { Rfam_acc : { Rfseq_acc : [ start end evalue ] }} for clan competition .
# tested """
    Loads specific clan family sequences from full_region table and returns
    a dictionary structure as {Rfam_acc:{Rfseq_acc:[start, end, evalue]}}
    for clan competition.

    This has been modified to accommodate sequence duplicates

    clan_acc: Clan accession as in Rfam
    """ # connect to db # get a new buffered cursor # Fetch clan specific family full_region data # execute the query # build family dictionary of sequences # close cursor and DB connection
clan_acc