-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/dev'
- Loading branch information
Showing
22 changed files
with
259 additions
and
83 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env Rscript | ||
|
||
library(optparse) | ||
library(tidyr) | ||
library(vroom) | ||
|
||
option_list <- list( | ||
make_option(c("--input"), type = "character", help = "Input TSV file", metavar = "character"), | ||
make_option(c("--output"), type = "character", help = "Output CSV file", metavar = "character") | ||
) | ||
|
||
opt_parser <- OptionParser(option_list = option_list) | ||
opt <- parse_args(opt_parser) | ||
|
||
# Read CSV with vroom | ||
data <- vroom::vroom(opt$input, delim = "\t", col_types = c(.default = "c")) | ||
|
||
last_col <- names(data)[ncol(data)] | ||
|
||
# Convert from wide to long format | ||
long_data <- data %>% | ||
pivot_longer( | ||
cols = last_col, | ||
names_to = "Sample_ID", | ||
values_to = "Counts" | ||
) | ||
|
||
vroom_write(long_data, opt$output, delim = ",") | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env Rscript | ||
|
||
library(optparse) | ||
library(tidyr) | ||
library(vroom) | ||
library(dplyr) | ||
|
||
option_list <- list( | ||
make_option(c("--input"), type = "character", help = "Input CSV file in long format", metavar = "character"), | ||
make_option(c("--output"), type = "character", help = "Output CSV file in wide format", metavar = "character") | ||
) | ||
|
||
opt_parser <- OptionParser(option_list = option_list) | ||
opt <- parse_args(opt_parser) | ||
|
||
# Read CSV with vroom | ||
long_data <- vroom::vroom(opt$input, delim = ",", | ||
col_types = c( | ||
Counts = "d", | ||
.default = "c" | ||
)) | ||
|
||
# Transform to wide format | ||
wide_data <- long_data %>% | ||
pivot_wider( | ||
names_from = Sample_ID, | ||
values_from = Counts, | ||
values_fill = 0 | ||
) | ||
|
||
# Export wide format | ||
vroom_write(wide_data, opt$output, delim = "\t") |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
channels: | ||
- conda-forge | ||
dependencies: | ||
- conda-forge::r-optparse | ||
- conda-forge::r-tidyverse |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
process PIVOT_LONGER { | ||
tag"$meta.id" | ||
label 'process_single' | ||
|
||
conda "${moduleDir}/environment.yml" | ||
container "community.wave.seqera.io/library/r-optparse_r-tidyverse_r-vroom:3cbb224fea84a0e1" | ||
|
||
input: | ||
tuple val(meta), path(tsv) | ||
|
||
output: | ||
tuple val(meta), path("*_long.csv") , emit: csv | ||
path "versions.yml" , emit: versions | ||
|
||
script: | ||
""" | ||
pivot_longer.R \\ | ||
--input ${tsv} \\ | ||
--output ${meta.id}_long.csv | ||
cat <<-END_VERSIONS > versions.yml | ||
"${task.process}": | ||
r-base: \$(echo \$(R --version 2>&1) | sed 's/^.*R version //; s/ .*\$//') | ||
tidyr: \$(Rscript -e "library(tidyr); cat(as.character(packageVersion('tidyr')))") | ||
optparse: \$(Rscript -e "library(optparse); cat(as.character(packageVersion('optparse')))") | ||
END_VERSIONS | ||
""" | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
channels: | ||
- conda-forge | ||
dependencies: | ||
- conda-forge::r-optparse | ||
- conda-forge::r-tidyverse |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
process PIVOT_WIDER { | ||
tag"$meta.id" | ||
label 'process_high' | ||
|
||
conda "${moduleDir}/environment.yml" | ||
container "community.wave.seqera.io/library/r-optparse_r-tidyverse_r-vroom:3cbb224fea84a0e1" | ||
|
||
input: | ||
tuple val(meta), path(csvs) | ||
|
||
output: | ||
tuple val(meta), path("*joined_samples_mirtop.tsv") , emit: csv | ||
path "versions.yml" , emit: versions | ||
|
||
script: | ||
""" | ||
awk 'NR == 1 || FNR > 1' ${csvs.join(' ')} > final_long_results_temp.csv | ||
pivot_wider.R \\ | ||
--input final_long_results_temp.csv \\ | ||
--output ${meta.id}_concatenated_temp.csv | ||
sort -t\$'\t' -k1,1 ${meta.id}_concatenated_temp.csv > joined_samples_mirtop.tsv | ||
cat <<-END_VERSIONS > versions.yml | ||
"${task.process}": | ||
r-base: \$(echo \$(R --version 2>&1) | sed 's/^.*R version //; s/ .*\$//') | ||
tidyr: \$(Rscript -e "library(tidyr); cat(as.character(packageVersion('tidyr')))") | ||
dplyr: \$(Rscript -e "library(dplyr); cat(as.character(packageVersion('dplyr')))") | ||
optparse: \$(Rscript -e "library(optparse); cat(as.character(packageVersion('optparse')))") | ||
vroom: \$(Rscript -e "library(vroom); cat(as.character(packageVersion('vroom')))") | ||
END_VERSIONS | ||
""" | ||
|
||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.