Skip to content

Commit

Permalink
update scripts and configs
Browse files Browse the repository at this point in the history
  • Loading branch information
rcannood committed Jul 17, 2024
1 parent 67b3e77 commit 14f1c9c
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 33 deletions.
3 changes: 3 additions & 0 deletions src/template/combine_columns/config.vsh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ arguments:
type: file
multiple: true
required: true
example: [ resources_test/file1.tsv, resources_test/file2.tsv ]

- name: "--output"
alternatives: [ "-o" ]
type: file
required: true
direction: output
example: output.tsv

resources:
- type: r_script
Expand Down
4 changes: 2 additions & 2 deletions src/template/combine_columns/script.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

## VIASH START
par <- list(
input = c("data/file1.tsv", "data/file2.tsv"),
output = "temp/foo.tsv"
input = c("resources_test/file1.tsv", "resources_test/file2.tsv"),
output = "temp/foo.tsv"
)
## VIASH END

Expand Down
2 changes: 1 addition & 1 deletion src/template/remove_comments/config.vsh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ arguments:
alternatives: [ "-i" ]
type: file
required: true
example: "file.tsv"
example: "resources_test/file1.tsv"
- name: "--output"
alternatives: [ "-o" ]
type: file
Expand Down
2 changes: 1 addition & 1 deletion src/template/remove_comments/script.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

grep -v '^#' "$par_input" > "$par_output"
grep -v '^#' "$par_input" > "$par_output"
15 changes: 12 additions & 3 deletions src/template/remove_comments/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

echo "Generate test tsv content"



echo ">>> Running tests with only comments"

cat > file1.tsv <<EOF
Expand All @@ -11,31 +13,38 @@ cat > file1.tsv <<EOF
# contains comments
EOF

./$meta_functionality_name -i file1.tsv -o output1.tsv
$meta_executable -i file1.tsv -o output1.tsv

[[ ! -f output1.tsv ]] && echo "It seems no output is generated" && exit 1
[[ ! `sed -n '$=' output1.tsv` == "" ]] && echo "All lines should be filtered out" && exit 1




echo ">>> Running tests with no comments"

cat > file2.tsv <<EOF
This file contains
no comments no
EOF

./$meta_functionality_name -i file2.tsv -o output2.tsv
$meta_executable -i file2.tsv -o output2.tsv

[[ ! -f output2.tsv ]] && echo "It seems no output is generated" && exit 1
[[ ! `sed -n '$=' output2.tsv` == 2 ]] && echo "No lines should be filtered out" && exit 1





echo ">>> Running tests mixed"

cat > file3.tsv <<EOF
# This file contains
no comments no
EOF

./$meta_functionality_name -i file3.tsv -o output3.tsv
$meta_executable -i file3.tsv -o output3.tsv

[[ ! -f output3.tsv ]] && echo "It seems no output is generated" && exit 1
[[ ! `sed -n '$=' output3.tsv` == 1 ]] && echo "No lines should be filtered out" && exit 1
Expand Down
4 changes: 4 additions & 0 deletions src/template/take_column/config.vsh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ arguments:
alternatives: [ "-i" ]
type: file
required: true
example: "resources_test/file1.tsv"

- name: "--output"
alternatives: [ "-o" ]
type: file
required: true
direction: output
example: path/to/output.tsv

- name: "--column"
type: integer
required: false
Expand Down
8 changes: 4 additions & 4 deletions src/template/take_column/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## VIASH START
par = {
"input": "data/file1.tsv",
"column": 2,
"output": "temp/foo"
"input": "resources_test/file1.tsv",
"column": 2,
"output": "temp/foo"
}
## VIASH END

Expand All @@ -15,4 +15,4 @@
tab_filt = tab.iloc[:, par["column"]-1]

# write to file
tab_filt.to_csv(par["output"], index=False)
tab_filt.to_csv(par["output"], index=False)
4 changes: 3 additions & 1 deletion src/template/workflow/config.vsh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ arguments:
type: file
required: true
description: Input TSV file
example: file1.tar.gz
example: resources_test/file1.tsv

- name: "--column"
type: integer
required: false
default: 2
description: The column index to extract from the TSV input file

- name: "--output"
alternatives: [ "-o" ]
type: file
Expand Down
61 changes: 40 additions & 21 deletions src/template/workflow/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,71 @@ workflow run_wf {
main:
output_ch = input_ch

| view{"input: $it"}

// Remove comments from each TSV input file
/*
Remove comments from each TSV input file
Example of an element in the channel at this stage:
[ "myid", [ input: "path/to/input.tsv", column: 3 ] ]
*/
| remove_comments.run(
fromState: [ input: "input" ],
toState: [ output: "output" ]
toState: [ data_comments_removed: "output" ]
)

| view{"after remove_comments: $it"}

// Extract a single column from each TSV
// The column to extract is specified in the sample sheet
/*
Extract a single column from each TSV
Example of an element in the channel at this stage:
[
"myid",
[
input: "path/to/input.tsv",
column: 3,
data_comments_removed: "work/path/to/output.tsv"
]
]
*/
| take_column.run(
fromState: [
input: "output",
input: "data_comments_removed",
column: "column"
],
toState: [ output: "output" ]
toState: [ data_one_column: "output" ]
)

| view{"after take_column: $it"}

// Combine the given tuples into one
| toSortedList

| map { state_list ->
def new_id = "combined"
def new_state = [
input: state_list.collect{ id, state -> state.output },
input: state_list.collect{ id, state -> state.data_one_column },
// store the original id in the _meta field
_meta: [ join_id: state_list[0][0] ]
]
[ new_id, new_state ]
}

| view{"before combine_columns: $it"}

// Concatenate TSVs into one
// and prep the output state.
/*
Combine the TSV files into one
Example of an element in the channel at this stage:
[
"combined",
[
input: [ "path/to/output1.tsv", "path/to/output2.tsv" ],
_meta: [ join_id: "myid" ]
]
]
*/
| combine_columns.run(
auto: [ publish: true ],
fromState: [ input: "input" ],
toState: ["output": "output"]
toState: [ output: "output" ]
)

| view{"after combine_columns: $it"}

// make sure the output state only contains
// a value called 'output' and '_meta'
| setState(["output", "_meta"])
Expand Down

0 comments on commit 14f1c9c

Please sign in to comment.