Repository 'peakranger'
hg clone https://toolshed.g2.bx.psu.edu/repos/modencode-dcc/peakranger

Changeset 9:b3366931d056 (2013-01-17)
Previous changeset 8:0af806f1d2f5 (2013-01-17) Next changeset 10:6f56c88fc1d7 (2013-01-17)
Commit message:
Uploaded
added:
ranger_wrapper.py
b
diff -r 0af806f1d2f5 -r b3366931d056 ranger_wrapper.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ranger_wrapper.py Thu Jan 17 16:21:24 2013 -0500
[
b'@@ -0,0 +1,184 @@\n+#purpose: python wrapper to run peak ranger\n+#author: Ziru Zhou\n+#Date: November 2012\n+\n+import sys, subprocess, tempfile, shutil, glob, os, os.path, gzip\n+from galaxy import eggs\n+import pkg_resources\n+pkg_resources.require( "simplejson" )\n+import simplejson\n+import glob\n+import datetime\n+\n+CHUNK_SIZE = 1024\n+\n+def main():\n+    options = simplejson.load( open( sys.argv[1] ) )\n+    outputs = simplejson.load( open( sys.argv[2] ) )\n+\n+\n+    #sets experiment name and sets the chip/input files\n+    #========================================================================================    \n+    experiment_name = \'_\'.join( options[\'experiment_name\'].split() ) #save experiment name\n+\n+    #cmdline = "bash /mnt/galaxyTools/galaxy-central/tools/modENCODE_DCC_tools/peakranger/peakranger %s -d %s --format bam" % ( options[\'action\'], options[\'chip_file\'] )\n+    cmdline = "peakranger %s -d %s" % ( options[\'action\'], options[\'chip_file\'] )\n+    if \'input_file\' in options:\n+        cmdline = "%s -c %s" % ( cmdline, options[\'input_file\'] )\n+\n+    #set additional options\n+    #========================================================================================\n+    if (options[\'action\'] == "nr"):\n+\toutput_ranger_file = outputs[\'output_ranger_file\']\n+\n+\tcmdline = "%s --format bam -l %s --verbose > default_output.txt" % ( cmdline, options[\'extension\'] ) \n+    elif (options[\'action\'] == "lc"):\n+\toutput_ranger_file = outputs[\'output_ranger_file\']\n+\n+\tcmdline = "%s --verbose > default_output.txt" % ( cmdline )\n+    elif (options[\'action\'] == "wig"):\n+\toutput_wigzip_file = outputs[\'output_wigzip_file\']\n+\n+\tcmdline = "%s --format bam -l %s %s %s %s -o ranger_wig" % ( cmdline, options[\'extension\'], options[\'split\'], options[\'strand\'], options[\'gzip\'] ) \n+    elif (options[\'action\'] == "wigpe"):\n+\toutput_wigzip_file = outputs[\'output_wigzip_file\']\n+\n+\tcmdline = "%s -l %s %s %s %s -o ranger_wig" % ( cmdline, options[\'extension\'], options[\'split\'], options[\'strand\'], options[\'gzip\'] ) \n+    elif (options[\'action\'] == "ranger"):\n+\toutput_summit_file = outputs[\'output_summit_file\']\n+\toutput_region_file = outputs[\'output_region_file\']\n+\toutput_details_file = outputs[\'output_details_file\']\n+\toutput_report_file = outputs[\'output_report_file\']\n+\n+\tif (options[\'gene_annotate_file\'] != "None"):\n+\t\tgene_annotate_file = "--gene_annot_file /mnt/galaxyTools/galaxy-central/tools/modENCODE_DCC_tools/peakranger/gene_annotation_files/%s" % options[\'gene_annotate_file\']\n+\t\treport = "--report"\n+\telif (options[\'gene_annotate_file\'] == "Upload"):\n+\t\tgene_annotate_file = options[\'usr_annot_file\']\n+\t\treport = "--report"\n+\telse:\n+\t\tgene_annotate_file = ""\n+\t\treport = ""\n+\n+\tcmdline = "%s -t %s --format bam %s --plot_region %s -l %s -p %s -q %s -r %s -b %s %s %s -o ranger_peak" % ( cmdline, options[\'threads\'], gene_annotate_file, options[\'plot_region\'], options[\'extension\'], options[\'pvalue\'], options[\'fdr\'], options[\'delta\'], options[\'bandwith\'], options[\'pad\'], report )\n+    elif (options[\'action\'] == "ccat"):\n+\toutput_summit_file = outputs[\'output_summit_file\']\n+\toutput_region_file = outputs[\'output_region_file\']\n+\toutput_details_file = outputs[\'output_details_file\']\n+\toutput_report_file = outputs[\'output_report_file\']\n+\toutput_ranger_file = outputs[\'output_ranger_file\']\n+\t\n+\tif (options[\'gene_annotate_file\'] != "None"):\n+\t\tgene_annotate_file = "--gene_annot_file /mnt/galaxyTools/galaxy-central/tools/modENCODE_DCC_tools/peakranger/gene_annotation_files/%s" % options[\'gene_annotate_file\']\n+\t\treport = "--report"\n+\telif (options[\'gene_annotate_file\'] == "Upload"):\n+\t\tgene_annotate_file = options[\'usr_annot_file\']\n+\t\treport = "--report"\n+\telse:\n+\t\tgene_annotate_file = ""\n+\t\treport = ""\n+\n+\tcmdline = "%s --format bam %s --plot_region %s -l %s -q %s --win_size %s --win_step %s --min_count %s --min_score %s %s -o ranger_peak > default_output.txt" % ( cmdline, gene_annotate_file, options[\'plot_region\'], options[\'extension\'], options[\'fdr\'], options[\'winsize'..b'uts are there, copy them to the appropriate dir and filename\n+    #========================================================================================\n+    if(options[\'action\'] == "nr" or options[\'action\'] == "lc" or options[\'action\'] == "ccat"):\n+\tcreated_ranger_file =  os.path.join( tmp_dir, "default_output.txt" )\n+        if os.path.exists( created_ranger_file ):\n+        \tshutil.move( created_ranger_file, output_ranger_file )\n+\n+    if(options[\'action\'] == "wig" or options[\'action\'] == "wigpe"):\n+\tif(options[\'split\'] == "-s" or options[\'strand\'] == "-x"):\n+\t\tif(options[\'gzip\'] == "-z"):\n+\t\t\tfiles = str( glob.glob(\'%s/*.wig.gz\' % tmp_dir) )\n+\t\t\tfiles = files.replace("[", "")\n+\t\t\tfiles = files.replace("]", "")\n+\t\t\tfiles = files.replace(",", "")\n+\t\t\tfiles = files.replace("\'", "")\n+\t\t\tcmd = "zip -j %s/ranger_wig.zip %s > /dev/null" % (tmp_dir, files)\n+\t\t\t#cmd = "tar -czvf %s/ranger_wig.tar %s > /dev/null" % (tmp_dir, files)\n+\t\t\tos.system(cmd)\n+\t\t\tcreated_wigzip_file =  os.path.join( tmp_dir, "ranger_wig.zip" )\n+\t\telse:\n+\t\t\tfiles = str( glob.glob(\'%s/*.wig\' % tmp_dir) )\n+\t\t\tfiles = files.replace("[", "")\n+\t\t\tfiles = files.replace("]", "")\n+\t\t\tfiles = files.replace(",", "")\n+\t\t\tfiles = files.replace("\'", "")\n+\t\t\tcmd = "zip -j %s/ranger_wig.zip %s > /dev/null" % (tmp_dir, files)\n+\t\t\t#cmd = "tar -czvf %s/ranger_wig.tar %s > /dev/null" % (tmp_dir, files)\n+\t\t\tos.system(cmd)\n+\t\t\tcreated_wigzip_file =  os.path.join( tmp_dir, "ranger_wig.zip" )\n+\telse:\n+\t\tif(options[\'gzip\'] == "-z"):\n+\t\t\tcreated_wigzip_file =  os.path.join( tmp_dir, "ranger_wig.wig.gz" )\n+\t\telse:\n+\t\t\tcreated_wigzip_file =  os.path.join( tmp_dir, "ranger_wig.wig" )\n+ \n+\tif os.path.exists( created_wigzip_file ):\n+        \tshutil.move( created_wigzip_file, output_wigzip_file )\n+ \n+    if(options[\'action\'] == "ranger" or options[\'action\'] == "ccat"):\t\n+\tcreated_summit_file =  os.path.join( tmp_dir, "ranger_peak_summit.bed"  )\n+\tif os.path.exists( created_summit_file ):\n+        \tshutil.move( created_summit_file, output_summit_file )\n+\n+\tcreated_region_file =  os.path.join( tmp_dir, "ranger_peak_region.bed"  )\n+\tif os.path.exists( created_region_file ):\n+        \tshutil.move( created_region_file, output_region_file )\n+\n+\tcreated_details_file =  os.path.join( tmp_dir, "ranger_peak_details"  )\n+\tif os.path.exists( created_details_file ):\n+        \tshutil.move( created_details_file, output_details_file )\n+\n+\t#zips the html report and puts it in history, whole report is too big and display in galaxy is very unformatted \n+\tfilename = os.path.splitext(os.path.basename(options[\'chip_file\']))[0]\n+\tfilename = filename.upper()\n+\textension = os.path.splitext(options[\'chip_file\'])[1]\n+\textension = extension.replace(".", "")\n+\textension = extension.upper()\n+\tnow = datetime.datetime.now()\n+\tdate = now.strftime("%Y-%m-%d")\n+\tfoldername = "%s_%s_REPORT_%s" % (filename, extension, date)\n+\n+\tcreated_report_file = os.path.join( tmp_dir, foldername )\n+\tif os.path.exists ( created_report_file ):\n+\t\t#os.system("cp -rf %s %s" % (created_report_file, "/mnt/galaxyData/files/000/"))\n+\t\tos.system("cp -rf %s ." % created_report_file)\n+\t\tos.system("zip -r created_report.zip %s > /dev/null" % foldername)\n+\t\t#os.system("zip -r created_report.zip /mnt/galaxyData/files/000/%s > /dev/null" % foldername)\n+\t\tshutil.move( "created_report.zip", output_report_file)\n+\n+\n+\t\t#os.system("ln -fs %s/index.html %s" %( foldername, output_report_file ))\n+\t\t#datafoldername = os.path.splitext(os.path.basename(output_report_file))\n+\t\t#datafolder = os.path.join ("/mnt/galaxyData/files/000/" datafoldername)\n+\t\t#print "datafolder %s" % datafolder\n+\t\t#if os.path.exists( datafolder )\n+\t\t#\tos.system("rm -rf %s" % datafolder)\n+\t\t#\tos.system("cp -rf %s/%s/imgs /mnt/galaxyData/files/000/%s" % (tmp_dir, foldername, datafolder))\n+\t\t#\tos.system("cp -rf %s/%s/scripts /mnt/galaxyData/files/000/%s" % (tmp_dir, foldername, datafolder))\n+\n+    os.unlink( stderr_name )\n+    shutil.rmtree( tmp_dir )\n+\n+if __name__ == "__main__": main()\n'