Last active
April 19, 2022 08:34
-
-
Save elowy01/c873f44835cd34589f91cc09f3e9243c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Now, create a channel from paths in a file | |
Where params.list is: | |
/home/ec2-user/lib/bioinformatics_pipelines/file1.txt | |
/home/ec2-user/lib/bioinformatics_pipelines/file2.txt | |
*/ | |
Channel.fromPath(params.list) | |
.splitText() | |
.set { value_list } | |
process test_ch_fromfile { | |
input: | |
path(i) from value_list | |
""" | |
cat $i | |
""" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
ach = Channel.fromPath(params.ifile).splitText() | |
ach.view() // output with newlines: | |
/home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00001.chr20.bam | |
/home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00001.chr21.bam | |
/home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00002.chr20.bam | |
/home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00002.chr21.bam | |
// | |
ach = Channel.fromPath(params.ifile).splitText().map{it -> it.trim()} | |
ach.view() | |
Output: | |
/home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00001.chr20.bam | |
/home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00001.chr21.bam | |
/home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00002.chr20.bam | |
/home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00002.chr21.bam | |
// | |
If we have in a file the following content: | |
SEQ_ENS_00001.chr20.bam | |
SEQ_ENS_00001.chr21.bam | |
SEQ_ENS_00002.chr20.bam | |
SEQ_ENS_00002.chr21.bam | |
# Then, to extract the first bit of the file we do: | |
ach = Channel.fromPath(params.ifile).splitText().map({line -> line.tokenize('.')[0]}) | |
ach.view() | |
# We get: | |
SEQ_ENS_00001 | |
SEQ_ENS_00001 | |
SEQ_ENS_00002 | |
SEQ_ENS_00002 | |
// | |
# But if we do: | |
ach = Channel.fromPath(params.ifile).splitText().map({line -> [line.tokenize('.')[0], file(line.trim())]}) | |
ach.view() | |
[SEQ_ENS_00001, /home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/SEQ_ENS_00001.chr20.bam] | |
[SEQ_ENS_00001, /home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/SEQ_ENS_00001.chr21.bam] | |
[SEQ_ENS_00002, /home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/SEQ_ENS_00002.chr20.bam] | |
[SEQ_ENS_00002, /home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/SEQ_ENS_00002.chr21.bam] | |
# Now , let's say that we have a similar file but absolute paths to the files. For example: | |
/home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00001.chr20.bam | |
/home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00001.chr21.bam | |
/home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00002.chr20.bam | |
/home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00002.chr21.bam | |
If we have: | |
ach = Channel.fromPath(params.ifile).splitText().map({line -> [file(line).baseName.tokenize('.')[0], file(line.trim())]}) | |
ach.view() | |
Then, we get: | |
[SEQ_ENS_00001, /home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00001.chr20.bam] | |
[SEQ_ENS_00001, /home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00001.chr21.bam] | |
[SEQ_ENS_00002, /home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00002.chr20.bam] | |
[SEQ_ENS_00002, /home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00002.chr21.bam] | |
# And if we use groupTuple() | |
ach = Channel.fromPath(params.ifile).splitText().map({line -> [file(line).baseName.tokenize('.')[0], file(line.trim())]}).groupTuple() | |
ach.view() | |
[SEQ_ENS_00001, [/home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00001.chr20.bam, /home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00001.chr21.bam]] | |
[SEQ_ENS_00002, [/home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00002.chr20.bam, /home/ec2-user/ENSPYRE/PIPELINE_RUNS/MS_22Mar08/MS_22Mar08_sample1/DEBUG/SIMULATED/out/bam/SEQ_ENS_00002.chr21.bam]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### | |
list.txt contains: | |
a | |
n | |
c | |
v | |
g | |
### | |
params.list = 'list.txt' | |
Channel.fromPath(params.list) | |
.splitText() | |
.set { value_list } | |
process test_ch_fromfile { | |
input: | |
val i from value_list | |
""" | |
echo $i | |
""" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment