Ejemplo n.º 1
0
 def __init__(self, post_data):
   self.f_al, self.enz_id_to_enz_descr = fac.FusedAlignment(), dict()
   self.filt_enz_id_set , self.filter_set = set(), None
   self.org_id_set, self.enz_id_list = set(), []
   self.db_name = sh.get_db_name(post_data)  
   self.al_id = sf.try_val_to_int(post_data.getvalue('al_id', ''))
   #get ref id to enumerate alignment position as in reference enzyme:
   self.ref_id = sf.try_val_to_int(post_data.getvalue('ref_id', ''))
   #get view mode to show alignments as blocks and spacers or as sequences
   self.show_blocks = eval(post_data.getvalue('show_mode','False'))
   #get markup checkboxes:
   self.set_bm = post_data.getvalue('set_bm', False)
   self.save_bm = post_data.getvalue('save_bm', False)
   #set self.su, self.pos and self.aac_name to split by aac:
   if self.al_id and self.db_name:
     db_link, db_cursor = df.get_link_and_cursor(self.db_name)
     if db_cursor:
       self.set_fused_al_enz_names_and_filters(db_cursor, post_data)
   #obtain filtered enzymes identifiers (if any) for further split and analyse:
       self.set_filtered_enz_ids(db_cursor)
   #change blocks markups on ones from post if "set_bm" is checked:
       if self.set_bm:
         self.set_block_markup(post_data)
   #save blocks markups to db if "save_bm" is checked then uncheck "save_bm":
       if self.save_bm:
         self.set_block_markup(post_data)
         self.save_block_markup(db_cursor)
Ejemplo n.º 2
0
 def __init__(self, enz_id, enz_name, org_id, org_name):
     enz_id, org_id = sf.try_val_to_int(enz_id), sf.try_val_to_int(org_id)
     self.enz_id = enz_id if enz_id else 0
     self.org_id = org_id if org_id else 0
     self.enz_name, self.org_name = enz_name, org_name
     self.name_str = enz_name + ' of ' + org_name
     self.id_name_str = str(enz_id) + ': ' + self.name_str
Ejemplo n.º 3
0
 def set_scores_params(self, post_data):
   self.prob_cutoff, self.shen_cutoff, self.rand_samp_num = 0, 0, 0
   self.use_prob = post_data.getvalue('use_prob', False)
   if self.use_prob:
     num_str = post_data.getvalue('prob_cutoff', 0)
     self.prob_cutoff = sf.try_val_to_int(num_str)
   self.use_shen = post_data.getvalue('use_shen', False)
   if self.use_shen:
     num_str = post_data.getvalue('shen_cutoff', 0)
     self.shen_cutoff = sf.try_val_to_int(num_str)
     num_str = post_data.getvalue('rand_samp_num', 40)
     self.rand_samp_num = sf.try_val_to_int(num_str)
Ejemplo n.º 4
0
def mk_al_anchor(db_name, al_id, ctime_str):  
  al_id = sf.try_val_to_int(al_id)
  if al_id:
    al_name = str(al_id) + ' (' + ctime(sf.try_val_to_float(ctime_str)) + ')'
    return '<a href = "fusedAlViewer.py?al_id=' + str(al_id) + '&db_name=' + \
           db_name + '">' + al_name + '</a>'
  return ''
Ejemplo n.º 5
0
 def set_su_data(self, sd_rows):
   for row in sd_rows:
     su_name = row.get('su_name', 'no subunit name')
     self.su_names.append(su_name)
     self.sn_to_al[su_name] = sf.try_val_to_int(row.get('al_length', 0))
     #convert markup string to block position list and assign it to subunit:
     self.add_sn_to_bm(su_name, row.get('block_markup', '')) 
     self.sn_to_ref_row[su_name] = []
Ejemplo n.º 6
0
 def set_filtered_ids(self, db_cursor):
   query = 'SELECT e.enz_id FROM `enzymes` e INNER JOIN organisms o ' + \
           'ON e.org_id = o.org_id'
   eid_wc = sf.get_where_id_case(self.all_ids, 'enzymes', True)
   f_wc = self.filter_set.get_db_query_filter()
   if eid_wc and f_wc: 
     wc = ' WHERE ' + eid_wc + ' AND ' + f_wc
     enz_id_rows = df.send_query(db_cursor, query + wc)
     for row in enz_id_rows:
       enz_id = sf.try_val_to_int(row['enz_id'])
       if enz_id:
         self.filtered_ids.append(enz_id)
Ejemplo n.º 7
0
 def __init__(self, post_data):
   self.db_name = sh.get_db_name(post_data)
   self.ref_id = sf.try_val_to_int(post_data.getvalue('ref_id', ''))
   self.al_id = sf.try_val_to_int(post_data.getvalue('al_id', ''))
   self.set_scores_params(post_data)
   self.all_filter_str = post_data.getvalue('al_filter_ta', '')
   self.split_crit_str = 'Split criteria isn\'t defined'
   self.filter_set, self.split = None, None
   self.su_pos_aac = []
   self.all_ids, self.split_ids, self.filtered_ids = [], [], []
   self.id_to_descr = dict() #descr is to be converted to str for output
   #fill in split, all_ids, id_to_descr, filter_set and filter_ids:
   self.set_from_db()
   if self.split:
     #get split_ids from one of available sources: filtered enzyme ids, 
     #current split ids or specified aac and set up split_crit_str:
     self.set_split_ids_and_crit(post_data)
     #use split_ids to make split in each split_col in self.split:
     self.split.set_split_cols(self.split_ids, self.use_prob, 
                               self.use_shen, self.rand_samp_num)
     self.split_ids = sorted(self.split_ids)
Ejemplo n.º 8
0
def get_max_col_id(db_cursor, table_name):
    prefix = sf.get_col_name_prefix(table_name) + '_'
    query = 'SELECT col_name FROM `attributes` WHERE col_name LIKE "' + \
            prefix + '%"'
    result = df.send_query(db_cursor, query)
    if type(result).__name__ == 'str':
        return ['cannot get the latest column id:' + result]
    id_str = []
    for row in result:  #get full col name, cut off prefix then get id
        col_id = sf.try_val_to_int(row.get('col_name', '')[len(prefix):])
        if col_id:
            id_str.append(col_id)
    return max(id_str) if id_str else 0
Ejemplo n.º 9
0
 def set_aac_cols(self, ad_rows, ref_id):
   row_num, cur_su_name, aac_cols, aac_cols_size_range = 0, '', [], ''
   for db_row in ad_rows:
     su_name = db_row.get('su_name', '')
     if su_name not in self.su_names:
       continue
     if su_name != cur_su_name: 
       #write down previous subunit aac_cols, initialize new ones:
       if aac_cols:
         self.sn_to_aac_cols[cur_su_name] = deepcopy(aac_cols)
         if not self.sn_to_ref_row[cur_su_name]: 
           #ref row hasn't been set, set it as row of gap aac:
           self.set_ref_row(cur_su_name, '-' * self.sn_to_al[cur_su_name], bm)
       #change current su_name, null the row_num to fill in cols from 1st row:
       row_num, cur_su_name = 0, su_name
       aac_cols, bm = [], self.sn_to_bm[su_name] # set new aac_cols and markup
       # aac_cols is shorter than alignment sequences if blocks are marked up,
       # using len(bm) to initialize corresponding number of cols:
       aac_cols_size_range = range(0, len(bm))
       for j in aac_cols_size_range: # make aac_col for each block
         aac_cols.append([])
     al_seq = db_row.get('al_seq') 
     id = sf.try_val_to_int(db_row.get('enz_id', 0))
     self.id_to_row_num[id] = row_num # set row_num for enzyme id
     if id == ref_id: # set reference sequence to enumerate positions:
       self.set_ref_row(su_name, al_seq, bm)
     # read each aac in al_seq to corresp. col: take alignment block pos (j)
     # from k-th bm then add j-th symbol from i-th al_seq to j-th aac_col:
     for k in aac_cols_size_range: 
       # print('k=', k, ', j = ', bm[k], ', al_seq[j] = ', al_seq[bm[k]-1], '<br>')
       aac_cols[k].append(al_seq[bm[k]-1]) #-1 for zero-start enumeration
     row_num += 1
   if aac_cols: #write down the last subunit aac_cols and ref_row
     self.sn_to_aac_cols[cur_su_name] = deepcopy(aac_cols)
     if not self.sn_to_ref_row[cur_su_name]: 
       #ref row hasn't been set, set it as row of gap aac:
       self.set_ref_row(cur_su_name, '-' * self.sn_to_al[cur_su_name], bm)