Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Implement feature to run pipelines on h5ad files with different suffixes
Browse files Browse the repository at this point in the history
Implement logic in channels.nf and files.nf
Add docs
  • Loading branch information
dweemx committed Sep 16, 2020
1 parent 5d74cb5 commit 44d9aef
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
19 changes: 19 additions & 0 deletions docs/pipelines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,25 @@ In the generated .config file, make sure the ``file_paths`` parameter is set wit

- The ``suffix`` parameter is used to infer the sample name from the file paths (it is removed from the input file path to derive a sample name).

In case, you want to use multiple .h5ad files that have different suffixes, use the following strategy to define the h5ad param::

[...]
data {
h5ad {
GROUP1 {
file_paths = "[path-to-group1-files]/*.SUFFIX1.h5ad"
suffix = ".SUFFIX1.h5ad"
}
GROUP2 {
file_paths = "[path-to-group1-files]/*.SUFFIX2.h5ad"
suffix = ".SUFFIX2.h5ad"
}
}
}
[...]

Note: GROUP1, GROUP2 are just example names here. They can be replaced by any value as long as they are alphanumeric (underscores are allowed).

----

Loom
Expand Down
16 changes: 13 additions & 3 deletions src/channels/channels.nf
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,20 @@ workflow getDataChannel {
}
}
if(params.data.containsKey("h5ad")) {
dataH5ad = params.data.h5ad
def filePaths = null
def suffix = null
if(!dataH5ad.containsKey("file_paths") && !dataH5ad.containsKey("suffix")) {
filePaths = dataH5ad.collect { k,v -> v["file_paths"] }
suffix = dataH5ad.collect { k,v -> v["suffix"] }
} else {
filePaths = dataH5ad.file_paths
suffix = dataH5ad.suffix
}
data = data.concat(
getFileChannel(
params.data.h5ad.file_paths,
params.data.h5ad.suffix
getFileChannel(
filePaths,
suffix
).map {
it -> tuple(it[0], it[1], "h5ad", "h5ad")
}
Expand Down
17 changes: 13 additions & 4 deletions src/utils/processes/files.nf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ def getBaseName(file) {

def extractSample(path, suffix) {
// Extract the sample name based on the given path and on the given suffix
suffix = suffix.replace(".","\\.")
pattern = /(.+)\/(.+)${suffix}/
(full, parentDir, id) = (path =~ pattern)[0]
return id
if(suffix instanceof String)
suffix = [suffix]
suffix = suffix.collect { it.replace(".","\\.") }
for (String sufx : suffix) {
pattern = /(.+)\/(.+)${sufx}/
res = (path =~ pattern)
if(res.size() == 0) continue
if(res.size() == 1) {
(full, parentDir, id) = res[0]
return id
}
}
throw new Exception("VSN ERROR: the suffix params couldn't match any of the file paths. Make sure the suffix param exist in the file paths.")
}

0 comments on commit 44d9aef

Please sign in to comment.