changeset 3:d085f995d556

remove prepare_commet and change/add packages
author cmonjeau
date Thu, 10 Sep 2015 13:38:21 +0000
parents 1478d48df8c7
children 29d66e64918f
files commet.py commet.xml repository_dependencies.xml tool_dependencies.xml
diffstat 4 files changed, 53 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/commet.py	Thu Sep 10 09:59:53 2015 +0000
+++ b/commet.py	Thu Sep 10 13:38:21 2015 +0000
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 import sys, tempfile, subprocess, glob
-import os, re, shutil, optparse
+import os, re, shutil, argparse
 import zipfile, tarfile, gzip
 from os.path import basename
 
@@ -13,7 +13,7 @@
 
 http://github.com/pierrepeterlongo/commet
 
-or with the galaxy_commet package in the GenOuest toolshed (coming soon)
+or with the package_commet package in the GenOuest toolshed and the main toolshed
 
 NOTE : 
 
@@ -25,69 +25,51 @@
 def __main__():
 
 	# arguments recuperation
-        parser = optparse.OptionParser()
-        parser.add_option("--input", dest="input")
-        parser.add_option("-k", dest="kmer")
-        parser.add_option("-t", dest="minsharedkmer")
-        parser.add_option("-l", dest="minlengthread")
-        parser.add_option("-n", dest="maxn")
-        parser.add_option("-e", dest="minshannonindex")
-        parser.add_option("-m", dest="maxreads")
+        parser = argparse.ArgumentParser()
+
+        parser.add_argument("--set", dest="set", action='append')
+        parser.add_argument("-k", dest="kmer")
+        parser.add_argument("-t", dest="minsharedkmer")
+        parser.add_argument("-l", dest="minlengthread")
+        parser.add_argument("-n", dest="maxn")
+        parser.add_argument("-e", dest="minshannonindex")
+        parser.add_argument("-m", dest="maxreads")
 
-        parser.add_option("--output")
-        parser.add_option("--output_vectors")
-        parser.add_option("--output_dendro")
-        parser.add_option("--output_logs")
-        parser.add_option("--output_matrix")
-        parser.add_option("--output_heatmap1")
-        parser.add_option("--output_heatmap2")
-        parser.add_option("--output_heatmap3")
+        parser.add_argument("--output")
+        parser.add_argument("--output_vectors")
+        parser.add_argument("--output_dendro")
+        parser.add_argument("--output_matrix")
+        parser.add_argument("--output_heatmap1")
+        parser.add_argument("--output_heatmap2")
+        parser.add_argument("--output_heatmap3")
 
-        (options, args) = parser.parse_args()
-
+        options = parser.parse_args()
 
 	# copy R script into the current dir
 	shutil.copy(os.environ['RSCRIPTS']+"/heatmap.r", os.getcwd())
         shutil.copy(os.environ['RSCRIPTS']+"/dendro.R", os.getcwd())
 
-	# remove the first line of the input file
-	commet_file = open(options.input, "r")
-	commet_file_clean = open("commet_clean_file", "w")
-
-	# delete the first line
-	commet_file.readline()
-	for line in commet_file:
-		commet_file_clean.write(line)
-
-	# close files
-	commet_file.close()
-	commet_file_clean.close()
+        # prepare input file
+        commet_file=open('commet_config_file', 'w')
+ 
+        for set in options.set:
+            clean_set=set.replace(',', ';').replace('::', ':')
+            commet_file.write(clean_set+"\n")                     
+        commet_file.close()
 
 	# edit the command line
 	cmd_line=[]
 	cmd_line.append("Commet.py")
-	cmd_line.extend(["commet_clean_file","-b",os.environ['BINARIES'],"-k",options.kmer,"-t",options.minsharedkmer,"-l",options.minlengthread,"-e",options.minshannonindex])
+	cmd_line.extend(["commet_config_file","-b",os.environ['BINARIES'],"-k",options.kmer,"-t",options.minsharedkmer,"-l",options.minlengthread,"-e",options.minshannonindex])
 
 	# add options
 	if options.maxn:
-		
-		#cmd_line += ' -n '+options.maxn+' -m '+options.maxreads+' > '+options.output+' 2>>'+options.output
 		cmd_line.extend(["-n",options.maxn,"-m",options.maxreads])
-	#else:
-		#cmd_line += ' > '+options.output+' 2>>'+options.output
 
 	# execute job
-	p=subprocess.Popen(cmd_line,
-                   stdout=subprocess.PIPE,stderr=subprocess.PIPE)
-
-	stdoutput, stderror = p.communicate()
+	p=subprocess.call(cmd_line)
 
-	# log file
-        logfile=open(options.output, "w")
-	logfile.write("[COMMAND LINE]"+' '.join(cmd_line)+"\n\n")
-	logfile.write(str(stdoutput))
-	logfile.write(str(stderror))
-	logfile.close()
+	print "[COMMAND LINE]"+' '.join(cmd_line)
 
 	# copy .bv files inside a .bv archive
 	tmp_output_dir=os.getcwd()+"/output_commet/"
@@ -120,10 +102,13 @@
         shutil.move(tmp_output_dir+'matrix.zip.temp', options.output_matrix)
 
 	# outputs
