annotate abims_sartools_deseq2_wrapper.py @ 3:de6d0b7c17af draft

release 1.6.3
author lgueguen
date Mon, 01 Oct 2018 05:07:56 -0400
parents 581d217c7337
children 05c9b1a7f44e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
1 #abims_sartools_deseq2_wrapper.py
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
2 #Author: Loraine Gueguen
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
3 # imports
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
4 import os, argparse
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
5
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
6
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
7
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
8 def main():
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
9
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
10 print("Start of galaxy wrapper")
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
11
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
12 #Check R and Rscript are installed
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
13 check_r_cmd="command -v R >/dev/null 2>&1 || { echo >&2 'This tool requires R but it is not installed. Aborting.'; exit 1; }"
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
14 check_rscript_cmd="command -v Rscript >/dev/null 2>&1 || { echo >&2 'This tool requires Rscript but it is not installed. Aborting.'; exit 1; }"
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
15 os.system(check_r_cmd)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
16 os.system(check_rscript_cmd)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
17
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
18 #Get arguments
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
19 parser = argparse.ArgumentParser()
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
20 parser.add_argument('--projectName')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
21 parser.add_argument('--author')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
22 parser.add_argument('--targetFile')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
23 parser.add_argument('--rawDir')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
24 parser.add_argument('--featuresToRemove')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
25 parser.add_argument('--varInt')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
26 parser.add_argument('--condRef')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
27 parser.add_argument('--batch')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
28 parser.add_argument('--fitType')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
29 parser.add_argument('--cooksCutoff')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
30 parser.add_argument('--independentFiltering')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
31 parser.add_argument('--alpha')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
32 parser.add_argument('--pAdjustMethod')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
33 parser.add_argument('--typeTrans')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
34 parser.add_argument('--locfunc')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
35 parser.add_argument('--colors')
3
de6d0b7c17af release 1.6.3
lgueguen
parents: 0
diff changeset
36 parser.add_argument('--forceCairoGraph')
0
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
37 parser.add_argument('--figures_html')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
38 parser.add_argument('--figures_html_files_path')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
39 parser.add_argument('--tables_html')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
40 parser.add_argument('--tables_html_files_path')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
41 parser.add_argument('--rdata')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
42 parser.add_argument('--report_html')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
43 parser.add_argument('--log')
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
44 args = parser.parse_args()
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
45 projectName=args.projectName
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
46 author=args.author
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
47 targetFile=args.targetFile
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
48 rawDir=args.rawDir
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
49 featuresToRemove=args.featuresToRemove
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
50 varInt=args.varInt
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
51 condRef=args.condRef
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
52 batch=args.batch
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
53 fitType=args.fitType
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
54 cooksCutoff=args.cooksCutoff
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
55 independentFiltering=args.independentFiltering
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
56 alpha=args.alpha
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
57 pAdjustMethod=args.pAdjustMethod
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
58 typeTrans=args.typeTrans
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
59 locfunc=args.locfunc
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
60 colors=args.colors
3
de6d0b7c17af release 1.6.3
lgueguen
parents: 0
diff changeset
61 forceCairoGraph=args.forceCairoGraph
0
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
62 figures_html=args.figures_html
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
63 figures_html_files_path=args.figures_html_files_path
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
64 tables_html=args.tables_html
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
65 tables_html_files_path=args.tables_html_files_path
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
66 rdata=args.rdata
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
67 report_html=args.report_html
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
68 log=args.log
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
69 #Print the parameters selected
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
70 print("Wrapper arguments: %s") %(args)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
71
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
72 #Get the working directory path
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
73 working_directory = os.getcwd()
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
74 #Get the script directory path
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
75 script_directory=os.path.dirname(os.path.realpath(__file__))
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
76
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
77 #Unzip files from rawDir
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
78 rawDir_unzipped_path=working_directory+"/rawDir_unzipped"
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
79 os.mkdir(rawDir_unzipped_path)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
80 unzip_cmd="unzip -j %s -d %s" % (rawDir,rawDir_unzipped_path) #-j arg: junk paths
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
81 os.system(unzip_cmd)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
82
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
83 #Create the command
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
84 cmd="Rscript --no-save --no-restore %s/template_script_DESeq2_CL.r --projectName %s --author %s " % (script_directory,projectName,author)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
85 cmd+="--targetFile %s --rawDir %s --featuresToRemove %s --varInt %s --condRef %s " % (targetFile,rawDir_unzipped_path,featuresToRemove,varInt,condRef)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
86 if batch and batch!="NULL":
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
87 cmd+="--batch %s " % (batch)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
88 if fitType:
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
89 cmd+="--fitType %s " % (fitType)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
90 if cooksCutoff:
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
91 cmd+="--cooksCutoff %s " % (cooksCutoff)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
92 if independentFiltering:
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
93 cmd+="--independentFiltering %s " % (independentFiltering)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
94 if alpha:
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
95 cmd+="--alpha %s " % (alpha)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
96 if pAdjustMethod:
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
97 cmd+="--pAdjustMethod %s " % (pAdjustMethod)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
98 if typeTrans:
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
99 cmd+="--typeTrans %s " % (typeTrans)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
100 if locfunc:
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
101 cmd+="--locfunc %s " % (locfunc)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
102 if colors:
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
103 cmd+="--colors %s " % (colors)
3
de6d0b7c17af release 1.6.3
lgueguen
parents: 0
diff changeset
104 if forceCairoGraph:
de6d0b7c17af release 1.6.3
lgueguen
parents: 0
diff changeset
105 cmd+="--forceCairoGraph %s " % (forceCairoGraph)
0
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
106 cmd+="> %s 2>&1" % (log)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
107 print("Rscript command: %s") % (cmd)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
108 os.system(cmd)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
109
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
110 #Get output files
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
111 os.mkdir(figures_html_files_path)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
112 os.mkdir(tables_html_files_path)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
113 rsync_figures_dir_cmd="rsync -r figures/* %s/." % (figures_html_files_path)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
114 rsync_tables_dir_cmd="rsync -r tables/* %s/." % (tables_html_files_path)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
115 os.system(rsync_figures_dir_cmd)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
116 os.system(rsync_tables_dir_cmd)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
117 figures_html_create_cmd="python %s/make_html.py --tool SARTools_DESeq2 --output_type Figures --output_dir %s --output_html %s" % (script_directory,figures_html_files_path,figures_html)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
118 tables_html_create_cmd="python %s/make_html.py --tool SARTools_DESeq2 --output_type Tables --output_dir %s --output_html %s" % (script_directory,tables_html_files_path,tables_html)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
119 os.system(figures_html_create_cmd)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
120 os.system(tables_html_create_cmd)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
121 rsync_rdata_file_cmd="rsync %s.RData %s" % (projectName,rdata)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
122 rsync_report_file_cmd="rsync %s_report.html %s" % (projectName,report_html)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
123 os.system(rsync_rdata_file_cmd)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
124 os.system(rsync_report_file_cmd)
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
125
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
126 print("End of galaxy wrapper")
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
127
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
128 if __name__ == '__main__':
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
129 main()
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
130
581d217c7337 Planemo upload
lgueguen
parents:
diff changeset
131