Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
biopet.biopet
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirrors
biopet.biopet
Commits
b4b6785a
Commit
b4b6785a
authored
9 years ago
by
bow
Browse files
Options
Downloads
Patches
Plain Diff
Refactor filename and extension retrieval in Flexiprep
parent
dafecf89
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Flexiprep.scala
+30
-14
30 additions, 14 deletions
...a/nl/lumc/sasc/biopet/pipelines/flexiprep/Flexiprep.scala
with
30 additions
and
14 deletions
public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Flexiprep.scala
+
30
−
14
View file @
b4b6785a
...
...
@@ -20,6 +20,8 @@ import nl.lumc.sasc.biopet.core.{ BiopetFifoPipe, PipelineCommand, SampleLibrary
import
nl.lumc.sasc.biopet.extensions.
{
Zcat
,
Gzip
}
import
nl.lumc.sasc.biopet.utils.config.Configurable
import
nl.lumc.sasc.biopet.extensions.tools.
{
SeqStat
,
FastqSync
}
import
org.apache.commons.io.FilenameUtils.getExtension
import
org.broadinstitute.gatk.queue.QScript
class
Flexiprep
(
val
root
:
Configurable
)
extends
QScript
with
SummaryQScript
with
SampleLibraryTag
{
...
...
@@ -73,6 +75,31 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
Some
(
flexiprepReport
)
}
/** Possible compression extensions to trim from input files. */
private
val
zipExtensions
=
Set
(
".gz"
,
".gzip"
)
/**
* Given a file object and a set of compression extensions, return the filename without any of the compression
* extensions and the filename's extension.
*
* Examples:
* - my_file.fq.gz returns ("my_file.fq", ".fq")
* - my_other_file.fastq returns ("my_file.fastq", ".fastq")
*
* @param f Input file object.
* @param exts Possible compression extensions to trim.
* @return Filename without compression extension and its extension.
*/
private
def
getNameAndExt
(
f
:
File
,
exts
:
Set
[
String
]
=
zipExtensions
)
:
(
String
,
String
)
=
{
val
unzippedFilename
=
zipExtensions
.
foldLeft
(
f
.
toString
)
{
case
(
fname
,
ext
)
=>
if
(
fname
.
toLowerCase
.
endsWith
(
ext
))
fname
.
dropRight
(
ext
.
length
)
else
fname
}
val
unzippedExt
=
"."
+
getExtension
(
unzippedFilename
)
(
unzippedFilename
,
unzippedExt
)
}
/** Function that's need to be executed before the script is accessed */
def
init
()
{
require
(
outputDir
!=
null
,
"Missing output directory on flexiprep module"
)
...
...
@@ -85,21 +112,10 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
inputFiles
:+=
new
InputFile
(
input_R1
)
input_R2
.
foreach
(
inputFiles
:+=
new
InputFile
(
_
))
if
(
input_R1
.
endsWith
(
".gz"
))
R1_name
=
input_R1
.
getName
.
substring
(
0
,
input_R1
.
getName
.
lastIndexOf
(
".gz"
))
else
if
(
input_R1
.
endsWith
(
".gzip"
))
R1_name
=
input_R1
.
getName
.
substring
(
0
,
input_R1
.
getName
.
lastIndexOf
(
".gzip"
))
else
R1_name
=
input_R1
.
getName
R1_ext
=
R1_name
.
substring
(
R1_name
.
lastIndexOf
(
"."
),
R1_name
.
length
)
R1_name
=
R1_name
.
substring
(
0
,
R1_name
.
lastIndexOf
(
R1_ext
))
input_R2
match
{
case
Some
(
fileR2
)
=>
(
R1_ext
,
R1_name
)
=
getNameAndExt
(
input_R1
)
input_R2
.
foreach
{
fileR2
=>
paired
=
true
if
(
fileR2
.
endsWith
(
".gz"
))
R2_name
=
fileR2
.
getName
.
substring
(
0
,
fileR2
.
getName
.
lastIndexOf
(
".gz"
))
else
if
(
fileR2
.
endsWith
(
".gzip"
))
R2_name
=
fileR2
.
getName
.
substring
(
0
,
fileR2
.
getName
.
lastIndexOf
(
".gzip"
))
else
R2_name
=
fileR2
.
getName
R2_ext
=
R2_name
.
substring
(
R2_name
.
lastIndexOf
(
"."
),
R2_name
.
length
)
R2_name
=
R2_name
.
substring
(
0
,
R2_name
.
lastIndexOf
(
R2_ext
))
case
_
=>
(
R2_ext
,
R2_name
)
=
getNameAndExt
(
fileR2
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment