Mercurial > repos > sblanck > mpagenomics_wrappers
comparison segmentFracB.py @ 8:d5ed62b4d3ac draft default tip
planemo upload for repository https://github.com/sblanck/MPAgenomics4Galaxy/tree/master/mpagenomics_wrappers commit 689d0d8dc899a683ee18700ef385753559850233
| author | sblanck |
|---|---|
| date | Tue, 12 May 2020 13:40:07 +0000 |
| parents | f2d24110f65a |
| children |
comparison
equal
deleted
inserted
replaced
| 7:f2d24110f65a | 8:d5ed62b4d3ac |
|---|---|
| 1 import os | |
| 2 import sys | |
| 3 import subprocess | |
| 4 import zipfile | |
| 5 import getopt | |
| 6 | |
| 7 | |
| 8 def main(argv): | |
| 9 | |
| 10 try: | |
| 11 opts, args = getopt.getopt(argv,"hc:i:o:f:s:og:fig:t:p:l:u:m:",["chrom=","input=","output=","new_file_path=","settings_type=","output_graph=","zip_figures=","settings_tumor=","outputlog=","log=","userid=","method="]) | |
| 12 except getopt.GetoptError as err: | |
| 13 print str(err) | |
| 14 sys.exit(2) | |
| 15 for opt, arg in opts: | |
| 16 if opt == '-h': | |
| 17 print 'extractCNopts.py' | |
| 18 sys.exit() | |
| 19 elif opt in ("-c", "--chrom"): | |
| 20 chromosome = arg | |
| 21 elif opt in ("-i", "--input"): | |
| 22 input_file = arg | |
| 23 elif opt in ("-o", "--output"): | |
| 24 output_file = arg | |
| 25 elif opt in ("-f", "--new_file_path"): | |
| 26 tmp_dir = arg | |
| 27 elif opt in ("-s", "--settings_type"): | |
| 28 input_type = arg | |
| 29 elif opt in ("-og", "--output_graph"): | |
| 30 output_graph = arg | |
| 31 elif opt in ("-fig", "--zip_figures"): | |
| 32 zip_file = arg | |
| 33 elif opt in ("-t", "--settings_tumor"): | |
| 34 tumorcsv = arg | |
| 35 elif opt in ("-p", "--outputlog"): | |
| 36 outputlog = arg | |
| 37 elif opt in ("-l", "--log"): | |
| 38 log = arg | |
| 39 elif opt in ("-u", "--userid"): | |
| 40 user_id = arg | |
| 41 elif opt in ("-m", "--method"): | |
| 42 method = arg | |
| 43 | |
| 44 script_dir=os.path.dirname(os.path.abspath(__file__)) | |
| 45 | |
| 46 iFile=open(input_file,'r') | |
| 47 dataSetLine=iFile.readline() | |
| 48 dataset=dataSetLine.split("\t")[1] | |
| 49 iFile.close() | |
| 50 | |
| 51 | |
| 52 if input_type=="dataset": | |
| 53 input_type=dataset | |
| 54 | |
| 55 if (outputlog=="TRUE"): | |
| 56 errfile=open(log,'w') | |
| 57 else: | |
| 58 errfile=open(os.path.join(tmp_dir,"errfile.log"),'w') | |
| 59 | |
| 60 fig_dir=os.path.join("mpagenomics",user_id,"figures",dataset,"segmentation/fracB") | |
| 61 | |
| 62 abs_fig_dir=os.path.join(tmp_dir,fig_dir) | |
| 63 if (os.path.isdir(abs_fig_dir)) and (output_graph=="TRUE"): | |
| 64 old_files=os.listdir(abs_fig_dir) | |
| 65 for ifile in old_files: | |
| 66 os.remove(os.path.join(abs_fig_dir,ifile)) | |
| 67 | |
| 68 | |
| 69 retcode=subprocess.call(["Rscript", os.path.join(script_dir,"segmentFracB.R"), chromosome, dataset, output_file, tmp_dir, input_type, output_graph, tumorcsv, user_id, method], stdout = errfile, stderr = errfile) | |
| 70 | |
| 71 errfile.close() | |
| 72 | |
| 73 if (retcode == 0): | |
| 74 if (os.path.isdir(abs_fig_dir)) and (output_graph=="TRUE"): | |
| 75 | |
| 76 new_files=os.listdir(abs_fig_dir) | |
| 77 zipbuf = zipfile.ZipFile(os.path.join(abs_fig_dir,zip_file), 'w', zipfile.ZIP_DEFLATED) | |
| 78 for current_file in new_files: | |
| 79 fn = os.path.join(abs_fig_dir,current_file) | |
| 80 relfn=fn[len(abs_fig_dir)+len(os.sep):] | |
| 81 zipbuf.write(fn,relfn) | |
| 82 sys.exit(retcode) | |
| 83 else: | |
| 84 sys.exit(retcode) | |
| 85 | |
| 86 if __name__ == "__main__": | |
| 87 main(main(sys.argv[1:])) |
