def candidate_set_probe(routes, self, query_id, candidate_id, probe_id): '''Candidate output page. Args: self (App): ProbeDesigner.App instance. query_id (string): query folder name. candidate_id (string): candidate folder name. ''' d = self.vd d['title'] = '%s Query: %s' % (self.tprefix, query_id) d['custom_stylesheets'] = ['query.css', 'style.css'] d['custom_root_stylesheets'] = [] d['query'] = Query(query_id, self.qpath).data d['queryRoot'] = self.qpath d['query']['candidate_table'] = pd.read_csv( os.path.join(self.qpath, query_id, "set_candidates.tsv"), "\t") d['candidate'] = {'id': candidate_id} d['probe'] = {'id': probe_id} configPath = os.path.join(self.qpath, query_id, f"probe_set_{candidate_id}", f"probe_{probe_id}", f"probe_{probe_id}.config") with open(configPath, 'r') as IH: config = configparser.ConfigParser() config.read_string("".join(IH.readlines())) d['probe'].update(config['REGION'].items()) d['probe'].update(config['PROBE'].items()) d['probe'].update(config['FEATURES'].items()) return (d)
def query(routes, self, query_id): '''Query output page. Args: self (App): ProbeDesigner.App instance. query_id (string): query folder name. ''' d = self.vd d['title'] = '%s Query: %s' % (self.tprefix, query_id) d['custom_stylesheets'] = ['query.css', 'style.css'] d['custom_root_stylesheets'] = [] d['query'] = Query(query_id, self.qpath).data d['queryRoot'] = self.qpath if 'done' == d['query']['status']: if 'single' == d['query']['type']: fpath = os.path.join(self.qpath, query_id, "candidates.tsv") elif 'spotting' == d['query']['type']: fpath = os.path.join(self.qpath, query_id, "set_candidates.tsv") if not os.path.isfile(fpath): d['query']['status'] = 'error' else: d['query']['candidate_table'] = pd.read_csv(fpath, "\t") d['queryTimeout'] = 24 * 60 * 60 # 1 day timeout d['admin_email'] = self.admin_email return (d)
def candidate_probe(routes, self, query_id, candidate_id): """Candidate output page. Args: self (App): ProbeDesigner.App instance. query_id (string): query folder name. candidate_id (string): candidate folder name. """ d = self.vd d["title"] = "%s Query: %s" % (self.tprefix, query_id) d["custom_stylesheets"] = ["query.css", "style.css"] d["custom_root_stylesheets"] = [] d["query"] = Query(query_id, self.qpath).data d["queryRoot"] = self.qpath d["candidate"] = {"id": candidate_id} configPath = os.path.join( self.qpath, query_id, f"candidate_{candidate_id}", f"candidate_{candidate_id}.config", ) with open(configPath, "r") as IH: config = configparser.ConfigParser() config.read_string("".join(IH.readlines())) d["candidate"].update(config["REGION"].items()) d["candidate"].update(config["PROBE"].items()) d["candidate"].update(config["FEATURES"].items()) return d
def query(routes, self, query_id): """Query output page. Args: self (App): ProbeDesigner.App instance. query_id (string): query folder name. """ d = self.vd d["title"] = "%s Query: %s" % (self.tprefix, query_id) d["custom_stylesheets"] = ["query.css", "style.css"] d["custom_root_stylesheets"] = [] d["query"] = Query(query_id, self.qpath).data d["queryRoot"] = self.qpath if d["query"]["status"] == "done": if d["query"]["type"] == "single": fpath = os.path.join(self.qpath, query_id, "candidates.tsv") elif d["query"]["type"] == "spotting": fpath = os.path.join(self.qpath, query_id, "set_candidates.tsv") if not os.path.isfile(fpath): d["query"]["status"] = "error" else: d["query"]["candidate_table"] = pd.read_csv(fpath, "\t") d["queryTimeout"] = 24 * 60 * 60 # 1 day timeout d["admin_email"] = self.admin_email return d
def queueStatus(routes, self): taskList = [] for task in self.queue.queue: query_id = os.path.basename(task[5]) data = Query(query_id, self.qpath).data taskList.append(os.path.basename(task[1]) + f' @{data["isotime"]}') if not taskList: return '{"queue":[]}' return '{"queue": ["%s"]}' % '", "'.join(taskList)
def queueStatus(routes, self): taskList = [] for task in self.queue.queue: if 'ifpd_query_set' == task[0]: outdir_id = 4 elif 'ifpd_query_probe' == task[0]: outdir_id = 3 query_id = os.path.basename(task[outdir_id]) data = Query(query_id, self.qpath).data taskList.append(os.path.basename(task[1]) + f' @{data["isotime"]}') if 0 == len(taskList): return '{"queue":[]}' return '{"queue": ["%s"]}' % '", "'.join(taskList)
def hide_alert(routes, self): '''Hide bookmark alert for a specific query. Args: self (App): ProbeDesigner.App instance. ''' formData = bot.request.forms query = Query(formData.query_id, self.qpath).data config = configparser.ConfigParser() configPath = os.path.join(self.qpath, f'{formData.query_id}.config') with open(configPath, 'r') as IH: config.read_string("".join(IH.readlines())) config['GENERAL']['hidden_bookmark_alter'] = "True" with open(configPath, 'w+') as OH: config.write(OH) return 'Done'
def hide_alert(routes, self): """Hide bookmark alert for a specific query. Args: self (App): ProbeDesigner.App instance. """ formData = bot.request.forms Query(formData.query_id, self.qpath).data config = configparser.ConfigParser() configPath = os.path.join(self.qpath, f"{formData.query_id}.config") with open(configPath, "r") as IH: config.read_string("".join(IH.readlines())) config["GENERAL"]["hidden_bookmark_alter"] = "True" with open(configPath, "w+") as OH: config.write(OH) return "Done"
def single_queries(routes, self): '''Single probe queries reception route. Args: self (App): ProbeDesigner.App instance. ''' # Read uploaded file data = bot.request.files.data raw = [row.decode('utf-8') for row in data.file.readlines()] # Submit query for row in raw: args = row.strip().split('\t') # Build query command line cmd = ['fprode_dbquery'] cmd.extend([Query.get_next_id(self.qpath, self.queue)]) cmd.extend([shlex.quote(args[0])]) cmd.extend([shlex.quote(e) for e in args[3:6]]) cmd.extend([shlex.quote('%s/db/%s' % (self.static_path, args[2]))]) cmd.extend(['--n_oligo', shlex.quote(args[6])]) cmd.extend(['--f1_thr', shlex.quote(args[7])]) cmd.extend(['--max_probes', shlex.quote(args[8])]) cmd.extend(['--feat_order', shlex.quote(args[9])]) cmd.extend(['--outdir', '%s/query/' % self.static_path]) cmd.extend(['--description', shlex.quote(args[1])]) # Add query to the queue self.queue.put(cmd) # Redirect bot.response.status = 303 bot.response.set_header('Location', "%s%s" % (self.root_uri, self.app_uri)) # Output return ('Query received.')
def candidate_set(routes, self, query_id, candidate_id): '''Candidate output page. Args: self (App): ProbeDesigner.App instance. query_id (string): query folder name. candidate_id (string): candidate folder name. ''' d = self.vd d['title'] = '%s Query: %s' % (self.tprefix, query_id) d['custom_stylesheets'] = ['query.css', 'style.css'] d['custom_root_stylesheets'] = [] d['query'] = Query(query_id, self.qpath).data d['queryRoot'] = self.qpath d['query']['candidate_table'] = pd.read_csv( os.path.join(self.qpath, query_id, "set_candidates.tsv"), "\t") d['candidate'] = {'id': candidate_id} return (d)
def candidate_set(routes, self, query_id, candidate_id): """Candidate output page. Args: self (App): ProbeDesigner.App instance. query_id (string): query folder name. candidate_id (string): candidate folder name. """ d = self.vd d["title"] = "%s Query: %s" % (self.tprefix, query_id) d["custom_stylesheets"] = ["query.css", "style.css"] d["custom_root_stylesheets"] = [] d["query"] = Query(query_id, self.qpath).data d["queryRoot"] = self.qpath d["query"]["candidate_table"] = pd.read_csv( os.path.join(self.qpath, query_id, "set_candidates.tsv"), "\t") d["candidate"] = {"id": candidate_id} return d