Mercurial > repos > peterjc > tmhmm_and_signalp
diff tools/protein_analysis/wolf_psort.py @ 19:f3ecd80850e2 draft
v0.2.9 Python style improvements
author | peterjc |
---|---|
date | Wed, 01 Feb 2017 09:46:42 -0500 |
parents | eb6ac44d4b8e |
children | a19b3ded8f33 |
line wrap: on
line diff
--- a/tools/protein_analysis/wolf_psort.py Tue Sep 01 09:56:36 2015 -0400 +++ b/tools/protein_analysis/wolf_psort.py Wed Feb 01 09:46:42 2017 -0500 @@ -35,7 +35,7 @@ """ import sys import os -from seq_analysis_utils import sys_exit, split_fasta, run_jobs, thread_count +from seq_analysis_utils import split_fasta, run_jobs, thread_count FASTA_CHUNK = 500 exe = "runWolfPsortSummary" @@ -56,44 +56,49 @@ return_code = subprocess.call(args) os.chdir(saved_dir) sys.exit(return_code) + +For more details on this workaround, see: +https://lists.galaxyproject.org/pipermail/galaxy-dev/2015-December/023386.html """ if len(sys.argv) != 5: - sys_exit("Require four arguments, organism, threads, input protein FASTA file & output tabular file") + sys.exit("Require four arguments, organism, threads, input protein FASTA file & output tabular file") organism = sys.argv[1] if organism not in ["animal", "plant", "fungi"]: - sys_exit("Organism argument %s is not one of animal, plant, fungi" % organism) + sys.exit("Organism argument %s is not one of animal, plant, fungi" % organism) num_threads = thread_count(sys.argv[2], default=4) fasta_file = sys.argv[3] tabular_file = sys.argv[4] + def clean_tabular(raw_handle, out_handle): """Clean up WoLF PSORT output to make it tabular.""" for line in raw_handle: if not line or line.startswith("#"): continue - name, data = line.rstrip("\r\n").split(None,1) + name, data = line.rstrip("\r\n").split(None, 1) for rank, comp_data in enumerate(data.split(",")): comp, score = comp_data.split() - out_handle.write("%s\t%s\t%s\t%i\n" \ - % (name, comp, score, rank+1)) + out_handle.write("%s\t%s\t%s\t%i\n" + % (name, comp, score, rank + 1)) fasta_files = split_fasta(fasta_file, tabular_file, n=FASTA_CHUNK) -temp_files = [f+".out" for f in fasta_files] +temp_files = [f + ".out" for f in fasta_files] assert len(fasta_files) == len(temp_files) jobs = ["%s %s < %s > %s" % (exe, organism, fasta, temp) for (fasta, temp) in zip(fasta_files, temp_files)] assert len(fasta_files) == len(temp_files) == len(jobs) + def clean_up(file_list): for f in file_list: if os.path.isfile(f): os.remove(f) if len(jobs) > 1 and num_threads > 1: - #A small "info" message for Galaxy to show the user. + # A small "info" message for Galaxy to show the user. print "Using %i threads for %i tasks" % (min(num_threads, len(jobs)), len(jobs)) results = run_jobs(jobs, num_threads) assert len(fasta_files) == len(temp_files) == len(jobs) @@ -106,7 +111,7 @@ if error_level or output.lower().startswith("error running"): clean_up(fasta_files) clean_up(temp_files) - sys_exit("One or more tasks failed, e.g. %i from %r gave:\n%s" % (error_level, cmd, output), + sys.exit("One or more tasks failed, e.g. %i from %r gave:\n%s" % (error_level, cmd, output), error_level) del results