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
7b260498
Commit
7b260498
authored
10 years ago
by
bow
Browse files
Options
Downloads
Patches
Plain Diff
Add relative symlink option to Ln wrapper
parent
1a6df3ca
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
biopet-framework/src/main/scala/nl/lumc/sasc/biopet/function/Ln.scala
+58
-4
58 additions, 4 deletions
...work/src/main/scala/nl/lumc/sasc/biopet/function/Ln.scala
with
58 additions
and
4 deletions
biopet-framework/src/main/scala/nl/lumc/sasc/biopet/function/Ln.scala
+
58
−
4
View file @
7b260498
package
nl.lumc.sasc.biopet.function
import
nl.lumc.sasc.biopet.core.config.Configurable
import
org.broadinstitute.gatk.queue.function.InProcessFunction
import
org.broadinstitute.gatk.utils.commandline.
{
Input
,
Output
}
import
java.io.File
import
scala.sys.process.Process
import
org.apache.commons.io.FilenameUtils
;
import
org.broadinstitute.gatk.queue.function.InProcessFunction
import
org.broadinstitute.gatk.utils.commandline.
{
Input
,
Output
}
import
nl.lumc.sasc.biopet.core.config.Configurable
class
Ln
(
val
root
:
Configurable
)
extends
InProcessFunction
with
Configurable
{
this
.
analysisName
=
getClass
.
getSimpleName
...
...
@@ -15,8 +16,61 @@ class Ln(val root: Configurable) extends InProcessFunction with Configurable {
@Output
(
doc
=
"Link destination"
)
var
out
:
File
=
_
var
relative
:
Boolean
=
true
private
lazy
val
inCanonical
:
String
=
{
// need to remove "/~" to correctly expand path with tilde
in
.
getCanonicalPath
().
replace
(
"/~"
,
""
)
}
private
lazy
val
outCanonical
:
String
=
{
out
.
getCanonicalPath
().
replace
(
"/~"
,
""
)
}
private
lazy
val
inToks
:
Array
[
String
]
=
{
inCanonical
.
split
(
File
.
separator
)
}
private
lazy
val
outToks
:
Array
[
String
]
=
{
outCanonical
.
split
(
File
.
separator
)
}
private
lazy
val
commonPrefixLength
:
Int
=
{
val
maxLength
=
scala
.
math
.
min
(
inToks
.
length
,
outToks
.
length
)
var
i
:
Int
=
0
;
while
(
i
<
maxLength
&&
inToks
(
i
)
==
outToks
(
i
))
i
+=
1
;
i
}
private
lazy
val
inUnique
:
String
=
{
inToks
.
slice
(
commonPrefixLength
,
inToks
.
length
).
mkString
(
File
.
separator
)
}
private
lazy
val
outUnique
:
String
=
{
outToks
.
slice
(
commonPrefixLength
,
outToks
.
length
).
mkString
(
File
.
separator
)
}
private
lazy
val
inRelative
:
String
=
{
// calculate 'distance' from output directory to input
// which is the number of directory walks required to get to the inUnique directory from outDir
val
outDir
=
FilenameUtils
.
getFullPathNoEndSeparator
(
outUnique
)
val
dist
:
Int
=
scala
.
math
.
max
(
0
,
outDir
.
split
(
File
.
separator
).
length
-
1
)
val
result
=
if
(
dist
>
0
)
((
".."
+
File
.
separator
)
*
dist
)
+
File
.
separator
+
inUnique
else
inUnique
result
}
override
def
run
{
val
cmd
=
"ln -s "
+
in
+
" "
+
out
val
cmd
=
if
(
relative
)
{
// workaround until we have `ln` that works with relative path (i.e. `ln -r`)
"ln -s "
+
inRelative
+
" "
+
outCanonical
}
else
{
"ln -s "
+
inCanonical
+
" "
+
outCanonical
}
val
process
=
Process
(
cmd
).
run
System
.
out
.
println
(
"cmd: '"
+
cmd
+
"', exitcode: "
+
process
.
exitValue
)
}
...
...
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