0
|
1 #abims_sartools_edger_wrapper.py
|
|
2 #Author: Loraine Gueguen
|
|
3 # imports
|
|
4 import os, argparse
|
|
5
|
|
6
|
|
7
|
|
8 def main():
|
|
9
|
|
10 print("Start of galaxy wrapper")
|
|
11
|
|
12 #Check R and Rscript are installed
|
|
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; }"
|
|
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; }"
|
|
15 os.system(check_r_cmd)
|
|
16 os.system(check_rscript_cmd)
|
|
17
|
|
18 #Get arguments
|
|
19 parser = argparse.ArgumentParser()
|
|
20 parser.add_argument('--projectName')
|
|
21 parser.add_argument('--author')
|
|
22 parser.add_argument('--targetFile')
|
|
23 parser.add_argument('--rawDir')
|
|
24 parser.add_argument('--featuresToRemove')
|
|
25 parser.add_argument('--varInt')
|
|
26 parser.add_argument('--condRef')
|
|
27 parser.add_argument('--batch')
|
|
28 parser.add_argument('--alpha')
|
|
29 parser.add_argument('--pAdjustMethod')
|
|
30 parser.add_argument('--cpmCutoff')
|
|
31 parser.add_argument('--geneSelection')
|
|
32 parser.add_argument('--normalizationMethod')
|
|
33 parser.add_argument('--colors')
|
3
|
34 parser.add_argument('--forceCairoGraph')
|
0
|
35 parser.add_argument('--figures_html')
|
|
36 parser.add_argument('--figures_html_files_path')
|
|
37 parser.add_argument('--tables_html')
|
|
38 parser.add_argument('--tables_html_files_path')
|
|
39 parser.add_argument('--rdata')
|
|
40 parser.add_argument('--report_html')
|
|
41 parser.add_argument('--log')
|
|
42 args = parser.parse_args()
|
|
43 projectName=args.projectName
|
|
44 author=args.author
|
|
45 targetFile=args.targetFile
|
|
46 rawDir=args.rawDir
|
|
47 featuresToRemove=args.featuresToRemove
|
|
48 varInt=args.varInt
|
|
49 condRef=args.condRef
|
|
50 batch=args.batch
|
|
51 alpha=args.alpha
|
|
52 pAdjustMethod=args.pAdjustMethod
|
|
53 cpmCutoff=args.cpmCutoff
|
|
54 geneSelection=args.geneSelection
|
|
55 normalizationMethod=args.normalizationMethod
|
|
56 colors=args.colors
|
3
|
57 forceCairoGraph=args.forceCairoGraph
|
0
|
58 figures_html=args.figures_html
|
|
59 figures_html_files_path=args.figures_html_files_path
|
|
60 tables_html=args.tables_html
|
|
61 tables_html_files_path=args.tables_html_files_path
|
|
62 rdata=args.rdata
|
|
63 report_html=args.report_html
|
|
64 log=args.log
|
|
65 #Print the parameters selected
|
|
66 print("Wrapper arguments: %s") %(args)
|
|
67
|
|
68 #Get the working directory path
|
|
69 working_directory = os.getcwd()
|
|
70 #Get the script directory path
|
|
71 script_directory=os.path.dirname(os.path.realpath(__file__))
|
|
72
|
|
73 #Unzip files from rawDir
|
|
74 rawDir_unzipped_path=working_directory+"/rawDir_unzipped"
|
|
75 os.mkdir(rawDir_unzipped_path)
|
|
76 unzip_cmd="unzip -j %s -d %s" % (rawDir,rawDir_unzipped_path) #-j arg: junk paths
|
|
77 os.system(unzip_cmd)
|
|
78
|
|
79 #Create the command
|
|
80 cmd="Rscript --no-save --no-restore %s/template_script_edgeR_CL.r --projectName %s --author %s " % (script_directory,projectName,author)
|
|
81 cmd+="--targetFile %s --rawDir %s --featuresToRemove %s --varInt %s --condRef %s " % (targetFile,rawDir_unzipped_path,featuresToRemove,varInt,condRef)
|
|
82 if batch and batch!="NULL":
|
|
83 cmd+="--batch %s " % (batch)
|
|
84 if alpha:
|
|
85 cmd+="--alpha %s " % (alpha)
|
|
86 if pAdjustMethod:
|
|
87 cmd+="--pAdjustMethod %s " % (pAdjustMethod)
|
|
88 if cpmCutoff:
|
|
89 cmd+="--cpmCutoff %s " % (cpmCutoff)
|
|
90 if geneSelection:
|
|
91 cmd+="--gene.selection %s " % (geneSelection)
|
|
92 if normalizationMethod:
|
|
93 cmd+="--normalizationMethod %s " % (normalizationMethod)
|
|
94 if colors:
|
|
95 cmd+="--colors %s " % (colors)
|
3
|
96 if forceCairoGraph:
|
|
97 cmd+="--forceCairoGraph %s " % (forceCairoGraph)
|
0
|
98 cmd+="> %s 2>&1" % (log)
|
|
99 print("Rscript command: %s") % (cmd)
|
|
100 os.system(cmd)
|
|
101
|
|
102 #Get output files
|
|
103 os.mkdir(figures_html_files_path)
|
|
104 os.mkdir(tables_html_files_path)
|
|
105 rsync_figures_dir_cmd="rsync -r figures/* %s/." % (figures_html_files_path)
|
|
106 rsync_tables_dir_cmd="rsync -r tables/* %s/." % (tables_html_files_path)
|
|
107 os.system(rsync_figures_dir_cmd)
|
|
108 os.system(rsync_tables_dir_cmd)
|
|
109 figures_html_create_cmd="python %s/make_html.py --tool SARTools_edgeR --output_type Figures --output_dir %s --output_html %s" % (script_directory,figures_html_files_path,figures_html)
|
|
110 tables_html_create_cmd="python %s/make_html.py --tool SARTools_edgeR --output_type Tables --output_dir %s --output_html %s" % (script_directory,tables_html_files_path,tables_html)
|
|
111 os.system(figures_html_create_cmd)
|
|
112 os.system(tables_html_create_cmd)
|
|
113 rsync_rdata_file_cmd="rsync %s.RData %s" % (projectName,rdata)
|
|
114 rsync_report_file_cmd="rsync %s_report.html %s" % (projectName,report_html)
|
|
115 os.system(rsync_rdata_file_cmd)
|
|
116 os.system(rsync_report_file_cmd)
|
|
117
|
|
118 print("End of galaxy wrapper")
|
|
119
|
|
120 if __name__ == '__main__':
|
|
121 main()
|
|
122
|
|
123
|