def setMutation(self,box=None): """ déclenché par le clic sur le bouton 'set mutation model' ou par le clic sur 'clear' dans 'set mutation model'. bascule vers la saisie du modèle mutationnel """ if box == None: box = self.sender().parent() title = str(box.title()) if "Microsatellites" in title: #self.parent.addTab(self.setMutation_dico[box],"Set mutation model") #self.parent.setTabEnabled(self.parent.indexOf(self),False) #self.parent.setCurrentWidget(self.setMutation_dico[box]) self.switchTo(self.setMutation_dico[box]) # maj du titre de la frame lab = self.setMutation_dico[box].ui.setMutMsLabel lab.setText("Set mutation model of %s (microsatellites)"%(" ".join(str(box.title()).split()[:2]))) # on considère que le setmutation n'est plus valide, il faut le revalider self.setMutationValid_dico[box] = False elif "Sequences" in title: #self.parent.addTab(self.setMutationSeq_dico[box],"Set mutation model") #self.parent.setTabEnabled(self.parent.indexOf(self),False) #self.parent.setCurrentWidget(self.setMutationSeq_dico[box]) self.switchTo(self.setMutationSeq_dico[box]) # maj du titre de la frame lab = self.setMutationSeq_dico[box].ui.setMutSeqLabel lab.setText("Set mutation model of %s (sequences)"%(" ".join(str(box.title()).split()[:2]))) # on considère que le setmutation n'est plus valide, il faut le revalider self.setMutationSeqValid_dico[box] = False else: output.notify(self,"Set Mutation Model error","Add locus to a group before setting the mutation model")
def wrapper(*args, **kwargs): elb = boto.connect_elb() elbs = elb.get_all_load_balancers() execute('locks.wait_for_all_locks') inst_id = instance_id() tags = ['task:' + func.__name__] + instance_tags(inst_id) active_lbs = sorted(lb for lb in elbs if inst_id in [info.id for info in lb.instances]) timer = partial(dog_stats_api.timer, tags=tags) # Remove this node from the LB for lb in active_lbs: notify("Removing {id} from {lb}".format(id=inst_id, lb=lb)) with timer('rolling.deregister_instance'): noopable(lb.deregister_instances)([inst_id]) noopable(await_elb_instance_state)(lb, inst_id, "OutOfService") # Execute the operation func(*args, **kwargs) # Add this node back to the LBs for lb in active_lbs: notify("Adding {id} to {lb}".format(id=inst_id, lb=lb)) with timer('rolling.register_instance'): noopable(lb.register_instances)([inst_id]) with timer('rolling.wait_for_start'): # Wait for the node to come online in the LBs for lb in active_lbs: noopable(await_elb_instance_state)(lb, inst_id, "InService")
def noop(*args, **kwargs): notify("Would have called: {fun}({args}, {kwargs})".format( fun=fun.__name__, args=", ".join(repr(a) for a in args), kwargs=", ".join("=".join([key, repr(val)]) for key, val in kwargs.items()), ))
def launchReftableGeneration(self): # SNP Tests remove bin and bin.txt if no reftable was generated + check if MAF was modified dataFile = str(self.ui.dataFileEdit.text()) if int(self.ui.nbSetsDoneEdit.text() )< 1 or not os.path.exists((u"%s/reftable.bin"%self.dir).encode(self.fsCoding)): log(3,"No reftable.bin found, try to remove %s and %s"%(dataFile+".bin", dataFile+"bin.txt")) if os.path.exists((dataFile+".bin").encode(self.fsCoding)) : os.remove((dataFile+".bin").encode(self.fsCoding)) log(3, "%s removed" % (dataFile+".bin")) if os.path.exists((dataFile+"bin.txt").encode(self.fsCoding)) : os.remove((dataFile+"bin.txt").encode(self.fsCoding)) log(3, "%s removed" % (dataFile+"bin.txt")) else : f=open(dataFile.encode(self.fsCoding),'r') words = f.readline().strip().split() f.close() commentWordsDict = DataAbstract.getParseCommentWordsDict(words) f=open((os.path.join(str(self.dir),"maf.txt")).encode(self.fsCoding),'r') maf = f.readline().strip().lower() f.close() if "hudson" in maf : maf = "hudson" else : maf = str(float(maf)) commentWordsDict["maf"] = str(float(commentWordsDict["maf"])) if str(commentWordsDict["maf"]) != maf : output.notify(self,"MAF value error","The actual reftable was generated with <MAF=%s> but your data file %s says <MAF=%s> !\nRemove your reftable.bin file or fix your maf data file" % (maf, dataFile ,commentWordsDict["maf"])) return if not os.path.exists((dataFile+".bin").encode(self.fsCoding)) : if self.checkSNPbin == None : self.checkSNPbin = checkFileExistThread(file=dataFile+".bin", ui=self) self.checkSNPbin.start() #checkSNPbin.updateInterfaceForSnpBin() super(ProjectSnp, self).launchReftableGeneration()
def save(self): """ sauvegarde du projet -> mainconf, histconf, genconf, theadconf Si le gen et hist sont valides, on génère le header """ log(2,"Saving project '%s'"%self.dir) self.parent.showStatus("Saving project %s"%self.name) if self.dir != None and self.dataFileName != "": # save meta project if os.path.exists((u"%s/%s"%(self.dir,self.parent.main_conf_name)).encode(self.fsCoding)): os.remove((u"%s/%s"%(self.dir,self.parent.main_conf_name)).encode(self.fsCoding)) f = codecs.open((u"%s/%s"%(self.dir,self.parent.main_conf_name)).encode(self.fsCoding),'w',"utf-8") f.write("%s\n"%self.dataFileName) # recup du nombre de params (depuis historical model et les mutational qui varient) nb_param = self.hist_model_win.getNbParam() f.write("%s parameters and %s summary statistics\n\n"%(nb_param,self.getNbSumStats())) f.close() # save hist conf self.hist_model_win.writeHistoricalConfFromGui() # save gen conf self.writeGeneticConfFromGui() # save th conf et production du reftable header if self.gen_state_valid and self.hist_state_valid: self.writeThConf() self.writeAscertConf() self.writeRefTableHeader() self.saveAnalysis() self.parent.clearStatus() self.parent.showStatus("Project %s successfully saved"%self.name,2000) else: output.notify(self,"Saving is impossible","Project %s is not yet completly created"%self.name) self.parent.clearStatus()
def loadFromDir(self): """ charge les infos à partir du répertoire self.dir """ log(2,"Launching load procedures") # GUI self.ui.dirEdit.setText(self.dir) self.ui.browseDataFileButton.setDisabled(True) self.ui.browseDataFileButton.hide() self.ui.groupBox_6.show() self.ui.groupBox_7.show() self.ui.groupBox_8.show() self.ui.setHistoricalButton.setDisabled(False) self.ui.setGeneticButton.setDisabled(False) try: self.loadMyConf() # lecture de conf.hist.tmp self.hist_model_win.loadHistoricalConf() self.ascert_frame.loadAscertConf() self.loadSumStatsConf() self.sum_stat_wins.lockLociSelection() self.loadAnalysis() except Exception as e: log(1, traceback.format_exc()) raise Exception("Impossible to read the project configuration\n\n%s"%e) output.notify(self,"Load error","Impossible to read the project configuration\n\n%s"%e)
def changeBackgroundColor(self, colorstr): if str(colorstr) in self.tabColor.keys(): self.parent.setStyleSheet("background-color: %s;" % self.tabColor[str(colorstr)]) elif colorstr == "default": output.notify(self, "advice", "Restart DIYABC in order to load the default color scheme") else: self.parent.setStyleSheet("background-color: %s;" % colorstr)
def validate(self,silent=False): if self.ui.ascYesRadio.isChecked(): problem = "" try: freq = float(self.ui.asc1ValEdit.text()) if freq < 0 or freq > 0.5 : raise Exception("Frequency must be positive and lower than 0.5") poly = float(self.ui.asc2ValEdit.text()) if poly < 0 or poly > 1 : raise Exception("Proportion of polymorphic SNPs must be in [0,1]") elim = float(self.ui.asc3ValEdit.text()) if elim < 0 or elim > 1 : raise Exception("Threshold to eliminate parameter values must be in [0,1]") except Exception as e: problem += "%s\n"%(e) if problem != "": if not silent: output.notify(self,"Value error",problem) self.parent.setAscertValid(False) else: self.parent.setAscertValid(True) #sortie self.exit() else: self.parent.setAscertValid(True) self.exit()
def setSum(self, box=None): """ déclenché par le clic sur le bouton 'set summary statistics' ou par le clic sur 'clear' dans 'set summary statistics'. bascule vers la saisie des summary statistics """ if box == None: box = self.sender().parent() title = str(box.title()) if "Microsatellites" in title: # self.parent.addTab(self.setSum_dico[box],"Set summary statistics") # self.parent.setTabEnabled(self.parent.indexOf(self),False) # self.parent.setCurrentWidget(self.setSum_dico[box]) self.switchTo(self.setSum_dico[box]) # maj du titre de la frame lab = self.setSum_dico[box].ui.sumStatLabel lab.setText("Set summary statistics of %s (microsatellites)" % (" ".join(str(box.title()).split()[:2]))) elif "Sequences" in title: # self.parent.addTab(self.setSumSeq_dico[box],"Set summary statistics") # self.parent.setTabEnabled(self.parent.indexOf(self),False) # self.parent.setCurrentWidget(self.setSumSeq_dico[box]) self.switchTo(self.setSumSeq_dico[box]) # maj du titre de la frame lab = self.setSumSeq_dico[box].ui.sumStatLabel lab.setText("Set summary statistics of %s (sequences)" % (" ".join(str(box.title()).split()[:2]))) else: output.notify( self, "Set Summary statistics error", "Add locus to a group before setting the summary statistics" )
def wait_for_lock(): if hasattr(env, 'deploy_user'): lock_user = env.deploy_user else: lock_user = env.user LOCK_ID = 'u:{user} h:{host} pid:{pid}'.format(user=lock_user, host=socket.gethostname(), pid=str(os.getpid())) sleep_time = 0.1 timeout = 120 start_time = time.time() with settings(warn_only=True): while True: wait_time = time.time() - start_time # break if the lockfile is removed or if it belongs to this pid # if it exists lock_status will have the file's contents with hide('running', 'stdout', 'stderr', 'warnings'): lock_status = run("test ! -f {lfile} || " "(cat {lfile} && " 'grep -q "{lid}" {lfile})'.format( lfile=LOCK_FILE, lid=LOCK_ID)) if lock_status.succeeded: noopable(sudo)('echo "{0}" > {1}'.format( LOCK_ID, LOCK_FILE)) notify("Took lock") break elif wait_time >= timeout: abort("Timeout expired, giving up") lock_create_time = run("stat -c %Y {0}".format(LOCK_FILE)) delta = time.time() - float(lock_create_time) (dhour, dsec) = divmod(delta, 3600) notify(""" !! Deploy lockfile already exists ({lockfile}) !! Waiting: {wait}s Lockfile info: [ {owner} ] Lock created: {dhour}h{dmin}m ago """.format( lockfile=LOCK_FILE, wait=int(timeout - wait_time), owner=lock_status, dhour=int(dhour), dmin=int(dsec / 60), )) time.sleep(sleep_time) sleep_time *= 2 if sleep_time > MAX_SLEEP_TIME: sleep_time = MAX_SLEEP_TIME
def display_installed_packages(installed_packages): """ Print all installed packages collected by collect_installed_packages """ # FIXME: env.hosts loses the port information here, not sure why with no_ts(): for pkg in installed_packages["{0}:22".format(env.host)]: notify("{pkg.name} = {pkg.revision}".format(pkg=pkg))
def display_installed_packages(installed_packages): """ Print all installed packages collected by collect_installed_packages """ # FIXME: env.hosts loses the port information here, not sure why with no_ts(): for pkg in installed_packages['{0}:22'.format(env.host)]: notify("{pkg.name} = {pkg.revision}".format(pkg=pkg))
def loadDataFile(self,name): """ Charge le fichier de données passé en paramètre. Cette fonction est appelée lors de l'ouverture d'un projet existant et lors du choix du fichier de données pour un nouveau projet """ log(2,"Loading datafile '%s'"%name) ## conversion de dos à unix #if not isUnixText(name): # dos2unix(name) buttonPreviousText = self.runReftableButton.text() self.runReftableButton.setText("Checking data file format : please wait") try: self.data = DataSnp(name) typestr = "" for ty in self.typesOrdered : if ty in self.data.ntypeloc.keys(): typestr += " %s : %s,"%(ty,self.data.ntypeloc[ty]) typestr = typestr[:-1] if str(self.data.commentValuesDict['maf']).lower() == "hudson" : if self.data.nloctot != self.data.nloc : output.notify(self,"Monomorphic Loci warning","Your dataset includes a fraction of monomorphic loci :\n\nONLY POLYMORPHIC LOCI WILL BE CONSIDERED AFTERWARDS.") self.ui.dataFileInfoLabel.setText("MAF = hudson : %s polymorphic loci + %s monomorphic loci\n%s individuals in %s samples\n%s" % \ (self.data.nloc,(self.data.nloctot-self.data.nloc),self.data.nindtot,self.data.nsample,typestr)) else : self.ui.dataFileInfoLabel.setText("MAF = %s : %s loci fitting the MAF (over %s)\n%s individuals in %s samples\n%s" % \ (self.data.commentValuesDict['maf'], self.data.nloc,self.data.nloctot,self.data.nindtot,self.data.nsample,typestr)) self.ui.dataFileEdit.setText(name) self.dataFileSource = name except Exception as e: log(1, traceback.format_exc()) keep = "" if self.ui.dataFileEdit.text() != "": keep = "\n\nThe file was not loaded, nothing was changed" output.notify(self,"Data file error","%s%s"%(e,keep)) self.runReftableButton.setText(buttonPreviousText) return False # on declare les sumstats apres avoir chargé le datafile car c'est nécessaire # feinte pour que le parent.parent renvoie au projet self.dummy = QFrame() self.dummy.parent = self self.clearSummaryStats() # selection du type de snp pour sumstats kkpz a retirer #self.typeCombo = QComboBox(self) #for ty in self.typesOrdered: # if ty in self.data.ntypeloc.keys(): # self.typeCombo.addItem(ty) #self.ui.horizontalLayout_6.addWidget(QLabel("for locus type :")) #self.ui.horizontalLayout_6.addWidget(self.typeCombo) self.runReftableButton.setText(buttonPreviousText) return True
def generate_next_state(self): postRep = self.reader.read_post_as(PollPost.PostInFeed, url=self.url) poll = PollPost(postRep).poll finished = self.check_finished(poll.votes) if finished and self.notify_on_complete: notify("All votes are in.") debug(*[ format_poll_option(option, voters) for option, voters in poll.votes.items() ]) return poll, finished
def from_strings(**pkg_revs): """ Cache packages based on strings, that can be either checked with confirm or deployed with deploy. Each named argument specifies a package by name, and the revision of the package to deploy """ packages = [] for pkg_name, pkg_rev in pkg_revs.items(): packages.append(PackageDescriptor(pkg_name, pkg_rev)) env.package_descriptors = packages notify(env.package_descriptors)
def getExecutablePath(self): exPath = "" if self.ui.useDefaultExecutableCheck.isChecked(): # LINUX if "linux" in sys.platform: if "86" in platform.machine() and "64" not in platform.machine(): exPath = "%s/bin/diyabc-comput-linux-i386" % DATAPATH else: exPath = "%s/bin/diyabc-comput-linux-x64" % DATAPATH # si on a le paquet deb installé et qu'aucun binaire n'est dans le datapath if ( os.path.exists(u"/usr/bin/diyabc".encode(self.fsCoding)) and not os.path.exists((u"%s/bin/diyabc-comput-linux-x64" % DATAPATH).encode(self.fsCoding)) and not os.path.exists((u"%s/bin/diyabc-comput-linux-i386" % DATAPATH).encode(self.fsCoding)) ): exPath = "/usr/bin/diyabc" # WINDOWS elif "win" in sys.platform and "darwin" not in sys.platform: if os.environ.has_key("PROCESSOR_ARCHITECTURE") and "86" not in os.environ["PROCESSOR_ARCHITECTURE"]: exPath = "%s\\bin\diyabc-comput-win-x64" % DATAPATH.replace("/", "\\") else: exPath = "%s\\bin\diyabc-comput-win-i386" % DATAPATH.replace("/", "\\") # MACOS elif "darwin" in sys.platform: if "86" in platform.machine() and "64" not in platform.machine(): exPath = os.path.join(DATAPATH, "bin/diyabc-comput-mac-i386") else: exPath = os.path.join(DATAPATH, "bin/diyabc-comput-mac-x64") else: if not os.path.exists(str(self.ui.execPathPathEdit.text()).encode(self.fsCoding)): output.notify( self, "executable not found", "The executable set in DIYABC settings cannot be found\n%s\n\If, and only if, 'use default executable' is checked, then this is a bug. We apologize !\n Please send us a b!ug report.\n\n Next, check if no analysis or reftable are running and restart diyabc.\nIt should work again." % self.ui.execPathPathEdit.text(), ) return "" return str(self.ui.execPathPathEdit.text()) if not os.path.exists(exPath.encode(self.fsCoding)): output.notify( self, "executable not found", "The executable set in DIYABC settings cannot be found\n%s\n\If, and only if, 'use default executable' is checked, then this is a bug. We apologize !\n Pleasesend us a bug report.\n\n Next, check if no analysis or reftable are running and restart diyabc.\nIt should work again." % exPath, ) return "" return os.path.abspath(str(exPath).encode(self.fsCoding))
def checkClusterValues(self, Qstr): numSimulatedDatasetByJob = str(self.ui.numSimulatedDataSetByJobEdit.text()).strip() if numSimulatedDatasetByJob != "": try: numSimulatedDatasetByJob = int(numSimulatedDatasetByJob) except ValueError: output.notify( self, "Value Error : numSimulatedDatasetByJob", "Number of simulated data set by job must be a positive integer", ) coresPerJob = str(self.ui.coresPerJobEdit.text()).strip() if coresPerJob != "": try: coresPerJob = int(coresPerJob) except ValueError: output.notify(self, "Value Error : coresPerJob", "Number of cores per job must be a positive integer") maxConcurrentJobs = str(self.ui.maxConcurrentJobsEdit.text()).strip() if maxConcurrentJobs != "": try: maxConcurrentJobs = int(maxConcurrentJobs) except ValueError: output.notify( self, "Value Error : maxConcurrentJobs", "Maximum number of concurrent job running on a cluster must be a positive integer", ) seed = str(self.ui.seedEdit.text()).strip() if seed not in ["", "None"]: try: seed = int(seed) except ValueError: output.notify(self, "Value Error : seed", "seed must be a positive integer or 'None' or blank") if (self.ui.clusterBinLocationCombo.currentText() == "local") and ( not os.path.exists(self.ui.diyabcPathLocalPathEdit.text()) ): output.notify( self, "Value Error : cluster bin path", "cluster binary not found. \n%s does not exists" % self.ui.diyabcPathLocalPathEdit.text(), )
def checkAll(self): problems = "" try: if self.analysis.category == "bias": notds = int(self.ui.notdsEdit.text()) elif self.analysis.category == "modelChecking": nodssftp = int(self.ui.nodssftpEdit.text()) nosd = int(self.ui.nosdEdit.text()) cnosd = int(self.ui.cnosdEdit.text()) except Exception as e: problems += "Only non-empty integer values are accepted\n" if problems == "": return True else: output.notify(self,"value problem",problems) return False
def valid(self): """ clic sur le bouton de validation qui entraine l'affichage de la condition dans setHistoricalModel """ problems = "" if len(self.parent.project_list) == 0: problems += "- You must have a currently opened project\n" if self.ui.lastThingNoRadio.isChecked(): problems += "- You must produce the bug just before opening this bug report window\n" if u"%s"%self.ui.descEdit.toPlainText() == "": problems += "- Please write at least a small description\n" if not self.ui.originInterfRadio.isChecked() and not self.ui.originCompRadio.isChecked(): problems += "- You must select a possible origin\n" if problems == "": self.generateBugReport() else: output.notify(self,"Invalid bug report",problems) return
def multi_choose_with_input(msg, options): """ Options: msg - header message for the chooser options - dictionary of options to select User selects one of the keys in the dictionary, a new value is read from stdin """ selections = options.keys() user_input = None while True: fastprint('\n{0}{1}'.format(white(msg, bold=True), white("\n"))) # The extra white("\n") prints are to reset # the color for the timestamp line prefix fastprint(white("\n")) for i, item in enumerate(selections): fastprint(" {0}. {1} : {2}".format(white(i, bold=True), cyan(item), cyan(options[item], bold=True)) + white("\n")) fastprint(blue(" a. Select all") + white("\n")) fastprint(blue(" c. Continue") + white("\n")) fastprint(blue(" x. Cancel") + white("\n")) fastprint(white("\n")) user_input = raw_input("> ") try: if user_input == 'c': break elif user_input == 'x': return None elif int(user_input) in range(len(selections)): name = selections[int(user_input)] fastprint(green('Enter new msg for ') + cyan(name)) options[name] = raw_input(white(": ")) except: notify("Invalid selection ->" + user_input + "<-") return options
def checkAll(self): problems = "" try: if "confidence" in self.analysis.category : notds = int(self.ui.notdsEdit.text()) if self.analysis.category == "confidence_posterior_global": linearRegrassion = int(self.ui.posteriorDistributionSampleSizeEdit.text()) lr = int(self.ui.lrEdit.text()) de = int(self.ui.deEdit.text()) cnosd = int(self.ui.cnosdEdit.text()) except Exception as e: problems += "Only non-empty integer values are accepted\n" if problems == "": return True else: output.notify(self,"value problem",problems) return False
def await_elb_instance_state(lb, instance_id, awaited_state): sleep_time = 0.1 start_time = time.time() while True: state = lb.get_instance_health([instance_id])[0].state if state == awaited_state: notify("Load Balancer {lb} is in awaited state {awaited_state}, proceeding.".format( lb=lb.dns_name, awaited_state=awaited_state )) break else: notify("Checking again in {0} seconds. Elapsed time: {1}".format(sleep_time, time.time() - start_time)) time.sleep(sleep_time) sleep_time *= 2 if sleep_time > MAX_SLEEP_TIME: sleep_time = MAX_SLEEP_TIME
def multi_choose_with_input(msg, options): """ Options: msg - header message for the chooser options - dictionary of options to select User selects one of the keys in the dictionary, a new value is read from stdin """ selections = options.keys() user_input = None while True: fastprint('\n{0}{1}'.format(white(msg, bold=True), white("\n"))) # The extra white("\n") prints are to reset # the color for the timestamp line prefix fastprint(white("\n")) for i, item in enumerate(selections): fastprint(" {0}. {1} : {2}".format(white(i, bold=True), cyan( item), cyan(options[item], bold=True)) + white("\n")) fastprint(blue(" a. Select all") + white("\n")) fastprint(blue(" c. Continue") + white("\n")) fastprint(blue(" x. Cancel") + white("\n")) fastprint(white("\n")) user_input = raw_input("> ") try: if user_input == 'c': break elif user_input == 'x': return None elif int(user_input) in range(len(selections)): name = selections[int(user_input)] fastprint(green('Enter new msg for ') + cyan(name)) options[name] = raw_input(white(": ")) except: notify("Invalid selection ->" + user_input + "<-") return options
def await_elb_instance_state(lb, instance_id, awaited_state): sleep_time = 0.1 start_time = time.time() while True: state = lb.get_instance_health([instance_id])[0].state if state == awaited_state: notify( "Load Balancer {lb} is in awaited state {awaited_state}, proceeding." .format(lb=lb.dns_name, awaited_state=awaited_state)) break else: notify("Checking again in {0} seconds. Elapsed time: {1}".format( sleep_time, time.time() - start_time)) time.sleep(sleep_time) sleep_time *= 2 if sleep_time > MAX_SLEEP_TIME: sleep_time = MAX_SLEEP_TIME
def validate(self,silent=False): try: # pour voir si ça déclenche une exception (nbstats,b) = self.getStats() for ty in self.parent.parent.typesOrdered : exec("av = int(str(self.ui.available%sLabel.text()))"%ty) exec("ta = int(str(self.ui.taken%sEdit.text()))"%ty) #if fro+ta > av+1 or ta <= 0 or fro <= 0: kkpz-rm if ta > av or ta < 0 : raise Exception("Number of taken loci must be positive and at most equal to available loci number") exec("hchoosen = int(str(self.ui.takenHEdit.text()))") fro = int(str(self.ui.fromEdit.text())) if fro <= 0 : raise Exception('"from locus" numver must be positive') #if self.parent.parent.getNbSumStats() == 0: if nbstats == 0: raise Exception("You must select at least one summary statistic") self.exit() except Exception as e: if not silent: output.notify(self,"Input error",str(e))
def writeRefTableHeader(self): """ écriture du header.txt à partir des conf """ super(ProjectSnp,self).writeRefTableHeader() if os.path.exists((u"%s/%s"%(self.dir,self.parent.ascertainment_conf_name)).encode(self.fsCoding)): f = codecs.open((u"%s/%s"%(self.dir,self.parent.ascertainment_conf_name)).encode(self.fsCoding),"rU","utf-8") ascert_string = f.read() f.close() else: output.notify(self,"Header generation problem","Impossible to add ascertainment part to header : ascertainment file doesn't exist") return if os.path.exists((u"%s/%s"%(self.dir,self.parent.reftableheader_name)).encode(self.fsCoding)): log(2,"Adding ascertainment part to header") fdest = codecs.open((u"%s/%s"%(self.dir,self.parent.reftableheader_name)).encode(self.fsCoding),"a","utf-8") fdest.write("\n\n%s"%ascert_string) fdest.close() else: output.notify(self,"Header generation problem","Impossible to add ascertainment part to header : header doesn't exist")
def multi_choose(msg, options): fastprint(white(msg, bold=True) + white("\n")) selected = [" " for option in options] user_input = None while True: # The extra white("\n") prints are to reset # the color for the timestamp line prefix fastprint(white("\n")) for i, target in enumerate(options): fastprint(green(selected[i])) fastprint(cyan(" {0}. {1}".format(i, target)) + white("\n")) fastprint(blue(" a. Select all") + white("\n")) fastprint(blue(" c. Deploy selections") + white("\n")) fastprint(blue(" x. Cancel") + white("\n")) fastprint(white("\n")) user_input = raw_input("> ") try: if user_input == 'c': break elif user_input == 'a': selected = ['*' for i in range(len(selected))] elif user_input == 'x': return None elif int(user_input) in range(len(options)): if selected[int(user_input)] == " ": selected[int(user_input)] = "*" else: selected[int(user_input)] = " " except: notify("Invalid selection ->" + user_input + "<-") pkgs = [options[s] for s in range(len(selected)) if selected[s] == '*'] return pkgs
def checkSampleSize(self): # on verifie qu'on a le bon nombre de sample #nsamp = 0 scTxt = str(self.scList[0].findChild(QPlainTextEdit,"scplainTextEdit").toPlainText()) scChecker = Scenario(number=1,prior_proba="1") try: scChecker.checkread(scTxt.strip().split('\n'),None) scChecker.checklogic() dico_sc_infos = {} dico_sc_infos["text"] = scTxt.strip().split('\n') dico_sc_infos["checker"] = scChecker except Exception as e: pass if scChecker.nsamp != len(self.sampleSizeList): output.notify(self,"Sample size error","Sample number differs between the scenario and the size definition") return False try: for ssBox in self.sampleSizeList: msize = int(ssBox.findChild(QLineEdit,"msizeEdit").text()) fsize = int(ssBox.findChild(QLineEdit,"fsizeEdit").text()) if fsize+msize < 1: output.notify(self,"Sample size values error","Total sample size must be positive") return False except Exception as e: output.notify(self,"Sample size values error","%s"%e) return False return True
def addTheParams(self): """ trouve et ajoute les paramètres du scenario concerné """ try: sc = str(self.getScText()) scChecker = Scenario(number=self.sc_to_show) scChecker.checkread(sc.strip().split('\n'),self.parents.data) scChecker.checklogic() dico_sc_infos = {} dico_sc_infos["text"] = sc.strip().split('\n') dico_sc_infos["checker"] = scChecker #print "nb param du sc ",num," ",scChecker.nparamtot except Exception as e: output.notify(self,"Unexpected Error",str(e)) self.exit() return # calcul des infos pour savoir si on peut setCondition sur ce param dico_cat = {} lprem = [] for param in scChecker.parameters: if dico_cat.has_key(param.category): dico_cat[param.category] += 1 else: lprem.append(param.name) dico_cat[param.category] = 1 dico_param = self.parents.hist_model_win.param_info_dico for param in scChecker.parameters: pname = param.name pcat = param.category visible = False if pname not in lprem and dico_cat[pcat] > 1: visible = True elem = dico_param[pname] self.addParamGui(pname,elem[1],elem[2],elem[3],elem[4],elem[5],visible) self.param_info_dico[pname] = [pcat]
def defineSampleSize(self,silent=False): # nettoyage rmList = [] for ssizeBox in self.sampleSizeList: ssizeBox.hide() rmList.append(ssizeBox) for ss in rmList: self.sampleSizeList.remove(ss) # remplissage scTxt = str(self.scList[0].findChild(QPlainTextEdit,"scplainTextEdit").toPlainText()) scChecker = Scenario(number=1,prior_proba="1") try: log(3,"sc text %s"%scTxt) scChecker.checkread(scTxt.strip().split('\n'),None) scChecker.checklogic() dico_sc_infos = {} dico_sc_infos["text"] = scTxt.strip().split('\n') dico_sc_infos["checker"] = scChecker except IOScreenError, e: if not silent: output.notify(self,"Scenario error","%s"%e)
def wrapper(*args, **kwargs): elb = boto.connect_elb() elbs = elb.get_all_load_balancers() execute('locks.wait_for_all_locks') inst_id = instance_id() tags = ['task:' + func.__name__] + instance_tags(inst_id) active_lbs = sorted( lb for lb in elbs if inst_id in [info.id for info in lb.instances] ) timer = partial(dog_stats_api.timer, tags=tags) # Remove this node from the LB for lb in active_lbs: notify("Removing {id} from {lb}".format(id=inst_id, lb=lb)) with timer('rolling.deregister_instance'): noopable(lb.deregister_instances)([inst_id]) noopable(await_elb_instance_state)(lb, inst_id, "OutOfService") # Execute the operation func(*args, **kwargs) # Add this node back to the LBs for lb in active_lbs: notify("Adding {id} to {lb}".format(id=inst_id, lb=lb)) with timer('rolling.register_instance'): noopable(lb.register_instances)([inst_id]) with timer('rolling.wait_for_start'): # Wait for the node to come online in the LBs for lb in active_lbs: noopable(await_elb_instance_state)(lb, inst_id, "InService")
def loadDataFile(self, name): """ Charge le fichier de données passé en paramètre. Cette fonction est appelée lors de l'ouverture d'un projet existant et lors du choix du fichier de données pour un nouveau projet """ log(2, "Loading datafile '%s'" % name) ## conversion de dos à unix # if not isUnixText(name): # dos2unix(name) new_data = Data(name) try: new_data.loadfromfile() # on ne garde le data que si le load n'a pas déclenché d'exception self.data = new_data microsat = "" sequences = "" et = "" if self.data.nloc_mic > 0: microsat = "%s microsat" % self.data.nloc_mic if self.data.nloc_seq > 0: sequences = "%s sequences" % self.data.nloc_seq if self.data.nloc_mic > 0 and self.data.nloc_seq > 0: et = " and " self.ui.dataFileInfoLabel.setText( "%s loci (%s%s%s)\n%s individuals in %s samples" % (self.data.nloc, microsat, et, sequences, self.data.nindtot, self.data.nsample) ) self.ui.dataFileEdit.setText(name) self.dataFileSource = name except Exception as e: log(1, traceback.format_exc()) keep = "" if self.ui.dataFileEdit.text() != "": keep = "\n\nThe file was not loaded, nothing was changed" output.notify(self, "Data file error", "%s%s" % (e, keep)) return False return True
def checkName(self): """ vérifie si le nom est valide et libre """ name = str(self.ui.analysisNameEdit.text()) if name.strip() == "": output.notify(self,"name error","Analysis name cannot be empty") return False for c in self.parent.parent.illegalAnalysisNameCharacters: if c in name: output.notify(self,"name error","Analysis name contains illegal characters") return False for an in self.parent.analysisList: n = an.name if name.strip() == n.strip(): output.notify(self,"name error","Name already used") return False return True
with open(SESSION_PATH, 'r') as f: session = json.load(f) event_id = session['event_id'] unread = session['unread'] else: event_id = api.event_id()['EventID'] resp = api.events(event_id) messages = resp.get('Messages', []) if messages: inbox = next(c for c in resp['MessageCounts'] if c['LabelID'] == '0') unread = inbox['Unread'] unread_messages = list(filter(lambda m: m['Action'] == 1 and m['Message']['Unread'], messages)) output.notify(unread_messages) event_id = api.event_id()['EventID'] elif unread == None: resp = api.messages_count() inbox = next(c for c in resp['Counts'] if c['LabelID'] == '0') unread = inbox['Unread'] output.puts(unread) if not session or session['unread'] != unread or messages: with open(SESSION_PATH, 'w') as f: json.dump({'event_id': event_id, 'unread': unread}, f, separators=(',', ':')) if not session: SESSION_PATH.chmod(0o600)
def addToGroup(self,box=None): """ ajoute les loci selectionnés au groupe du bouton pressé """ all_similar = True first_type_found = "" if box == None: box = self.sender().parent() listwidget = box.findChild(QListWidget,"locusGroupList") row_list = [] selection = self.ui.tableWidget.selectedIndexes() selection.sort() for it in selection: if it.row() not in row_list: row_list.append(it.row()) # verif que tous les loci selectionnés ont le meme type if first_type_found == "": first_type_found = str(self.ui.tableWidget.item(it.row(),1).text()) else: if first_type_found != str(self.ui.tableWidget.item(it.row(),1).text()): all_similar = False # verif que les loci deja dans le groupe sont du même type que ceux sélectionnés # on compare le premier type trouvé dans la selection avec le type du premier # élément du groupe if listwidget.count() > 0: if all_similar: name = str(listwidget.item(0).text()) #num = int(name.split(' ')[1]) num = self.dico_num_and_numgroup_locus[name][0] # info sur le premier locus du groupe type = str(self.ui.tableWidget.item(num-1,1).text()) #print "\ntype deja present : %s"%type if type != first_type_found: all_similar = False else: if all_similar: # le groupe est vide, on set le nom avec le type old_title = str(box.title()) tt = '' if first_type_found == 'M': tt = "Microsatellites" elif first_type_found == 'S': tt = "Sequences" if tt != '': box.setTitle("%s %s : %s"%(old_title.split()[0],old_title.split()[1],tt)) # on met à jour le dico des groupes self.group_info_dico[box][0] = tt if all_similar: # déselection des présents for ind_to_unselect in range(listwidget.count()): listwidget.item(ind_to_unselect).setSelected(False) # ajout des nouveaux for row in row_list: name = self.ui.tableWidget.item(row,0).text() # ajout trié dans le groupe i = 0 #num_to_insert = int(name.split(' ')[1]) num_to_insert = row+1 while i < listwidget.count() and self.dico_num_and_numgroup_locus[str(listwidget.item(i).text())][0] < num_to_insert : i+=1 #box.findChild(QListWidget,"locusGroupList").addItem(name) box.findChild(QListWidget,"locusGroupList").insertItem(i,name) box.findChild(QListWidget,"locusGroupList").item(i).setSelected(True) # on cache la ligne self.ui.tableWidget.setRowHidden(row,True) # on met à jour le dico des groupes self.group_info_dico[box][1].append(num_to_insert) # on met à jour le numero du groupe pour ce locus self.dico_num_and_numgroup_locus[str(name)][1] = (self.groupList.index(box)+1) else: output.notify(self,"Group error","In a group, all the loci must have the same type")
def validate(self,silent=False): """ clic sur le bouton validate verifie la validité de tous les groupes (mutmodel valide && nbsumstats > 0 && nblocus > 0) si valide : sort , maj de l'icone de validité et sauve si non valide : informe et sauve """ #print self.group_info_dico #print self.dico_num_and_numgroup_locus problem = u"" if len(self.groupList) > 0: # verification des valeurs de motif et range problematicLocus = "" try: for i in range(self.ui.tableWidget.rowCount()): # c'est un microsat if str(self.ui.tableWidget.item(i,1).text())[0] == "M": motif_size = int(str(self.ui.tableWidget.item(i,2).text())) motif_range = int(str(self.ui.tableWidget.item(i,3).text()).strip()) ##print "locus %s size:%s range:%s"%(i,motif_size,motif_range) #mini = self.parent.data.locuslist[i].mini #maxi = self.parent.data.locuslist[i].maxi #kmoy = (mini + maxi)//2 #kmin = kmoy - (((motif_range/2)-1) * motif_size) #kmax = kmin + ((motif_range-1) * motif_size) #if (kmin > mini) or (kmax < maxi): # problematicLocus += "%s,"%(i+1) # log(4,"locus %s size:%s range:%s mini=%s maxi=%s kmoy=%s kmin=%s kmax=%s"%(self.parent.data.locuslist[i].name,motif_size,motif_range,mini,maxi,kmoy,kmin,kmax)) else: length = int(str(self.ui.tableWidget.item(i,4).text()).strip()) pcA = int(str(self.ui.tableWidget.item(i,5).text())) pcC = int(str(self.ui.tableWidget.item(i,6).text())) pcG = int(str(self.ui.tableWidget.item(i,7).text())) pcT = int(str(self.ui.tableWidget.item(i,8).text())) if length <= 0: problem += "Length has to be positive (locus %s)\n"%(i+1) for val in [pcA,pcC,pcG,pcT]: if val < 0 or val > 100: problem += "Locus %s has incoherent values of nucleotide frequencies"%(i+1) except Exception as e: problem += "%s\n"%e #print "\n"; if problematicLocus != "": problematicLocus = problematicLocus[:-1] problem += "Motif range at locus %s is not large enough to include all observed alleles\n"%problematicLocus for i,box in enumerate(self.groupList): title = str(box.title()) if "Microsatellites" in title: if box not in self.setMutationValid_dico.keys(): self.setMutationValid_dico[box] = self.setMutation_dico[box].allValid(silent=True) if not self.setMutationValid_dico[box]: problem += u"Mutation model of group %s is not considered as valid\n"%(i+1) else: log(3,"Mut model of group %s is valid"%box.title()) elif "Sequences" in title: if box not in self.setMutationSeqValid_dico.keys(): self.setMutationSeqValid_dico[box] = self.setMutationSeq_dico[box].allValid(silent=True) if not self.setMutationSeqValid_dico[box]: problem += u"Mutation model of group %s is not considered as valid\n"%(i+1) else: log(3,"Mut model of group %s is valid"%box.title()) else: problem += u"Group %s is empty\n"%(i+1) else: problem += "You must have at least one group of locus\n" if problem != u"": if not silent: output.notify(self,"Impossible to validate the genetic data",problem) self.parent.setGenValid(False) else: self.exit() self.parent.setGenValid(True)