def templet_generation_and_prediction(finger_sequence, finger_name,len_minimum, len_maximum, operation_tm, C_Na,C_Mg,C_Strand): if template_trigger_gengerate(finger_sequence,finger_name,len_maximum,len_minimum)==1: #gengerate trigger, template successfully and stored in ~tri.txt, ~tem.txt dic_therm=unafold_pred('~tem.txt',"~tri.txt",operation_tm, C_Na,C_Mg,C_Strand) dic_jf={} dic_tri={} dic_temp={} dic_trigen={} for cur_record_o in SeqIO.parse(open('~tem.txt'), "fasta") : dic_temp[str(cur_record_o.id)]=str(cur_record_o.seq) for cur_record_o in SeqIO.parse(open('~tri.txt'), "fasta") : dic_tri[str(cur_record_o.id)]=str(cur_record_o.seq) for cur_record_o in SeqIO.parse(open('~tri_gen.txt'), "fasta") : dic_trigen[str(cur_record_o.id)]=str(cur_record_o.seq) for cur_record_o in SeqIO.parse(open('~tem.txt'), "fasta") : cur_seq=str(cur_record_o.seq).upper() #all capitalized dic_jf[cur_record_o.id]=SeqDep.method_2_prediction(cur_seq) for key,value in sorted(dic_therm. iteritems(), key=lambda(k,v):(v,k)): valuelist=key.split('_') part='_'.join(valuelist[0:5]) part2=part+'_' triname=part2+'tri_' triname=triname+valuelist[6] trigenname=part2+'tri_gen' if (float(dic_therm[key][0])>configure_finger.min_tri_temp_tm and float(dic_therm[key][0])<configure_finger.max_tri_temp_tm and float(dic_therm[key][1])<configure_finger.max_temp_tm and int(dic_therm[key][2])<configure_finger.max_temp_bonds): #if(float(dic_therm[key][0])>configure_finger.min_tri_temp_tm and float(dic_therm[key][0])<configure_finger.max_tri_temp_tm and float(dic_therm[key][1])<configure_finger.max_temp_tm): todo.Tritemp(finger_id=valuelist[1],type=valuelist[2], start= valuelist[3], trigger =dic_tri[triname] , trig_gen=dic_trigen[trigenname],temp=dic_temp[key],tri_length=len(dic_tri[triname]) ,temp_bayes_class=dic_jf[key][1][0],temp_pwm_class=dic_jf[key][0][0] ,temp_p90_score=dic_jf[key][0][1],temp_diff_score= dic_jf[key][0][2],tri_temp_tm=dic_therm[key][0] ,temp_tm=dic_therm[key][1] ,bonds=dic_therm[key][2] ) elixir.session.commit
def savefilebrower_all(self): print "entered savefilebrower_all" fName = QtGui.QFileDialog.getSaveFileName(self, "Save as xls file", "Save as new file", self.tr("Text Files (*.xls)")) #print "step5", globals() if fName.isEmpty() == False: Expar.write_xls(str(fName),self, todo.Task.query.all(), todo.Tritemp.query.all()) #t=file1+'simple.xls' #rb = xlrd.open_workbook(t) #wb = copy(rb) #print(rb.sheet_by_index(0).cell(0,0).value) #wb.save(fName) print(fName) print('is generated!') QtGui.QMessageBox.about(self, "Saved", "%s is generated!" % (fName)) #SeqDep.delete_file('~') # delete all the files under this folder and begins with '~' SeqDep.delete_file2() self.close() exit()
def submit2(self): self.ui.progressBar.hide() iterator = QtGui.QTreeWidgetItemIterator(self.dialog.ui.list) task_list={} while True: value = iterator.value() if value is None: break if value.checkState(0): task_list[str(value.text(0))]=1 else: print "" iterator.__iadd__(1) if task_list==[]: return #print task_list self.dialog2 = QtGui.QDialog() self.dialog2.ui = Ui_Dialog2() self.dialog2.ui.setupUi(self.dialog2) QtCore.QObject.connect(self.dialog2.ui.pushButton, QtCore.SIGNAL("clicked()"), self.savefilebrower_all) for finger in todo.Task.query.all(): if task_list.has_key(str(finger.finger_id)): if str(finger.finger_type)=='HTH': QtGui.QMessageBox.warning(Form,"Warning", "HTH fingerprinting sites may take a long time to process!") break for finger in todo.Task.query.all(): self.tick.emit(1) SeqDep.delete_file('~tem') SeqDep.delete_file('~tri') if task_list.has_key(str(finger.finger_id)): name='seq_'+str(finger.finger_id)+'_'+str(finger.finger_type)+'_'+str(finger.start)+'_'+str(finger.length) finger.done=True elixir.session.commit Expar_database.templet_generation_and_prediction(finger.sequence, name, int(self.ui.lineEdit_9.text()),int(self.ui.lineEdit_10.text()), float(self.ui.lineEdit_11.text()), float(self.ui.lineEdit_12.text()),float(self.ui.lineEdit_13.text()),float(self.ui.lineEdit_7.text())) #Expar_database.templet_generation_and_prediction(finger.sequence, name,8, 30, 37, 0,1,0.00000005) for tritemp in todo.Tritemp.query.all(): item=QtGui.QTreeWidgetItem([str(tritemp.finger_id),str(tritemp.type),str(tritemp.start),str(tritemp.trig_gen),str(tritemp.trigger),str(tritemp.temp), str(tritemp.temp_bayes_class),str(tritemp.temp_pwm_class), str(tritemp.temp_p90_score),str(tritemp.temp_diff_score),str(tritemp.tri_temp_tm),str(tritemp.temp_tm),str(tritemp.bonds)]) self.dialog2.ui.list.sortByColumn(0, QtCore.Qt.AscendingOrder) self.dialog2.ui.list.addTopLevelItem(item) self.dialog2.ui.list.setSortingEnabled(True) self.dialog2.ui.list.setColumnWidth(4,250) #print SeqDep.method_2_prediction(finger.sequence) print "************************************\nDone!\n**************************************\n" self.dialog2.exec_()
def savefilebrower_all(self): print "entered savefilebrower_all" fName = QtGui.QFileDialog.getSaveFileName( self, "Save as xls file", "Save as new file", self.tr("Text Files (*.xls)")) #print "step5", globals() if fName.isEmpty() == False: Expar.write_xls(str(fName), self, todo.Task.query.all(), todo.Tritemp.query.all()) #t=file1+'simple.xls' #rb = xlrd.open_workbook(t) #wb = copy(rb) #print(rb.sheet_by_index(0).cell(0,0).value) #wb.save(fName) print(fName) print('is generated!') QtGui.QMessageBox.about(self, "Saved", "%s is generated!" % (fName)) #SeqDep.delete_file('~') # delete all the files under this folder and begins with '~' SeqDep.delete_file2() self.close() exit()
def submit2(self): self.ui.progressBar.hide() iterator = QtGui.QTreeWidgetItemIterator(self.dialog.ui.list) task_list = {} while True: value = iterator.value() if value is None: break if value.checkState(0): task_list[str(value.text(0))] = 1 else: print "" iterator.__iadd__(1) if task_list == []: return #print task_list self.dialog2 = QtGui.QDialog() self.dialog2.ui = Ui_Dialog2() self.dialog2.ui.setupUi(self.dialog2) QtCore.QObject.connect(self.dialog2.ui.pushButton, QtCore.SIGNAL("clicked()"), self.savefilebrower_all) for finger in todo.Task.query.all(): if task_list.has_key(str(finger.finger_id)): if str(finger.finger_type) == 'HTH': QtGui.QMessageBox.warning( Form, "Warning", "HTH fingerprinting sites may take a long time to process!" ) break for finger in todo.Task.query.all(): self.tick.emit(1) SeqDep.delete_file('~tem') SeqDep.delete_file('~tri') if task_list.has_key(str(finger.finger_id)): name = 'seq_' + str(finger.finger_id) + '_' + str( finger.finger_type) + '_' + str(finger.start) + '_' + str( finger.length) finger.done = True elixir.session.commit Expar_database.templet_generation_and_prediction( finger.sequence, name, int(self.ui.lineEdit_9.text()), int(self.ui.lineEdit_10.text()), float(self.ui.lineEdit_11.text()), float(self.ui.lineEdit_12.text()), float(self.ui.lineEdit_13.text()), float(self.ui.lineEdit_7.text())) #Expar_database.templet_generation_and_prediction(finger.sequence, name,8, 30, 37, 0,1,0.00000005) for tritemp in todo.Tritemp.query.all(): item = QtGui.QTreeWidgetItem([ str(tritemp.finger_id), str(tritemp.type), str(tritemp.start), str(tritemp.trig_gen), str(tritemp.trigger), str(tritemp.temp), str(tritemp.temp_bayes_class), str(tritemp.temp_pwm_class), str(tritemp.temp_p90_score), str(tritemp.temp_diff_score), str(tritemp.tri_temp_tm), str(tritemp.temp_tm), str(tritemp.bonds) ]) self.dialog2.ui.list.sortByColumn(0, QtCore.Qt.AscendingOrder) self.dialog2.ui.list.addTopLevelItem(item) self.dialog2.ui.list.setSortingEnabled(True) self.dialog2.ui.list.setColumnWidth(4, 250) #print SeqDep.method_2_prediction(finger.sequence) print "************************************\nDone!\n**************************************\n" self.dialog2.exec_()
def templet_generation_and_prediction(finger_sequence, finger_name,len_minimum, len_maximum, operation_tm, C_Na,C_Mg,C_Strand): rank=finger_name.split("_")[1] type=finger_name.split("_")[2] location=finger_name.split("_")[3] length=len(finger_sequence) trigger=[] template=[] maximum=int(len_maximum) minimum=int(len_minimum) nc=['A','T','G','C'] xxxx=[''] if (type=='HTH'): tri_gen=finger_sequence[length-9-8:length-9] tri_gen_len=len(tri_gen) for i in range(minimum,maximum+1): if (length-9-i>=9): up_trigger=finger_sequence[length-9-i:length-9] bottom_trigger=revcomp(finger_sequence[9:i+9]) for j in range(4): for h in range(4): for k in range(4): for m in range(4): xxxx=nc[j]+nc[h]+nc[k]+nc[m] up_emplate=up_trigger+'GAGTC'+xxxx+up_trigger bottom_template=bottom_trigger+'GAGTC'+xxxx+bottom_trigger #print "<tr><td>",up_trigger,"</td><td>",revcomp(up_template),"<td><tr>" up_set=cal_tm_bond(up_trigger,revcomp(up_template),1000,0,50) up_pred=SeqDep.method_2_prediction(str(up_template).upper()) bottom_set=cal_tm_bond(up_trigger,revcomp(up_template),C_Na*1000,C_Mg*1000,C_Strand*1000000000) bottom_pred=SeqDep.method_2_prediction(str(up_template).upper()) print up_trigger, revcomp(up_template), up_set[0], configure_finger.min_tri_temp_tm, float(up_set[0]), configure_finger.max_tri_temp_tm, float(up_set[1]), configure_finger.max_temp_tm , int(up_set[2]), configure_finger.max_temp_bonds if (float(up_set[0])>configure_finger.min_tri_temp_tm and float(up_set[0])<configure_finger.max_tri_temp_tm and float(up_set[1])<configure_finger.max_temp_tm and int(up_set[2])<configure_finger.max_temp_bonds): todo.Tritemp(finger_id=rank,type=type, start= location, trigger =up_trigger , trig_gen=tri_gen,temp=up_template,tri_length=tri_gen_len ,temp_bayes_class=up_pred[1],temp_pwm_class=up_pred[0][0] ,temp_p90_score=up_pred[0][1],temp_diff_score= up_pred[0][2],tri_temp_tm=up_set[0] ,temp_tm=up_set[1] ,bonds=up_set[2] ) elixir.session.commit if (float(bottom_set[0])>configure_finger.min_tri_temp_tm and float(bottom_set[0])<configure_finger.max_tri_temp_tm and float(bottom_set[1])<configure_finger.max_temp_tm and int(bottom_set[2])<configure_finger.max_temp_bonds): todo.Tritemp(finger_id=rank,type=type, start= location, trigger =bottom_trigger , trig_gen=tri_gen,temp=bottom_template, tri_length=tri_gen_len ,temp_bayes_class=bottom_pred[1],temp_pwm_class=bottom_pred[0][0] ,temp_p90_score=bottom_pred[0][1],temp_diff_score= bottom_pred[0][2],tri_temp_tm=bottom_set[0] ,temp_tm=bottom_set[1] ,bonds=bottom_set[2] ) elixir.session.commit if (type=='HTT'): tri_gen=finger_sequence[length-9-8:length-4] len_tri_gen=len(tri_gen) #print "HTT enter" for i in range(minimum,maximum+1): if (length-9-i>=9): up_trigger=finger_sequence[length-9-i:length-9] xxxx=finger_sequence[length-4:length] up_template=up_trigger+'GAGTC'+xxxx+up_trigger up_set=cal_tm_bond(up_trigger,revcomp(up_template),C_Na*1000,C_Mg*1000,C_Strand*1000000000) up_pred=SeqDep.method_2_prediction(str(up_template).upper()) if (float(up_set[0])>configure_finger.min_tri_temp_tm and float(up_set[0])<configure_finger.max_tri_temp_tm and float(up_set[1])<configure_finger.max_temp_tm and int(up_set[2])<configure_finger.max_temp_bonds): todo.Tritemp(finger_id=rank,type=type, start= location, trigger =up_trigger , trig_gen=tri_gen,temp=bottom_template,tri_length=tri_gen_len ,temp_bayes_class=up_pred[0],temp_pwm_class=up_pred[1] ,temp_p90_score=up_pred[0][1],temp_diff_score= up_pred[0][2],tri_temp_tm=up_set[0] ,temp_tm=up_set[1] ,bonds=up_set[2] ) elixir.session.commit if (type=='TTH'): for i in range(minimum,maximum+1): if (length-9-i>=9): bottom_trigger=revcomp(finger_sequence[9:i+9]) xxxx=revcomp(finger_sequence[0:4]) bottom_template=bottom_trigger+'GAGTC'+xxxx+bottom_trigger bottom_set=cal_tm_bond(bottom_trigger,revcomp(bottom_template),C_Na*1000,C_Mg*1000,C_Strand*1000000000) bottom_pred=SeqDep.method_2_prediction(str(bottom_template).upper()) if (float(bottom_set[0])>configure_finger.min_tri_temp_tm and float(bottom_set[0])<configure_finger.max_tri_temp_tm and float(bottom_set[1])<configure_finger.max_temp_tm and int(bottom_set[2])<configure_finger.max_temp_bonds): todo.Tritemp(finger_id=rank,type=type, start= location, trigger =bottom_trigger , trig_gen=tri_gen,temp=bottom_template, tri_length=tri_gen_len ,temp_bayes_class=bottom_pred[1],temp_pwm_class=bottom_pred[0][0] ,temp_p90_score=bottom_pred[0][1],temp_diff_score= bottom_pred[0][2],tri_temp_tm=bottom_set[0] ,temp_tm=bottom_set[1] ,bonds=bottom_set[2] ) elixir.session.commit