diff ffp_phylogeny.py @ 1:d1c88b118a3f draft

Uploaded
author damion
date Fri, 13 Mar 2015 20:59:28 -0400
parents eb6e5e78a066
children 671667722d3d
line wrap: on
line diff
--- a/ffp_phylogeny.py	Mon Feb 23 18:25:25 2015 -0500
+++ b/ffp_phylogeny.py	Fri Mar 13 20:59:28 2015 -0400
@@ -1,5 +1,6 @@
 #!/usr/bin/python
 import optparse
+import re
 import time
 import os
 import tempfile
@@ -160,6 +161,8 @@
 	commands = command.split("|")
 	processes = []
 	ptr = 0
+	substantive = re.compile('[a-zA-Z0-9]+')
+	
 	for command_line in commands:
 		print command_line.strip()
 		args = shlex.split(command_line.strip())
@@ -167,22 +170,26 @@
 			proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 			processes.append(proc)
 		else:
+
+			#this has to come before error processing?
+			newProcess = subprocess.Popen(args, stdin=processes[ptr-1].stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+			
 			# It seems the act of reading standard error output is enough to trigger
 			# error code signal for that process, i.e. so that retcode returns a code.
+			retcode = processes[ptr-1].poll()
 			stderrdata = processes[ptr-1].stderr.read()
-			retcode = processes[ptr-1].poll()
-			if retcode or len(stderrdata) > 0:
-				stop_err(stderrdata)
+			#Issue with ffptree is it outputs ----....---- on stderr
+			if retcode or (len(stderrdata) > 0 and substantive.search(stderrdata)):
+				stop_err(stderrdata)			
 
-			newProcess = subprocess.Popen(args, stdin=processes[ptr-1].stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-			processes.append(newProcess)
+			processes.append(newProcess)			
 			processes[ptr-1].stdout.close() # Allow prev. process to receive a SIGPIPE if current process exits.
 		
 		ptr += 1
 
+	retcode = processes[ptr-1].poll()
 	(stdoutdata, stderrdata) = processes[ptr-1].communicate()
-	retcode = processes[ptr-1].poll()
-	if retcode or len(stderrdata) > 0:
+	if retcode or (len(stderrdata) > 0 and substantive.search(stderrdata)):
 		stop_err(stderrdata)
 	
 	return stdoutdata
@@ -322,6 +329,7 @@
 		#Now create a taxonomy label file, ensuring a name exists for each profile.
 		taxonomyNames = getTaxonomyNames(options.type, options.multiple, options.abbreviate, in_files, options.taxonomy)
 		taxonomyTempFile = getTaxonomyFile(taxonomyNames)
+		
 		# -p = Include phylip format 'infile' of the taxon names to use.  Very simple, just a list of fasta identifier names.
 		command += ' | ffpjsd -p ' + taxonomyTempFile
 
@@ -337,6 +345,8 @@
 			else:
 				stop_err("For a phylogenetic tree display, one must have at least 3 ffp profiles.")
 
+		#print command
+		
 		result = check_output(command)
 		with open(options.output,'w') as fw:
 			fw.writelines(result)