def _translate_gene_list(gene_list): """gene_list can already be a sequence of strings or it could be a path to a file that contains a list of strings. The path can be relative to the data directory or an absolute path. The file can be any format supported by read_strings_from_file() """ # if it's not something that could be a filename assume it's a sequence of strings if not isinstance(gene_list, basestring): return None, gene_list # try to find a matching filename and read the data from it pathway_name = splitext(basename(gene_list))[ 0] # use the file's basename (without extension) as the pathway name for path in [ gene_list, join(project_dirs.data_dir(), gene_list), join(project_dirs.pathways_dir(), gene_list) ]: if isfile(path): if cfg.verbosity > 0: print 'Reading gene list from {}'.format(path) gene_list = read_strings_from_file(path) return pathway_name, gene_list # not found return None, None
def list_to_pathway_names(listname): if listname == 'all': pathway_names = [f[:-4] for f in listdir(pathways_dir()) if f.endswith('.txt')] else: listfile = join(pathway_lists_dir(),listname) with open(listfile) as f: lines = f.readlines() pathway_names = [x.strip() for x in lines] # remove newlines pathway_names = [x for x in pathway_names if x] # rmeove empty strings return pathway_names
def _translate_gene_list(gene_list): """gene_list can already be a sequence of strings or it could be a path to a file that contains a list of strings. The path can be relative to the data directory or an absolute path. The file can be any format supported by read_strings_from_file() """ # if it's not something that could be a filename assume it's a sequence of strings if not isinstance(gene_list, basestring): return None, gene_list # try to find a matching filename and read the data from it pathway_name = splitext(basename(gene_list))[0] # use the file's basename (without extension) as the pathway name for path in [gene_list, join(project_dirs.data_dir(),gene_list), join(project_dirs.pathways_dir(),gene_list)]: if isfile(path): if cfg.verbosity > 0: print 'Reading gene list from {}'.format(path) gene_list = read_strings_from_file(path) return pathway_name, gene_list # not found return None,None
def read_pathway(pathway): filename = join(pathways_dir(), pathway + '.txt') with open(filename) as f: lines = f.readlines() genes = [x.strip() for x in lines] # remove newlines return [x for x in genes if x] # rmeove empty strings