-        shutil.move(tmp_output_dir+'dendrogram_normalized.png', options.output_dendro)
-	shutil.move(tmp_output_dir+'heatmap_normalized.png', options.output_heatmap1)
-	shutil.move(tmp_output_dir+'heatmap_percentage.png', options.output_heatmap2)
-	shutil.move(tmp_output_dir+'heatmap_plain.png', options.output_heatmap3)
+        try:
+            shutil.move(tmp_output_dir+'dendrogram_normalized.png', options.output_dendro)
+            shutil.move(tmp_output_dir+'heatmap_percentage.png', options.output_heatmap2)
+            shutil.move(tmp_output_dir+'heatmap_normalized.png', options.output_heatmap1)
+            shutil.move(tmp_output_dir+'heatmap_plain.png', options.output_heatmap3)
+        except:
+            print "There is a problem with gplots execution"
 
 if __name__ == "__main__": __main__()
 
--- a/commet.xml	Thu Sep 10 09:59:53 2015 +0000
+++ b/commet.xml	Thu Sep 10 13:38:21 2015 +0000
@@ -2,12 +2,13 @@
   <description>COmpare Multiple METagenomes</description>
   <requirements>
     <requirement type="package" version="24.7.14">commet</requirement>
-    <requirement type="package" version="2.15.0">R</requirement>
-    <requirement type="package" version="0.9.3">ggplot2</requirement>
+    <requirement type="package" version="3.0.1">R</requirement>
   </requirements>
 <command interpreter="python">
 commet.py
---input $input
+#for $set in $sets
+    --set ${set.setname}::${set.reads}
+#end for
 -k $kmer
 -t $minsharedkmer
 -l $minlengthread
@@ -19,7 +20,6 @@
 --output $output
 --output_vectors $output_vectors
 --output_dendro $output_dendro
---output_logs $output_logs
 --output_matrix $output_matrix
 --output_heatmap1 $output_heatmap1
 --output_heatmap2 $output_heatmap2
@@ -28,7 +28,10 @@
 
   <inputs>
 	<!-- Input data files -->
-	<param name="input" type="data" format="commet" label="Read sets" help="input read sets a line = a set composed by “set_name: read_file; read_file...“. Generate with Prepare commet tool" /> 
+        <repeat name="sets" title="Read sets" min="1">
+            <param name="reads" type="data" multiple="true" format="fasta, fastq, fastq.gz" label="Dataset" help="Accept fasta/fastq/fastq.gz"/>
+            <param name="setname" type="text" label="Set name" value="set_name" help="Please don't use spaces or special characters"/>
+        </repeat>
 	<param name="kmer" type="integer" label="Size of kmers" value="33" help="Set the length of used kmers." />
 	<param name="minsharedkmer" type="integer" label="Mini shared kmers" value="2" help="Minimal number of shared kmers." />
 	<param name="minlengthread" type="integer" label="Read mini length" value="0" help="Minimal length a read should have to be kept." />
@@ -44,9 +47,7 @@
 		</when>
 	</conditional>
   </inputs>
-
   <outputs>
-      <data format="txt" name="output" label="${tool.name} on ${on_string}: commet.log" />
       <data format="zip" name="output_vectors" label="${tool.name} on ${on_string}: vector.zip" />
       <data format="zip" name="output_logs" label="${tool.name} on ${on_string}: logs.zip" />
       <data format="png" name="output_dendro" label="${tool.name} on ${on_string}: dendrogram.png" />
@@ -55,6 +56,9 @@
       <data format="png" name="output_heatmap2" label="${tool.name} on ${on_string}: heatmap_percentage.png" />
       <data format="png" name="output_heatmap3" label="${tool.name} on ${on_string}: heatmap_plain.png" />
   </outputs>
+  <stdio>
+    <exit_code range="1" level="fatal" description="Error in Commet execution" />
+  </stdio>  
   <help>
 
 **Description**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/repository_dependencies.xml	Thu Sep 10 13:38:21 2015 +0000
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<repositories>
+   <repository changeset_revision="fcd9ce567d57" name="archive_toolbox" owner="cmonjeau" toolshed="https://toolshed.g2.bx.psu.edu" />
+</repositories>
--- a/tool_dependencies.xml	Thu Sep 10 09:59:53 2015 +0000
+++ b/tool_dependencies.xml	Thu Sep 10 13:38:21 2015 +0000
@@ -3,11 +3,7 @@
   <package name="commet" version="24.7.14">
       <repository changeset_revision="741836b9e2c5" name="package_commet_24_07_14" owner="cmonjeau" prior_installation_required="True" toolshed="https://toolshed.g2.bx.psu.edu" />
   </package>
-  <package name="R" version="2.15.0">
-       <repository changeset_revision="07de191649b4" name="package_r_ggplot2_0_9_3" owner="iuc" prior_installation_required="True" toolshed="https://toolshed.g2.bx.psu.edu" />
+  <package name="R" version="3.0.1">
+      <repository changeset_revision="59b82e6e0801" name="package_r_3_0_1" owner="iuc" prior_installation_required="True" toolshed="https://toolshed.g2.bx.psu.edu" />
   </package>
-  <package name="ggplot2" version="0.9.3">
-       <repository changeset_revision="07de191649b4" name="package_r_ggplot2_0_9_3" owner="iuc" prior_installation_required="True" toolshed="https://toolshed.g2.bx.psu.edu" />
-  </package>
-
 </tool_dependency>