1- class MyUtils {
2- // Check if params is in this given list
1+ import static nextflow.Nextflow.file
2+ import nextflow.Channel
3+
4+ class SarekUtils {
5+
6+ // Check file extension
7+ static def checkFileExtension (it , extension ) {
8+ if (! it. toString(). toLowerCase(). endsWith(extension. toLowerCase())) exit 1 , " File: ${ it} has the wrong extension: ${ extension} see --help for more information"
9+ }
10+
11+ // Check parameter existence
12+ static def checkParameterExistence (it , list ) {
13+ if (! list. contains(it)) {
14+ println (" Unknown parameter: ${ it} " )
15+ return false
16+ }
17+ return true
18+ }
19+
20+ // Compare each parameter with a list of parameters
21+ static def checkParameterList (list , realList ) {
22+ return list. every{ checkParameterExistence(it, realList) }
23+ }
24+
25+ // Return element in list of allowed params
326 static def checkParams (it ) {
427 return it in [
528 ' annotate-tools' ,
@@ -68,15 +91,22 @@ class MyUtils {
6891 ' version' ]
6992 }
7093
71- // Loop through all parameters to check their existence and spelling
72- static def checkParameterList (list , realList ) {
73- return list. every{ checkParameterExistence(it, realList) }
94+ // Loop through all the references files to check their existence
95+ static def checkReferenceMap (referenceMap ) {
96+ referenceMap. every {
97+ referenceFile, fileToCheck ->
98+ SarekUtils . checkRefExistence(referenceFile, fileToCheck)
99+ }
74100 }
75101
76- // Check parameter existence
77- static def checkParameterExistence (it , list ) {
78- if (! list. contains(it)) {
79- println (" Unknown parameter: ${ it} " )
102+ // Loop through all the references files to check their existence
103+ static def checkRefExistence (referenceFile , fileToCheck ) {
104+ if (fileToCheck instanceof List ) return fileToCheck. every{ SarekUtils . checkRefExistence(referenceFile, it) }
105+ def f = file(fileToCheck)
106+ // this is an expanded wildcard: we can assume all files exist
107+ if (f instanceof List && f. size() > 0 ) return true
108+ else if (! f. exists()) {
109+ this . log. info " Missing references: ${ referenceFile} ${ fileToCheck} "
80110 return false
81111 }
82112 return true
@@ -85,32 +115,66 @@ class MyUtils {
85115 // Define map of directories
86116 static def defineDirectoryMap (outDir ) {
87117 return [
88- ' nonRealigned' : " ${ outDir} /Preprocessing/NonRealigned" ,
89- ' nonRecalibrated' : " ${ outDir} /Preprocessing/NonRecalibrated" ,
90- ' recalibrated' : " ${ outDir} /Preprocessing/Recalibrated" ,
91- ' ascat' : " ${ outDir} /VariantCalling/Ascat" ,
92- ' freebayes' : " ${ outDir} /VariantCalling/FreeBayes" ,
93- ' gvcf-hc' : " ${ outDir} /VariantCalling/HaplotypeCallerGVCF" ,
94- ' haplotypecaller' : " ${ outDir} /VariantCalling/HaplotypeCaller" ,
95- ' manta' : " ${ outDir} /VariantCalling/Manta" ,
96- ' mutect1' : " ${ outDir} /VariantCalling/MuTect1" ,
97- ' mutect2' : " ${ outDir} /VariantCalling/MuTect2" ,
98- ' strelka' : " ${ outDir} /VariantCalling/Strelka" ,
99- ' strelkabp' : " ${ outDir} /VariantCalling/StrelkaBP" ,
100- ' snpeff' : " ${ outDir} /Annotation/SnpEff" ,
101- ' vep' : " ${ outDir} /Annotation/VEP" ,
102- ' bamQC' : " ${ outDir} /Reports/bamQC" ,
103- ' bcftoolsStats' : " ${ outDir} /Reports/BCFToolsStats" ,
104- ' fastQC' : " ${ outDir} /Reports/FastQC" ,
105- ' markDuplicatesQC' : " ${ outDir} /Reports/MarkDuplicates" ,
106- ' multiQC' : " ${ outDir} /Reports/MultiQC" ,
107- ' samtoolsStats' : " ${ outDir} /Reports/SamToolsStats" ,
108- ' snpeffReports' : " ${ outDir} /Reports/SnpEff" ,
109- ' vcftools' : " ${ outDir} /Reports/VCFTools" ,
110- ' version' : " ${ outDir} /Reports/ToolsVersion"
118+ ' nonRealigned' : " ${ outDir} /Preprocessing/NonRealigned" ,
119+ ' nonRecalibrated' : " ${ outDir} /Preprocessing/NonRecalibrated" ,
120+ ' recalibrated' : " ${ outDir} /Preprocessing/Recalibrated" ,
121+ ' ascat' : " ${ outDir} /VariantCalling/Ascat" ,
122+ ' freebayes' : " ${ outDir} /VariantCalling/FreeBayes" ,
123+ ' gvcf-hc' : " ${ outDir} /VariantCalling/HaplotypeCallerGVCF" ,
124+ ' haplotypecaller' : " ${ outDir} /VariantCalling/HaplotypeCaller" ,
125+ ' manta' : " ${ outDir} /VariantCalling/Manta" ,
126+ ' mutect1' : " ${ outDir} /VariantCalling/MuTect1" ,
127+ ' mutect2' : " ${ outDir} /VariantCalling/MuTect2" ,
128+ ' strelka' : " ${ outDir} /VariantCalling/Strelka" ,
129+ ' strelkabp' : " ${ outDir} /VariantCalling/StrelkaBP" ,
130+ ' snpeff' : " ${ outDir} /Annotation/SnpEff" ,
131+ ' vep' : " ${ outDir} /Annotation/VEP" ,
132+ ' bamQC' : " ${ outDir} /Reports/bamQC" ,
133+ ' bcftoolsStats' : " ${ outDir} /Reports/BCFToolsStats" ,
134+ ' fastQC' : " ${ outDir} /Reports/FastQC" ,
135+ ' markDuplicatesQC' : " ${ outDir} /Reports/MarkDuplicates" ,
136+ ' multiQC' : " ${ outDir} /Reports/MultiQC" ,
137+ ' samtoolsStats' : " ${ outDir} /Reports/SamToolsStats" ,
138+ ' snpeffReports' : " ${ outDir} /Reports/SnpEff" ,
139+ ' vcftools' : " ${ outDir} /Reports/VCFTools" ,
140+ ' version' : " ${ outDir} /Reports/ToolsVersion"
111141 ]
112142 }
113143
144+ // Channeling the TSV file containing BAM.
145+ // Format is: "subject gender status sample bam bai"
146+ static def extractBams (tsvFile , mode ) {
147+ Channel
148+ .from(tsvFile. readLines())
149+ .map{line ->
150+ def list = SarekUtils . returnTSV(line. split(),6 )
151+ def idPatient = list[0 ]
152+ def gender = list[1 ]
153+ def status = SarekUtils . returnStatus(list[2 ]. toInteger())
154+ def idSample = list[3 ]
155+ def bamFile = SarekUtils . returnFile(list[4 ])
156+ def baiFile = SarekUtils . returnFile(list[5 ])
157+
158+ SarekUtils . checkFileExtension(bamFile," .bam" )
159+ SarekUtils . checkFileExtension(baiFile," .bai" )
160+
161+ if (mode == " germline" ) return [ idPatient, status, idSample, bamFile, baiFile ]
162+ else return [ idPatient, gender, status, idSample, bamFile, baiFile ]
163+ }
164+ }
165+
166+ // Extract gender from Channel as it's only used for CNVs
167+ static def extractGenders (channel ) {
168+ def genders = [:]
169+ channel = channel. map{ it ->
170+ def idPatient = it[0 ]
171+ def gender = it[1 ]
172+ genders[idPatient] = gender
173+ [idPatient] + it[2 .. -1 ]
174+ }
175+ [genders, channel]
176+ }
177+
114178 // Compare params to list of verified params
115179 static def isAllowedParams (params ) {
116180 final test = true
@@ -122,4 +186,34 @@ class MyUtils {
122186 }
123187 return test
124188 }
189+
190+ // Return file if it exists
191+ static def returnFile (it ) {
192+ if (! file(it). exists()) exit 1 , " Missing file in TSV file: ${ it} , see --help for more information"
193+ return file(it)
194+ }
195+
196+ // Return status [0,1]
197+ // 0 == Normal, 1 == Tumor
198+ static def returnStatus (it ) {
199+ if (! (it in [0 , 1 ])) exit 1 , " Status is not recognized in TSV file: ${ it} , see --help for more information"
200+ return it
201+ }
202+
203+ // Return TSV if it has the correct number of items in row
204+ static def returnTSV (it , number ) {
205+ if (it. size() != number) exit 1 , " Malformed row in TSV file: ${ it} , see --help for more information"
206+ return it
207+ }
208+
209+ // Sarek ascii art
210+ static def sarek_ascii () {
211+ println " ____ _____ _ "
212+ println " .' _ `. / ____| | | "
213+ println " / |\\ `-_ \\ | (___ __ _ _ __ ___| | __ "
214+ println " | | \\ `-| \\ ___ \\ / _` | '__/ __| |/ / "
215+ println " \\ | \\ / ____) | (_| | | | __| < "
216+ println " `|____\\ ' |_____/ \\ __,_|_| \\ ___|_|\\ _\\ "
217+ }
218+
125219}
0 commit comments