Mercurial > repos > damion > ffp_phylogeny
comparison ffp_phylogeny.py @ 2:671667722d3d draft
fix: ffptree taxonomy name file convert () to _
author | damion |
---|---|
date | Fri, 20 Mar 2015 14:27:19 -0400 |
parents | d1c88b118a3f |
children | 79a4a86981d3 |
comparison
equal
deleted
inserted
replaced
1:d1c88b118a3f | 2:671667722d3d |
---|---|
6 import tempfile | 6 import tempfile |
7 import sys | 7 import sys |
8 import shlex, subprocess | 8 import shlex, subprocess |
9 from string import maketrans | 9 from string import maketrans |
10 | 10 |
11 VERSION_NUMBER = "0.1.00" | 11 VERSION_NUMBER = "0.1.03" |
12 | 12 |
13 class MyParser(optparse.OptionParser): | 13 class MyParser(optparse.OptionParser): |
14 """ | 14 """ |
15 From http://stackoverflow.com/questions/1857346/python-optparse-how-to-include-additional-info-in-usage-output | 15 From http://stackoverflow.com/questions/1857346/python-optparse-how-to-include-additional-info-in-usage-output |
16 Provides a better class for displaying formatted help info in epilog() portion of optParse; allows for carriage returns. | 16 Provides a better class for displaying formatted help info in epilog() portion of optParse; allows for carriage returns. |
38 @filepaths array resulting galaxy dataset file .dat paths | 38 @filepaths array resulting galaxy dataset file .dat paths |
39 | 39 |
40 """ | 40 """ |
41 # Take off prefix/suffix whitespace/comma : | 41 # Take off prefix/suffix whitespace/comma : |
42 taxonomy = filenames.strip().strip(',').split(',') | 42 taxonomy = filenames.strip().strip(',').split(',') |
43 translations = maketrans(' .- ','____') | |
44 names=[] | 43 names=[] |
45 ptr = 0 | 44 ptr = 0 |
46 | 45 |
47 for file in filepaths: | 46 for file in filepaths: |
48 # First, convert space, period to underscore in file names. ffprwn IS VERY SENSITIVE ABOUT THIS. | 47 # Trim labels to 50 characters max. ffpjsd kneecaps a taxonomy label to 10 characters if it is greater than 50 chars. |
49 # Also trim labels to 50 characters. Turns out ffpjsd is kneecapping a taxonomy label to 10 characters if it is greater than 50 chars. | 48 taxonomyitem = taxonomy[ptr].strip()[:50] #.translate(translations) |
50 taxonomyitem = taxonomy[ptr].strip().translate(translations)[:50] | 49 # Convert non-alphanumeric characters to underscore in taxonomy names. ffprwn IS VERY SENSITIVE ABOUT THIS. |
51 # print taxonomyitem | 50 taxonomyitem = re.sub('[^0-9a-zA-Z]+', '_', taxonomyitem) |
52 if not type in 'text' and multiple: | 51 |
52 if (not type in 'text') and multiple: | |
53 #Must read each fasta file, looking for all lines beginning ">" | 53 #Must read each fasta file, looking for all lines beginning ">" |
54 with open(file) as fastafile: | 54 with open(file) as fastafile: |
55 lineptr = 0 | 55 lineptr = 0 |
56 for line in fastafile: | 56 for line in fastafile: |
57 if line[0] == '>': | 57 if line[0] == '>': |
59 # Odd case where no fasta description found | 59 # Odd case where no fasta description found |
60 if name == '': name = taxonomyitem + '.' + str(lineptr) | 60 if name == '': name = taxonomyitem + '.' + str(lineptr) |
61 names.append(name) | 61 names.append(name) |
62 lineptr += 1 | 62 lineptr += 1 |
63 else: | 63 else: |
64 | |
64 names.append(taxonomyitem) | 65 names.append(taxonomyitem) |
65 | 66 |
66 ptr += 1 | 67 ptr += 1 |
67 | 68 |
68 if abbreviate: | 69 if abbreviate: |
176 | 177 |
177 # It seems the act of reading standard error output is enough to trigger | 178 # It seems the act of reading standard error output is enough to trigger |
178 # error code signal for that process, i.e. so that retcode returns a code. | 179 # error code signal for that process, i.e. so that retcode returns a code. |
179 retcode = processes[ptr-1].poll() | 180 retcode = processes[ptr-1].poll() |
180 stderrdata = processes[ptr-1].stderr.read() | 181 stderrdata = processes[ptr-1].stderr.read() |
181 #Issue with ffptree is it outputs ----....---- on stderr | 182 #Issue with ffptree is it outputs ---- ... ---- on stderr even when ok. |
182 if retcode or (len(stderrdata) > 0 and substantive.search(stderrdata)): | 183 if retcode or (len(stderrdata) > 0 and substantive.search(stderrdata)): |
183 stop_err(stderrdata) | 184 stop_err(stderrdata) |
184 | 185 |
185 processes.append(newProcess) | 186 processes.append(newProcess) |
186 processes[ptr-1].stdout.close() # Allow prev. process to receive a SIGPIPE if current process exits. | 187 processes[ptr-1].stdout.close() # Allow prev. process to receive a SIGPIPE if current process exits. |