diff --git a/workflows/smokers.py b/workflows/smokers.py index 3d222cd..5797347 100644 --- a/workflows/smokers.py +++ b/workflows/smokers.py @@ -229,15 +229,24 @@ class ModKernelFunction(workflow.Function): class NCBIQuery(workflow.Function): - def __init__(self): + def __init__(self, gene_id_name='gene_id'): + self._gene_id_name = gene_id_name workflow.Function.__init__(self, 'query', 'NCBI') def run(self, selection): + if not selection.has_key(self._gene_id_name): + logger.log("notice", "Expected gene ids: %s, but got: %s" %(self._gene_id_name, selection.keys())) + return None + if len(selection[self._gene_id_name])==0: + logger.log("notice", "No selected genes to query") + return None + + logger.log("notice", "No selected genes to query") base = 'http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?' options = {r'&db=' : 'gene', r'&cmd=' : 'retrieve', r'&dopt=' : 'full_report'} - gene_str = ''.join([gene + "+" for gene in selection['gene_id']]) + gene_str = ''.join([gene + "+" for gene in selection[self._gene_id_name]]) options[r'&list_uids='] = gene_str[:-1] opt_str = ''.join([key+value for key,value in options.items()]) web_str = base + opt_str @@ -245,20 +254,23 @@ class NCBIQuery(workflow.Function): class KEGGQuery(workflow.Function): - def __init__(self): + def __init__(self, org='hsa', gene_id_name='gene_id'): + self._org=org + self._gene_id_name = gene_id_name workflow.Function.__init__(self, 'query', 'KEGG') def run(self, selection): - if not selection.has_key('genes') \ - or not selection.has_key('orfs'): + if not selection.has_key(self._gene_id_name): + logger.log("notice", "Expected gene ids: %s, but got. %s" %(self._gene_id_name, selection.keys())) + return None + if len(selection[self._gene_id_name])==0: + logger.log("notice", "No selected genes to query") return None base = r'http://www.genome.jp/dbget-bin/www_bget?' - options = {'org' : 'gene'} - org = 'hsa' - gene_str = ''.join([gene + "+" for gene in selection['gene_id']]) + gene_str = ''.join([gene + "+" for gene in selection[self._gene_id_name]]) gene_str = gene_str[:-1] - gene_str = org + "+" + gene_str + gene_str = self._org + "+" + gene_str web_str = base + gene_str webbrowser.open(web_str)