# HG changeset patch # User nanette # Date 1377083154 14400 # Node ID a303f3ffa15302f27e4b6f0ce2d81e3942ee4329 # Parent b41fc3e15949574876803a63b9f1c87bf30989bd Uploaded diff -r b41fc3e15949 -r a303f3ffa153 test_script_path.py --- a/test_script_path.py Wed Aug 21 05:56:49 2013 -0400 +++ b/test_script_path.py Wed Aug 21 07:05:54 2013 -0400 @@ -20,8 +20,11 @@ help="genes") parser.add_option("-o", "--output1", default=None, dest="output1", help="star genes") + parser.add_option("-p", "--output2", default=None, dest="output2", + help="plot") parser.add_option("-m", "--myflag", default=None, dest="myflag", help="star genes") + (options, args) = parser.parse_args() try: @@ -47,6 +50,31 @@ outfile.write("--- TEST ---" + "\n") outfile.close() + ########################################################## + + # Create temp direcotry + tempdir = tempfile.mkdtemp() + fixdir = options.myflag + + # copy INPUT file to the temp directory + # create R script => save in temp directory + # generate new header + new_script = open(tempdir+"/new_script.r","w") + header = "setwd(\"%s\")" %tempdir + new_script.write(header+"\n") + + # add script body + script = open(fixdir+"/r_plot.r","r") + for line in script: + new_script.write(line.strip()+"\n") + new_script.close() + + # run R script from temp directory + s = "R CMD BATCH %s/new_script.r out.txt" %tempdir + subprocess.call(s, shell=True) + + os.system("mv %s/plot.pdf %s" %(tempdir,options.output2)) + ############################################## if __name__=="__main__": diff -r b41fc3e15949 -r a303f3ffa153 test_script_path.xml --- a/test_script_path.xml Wed Aug 21 05:56:49 2013 -0400 +++ b/test_script_path.xml Wed Aug 21 07:05:54 2013 -0400 @@ -5,7 +5,7 @@ SCRIPT_PATH - test_script_path.py --input1 $input1 --output1 $output1 --myflag \$SCRIPT_PATH + test_script_path.py --input1 $input1 --output1 $output1 --output2 $output2 --myflag \$SCRIPT_PATH @@ -13,6 +13,7 @@ +