Skip to content

Commit 33b448f

Browse files
committed
Add 3tr_validate_filename.R
1 parent 3d22e90 commit 33b448f

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env Rscript
2+
# Author: Manuel Rueda ([email protected])
3+
# Date: Oct-17-2025
4+
#
5+
# Minimal filename validator for the 3TR clinical naming convention.
6+
# Usage: Rscript validate_filename_simple.R <filename>
7+
# Exits 0 if valid, 1 if invalid.
8+
9+
pattern <- paste0(
10+
"^[A-Z0-9]+_[A-Z0-9]+_[A-Za-z0-9-]+_",
11+
"(?:REDCAP-(?:RAW|LABEL|DICT)|CSV-RAW)_",
12+
"\\d{8}_",
13+
"(?:PASS|FAIL|PARTIAL|NA)-[A-Z0-9]+",
14+
"(?:_CONV-(?:OMOP|PXF|BFF)(?:-[0-9]+(?:[._][0-9]+)*)?)?",
15+
"\\.(?:csv|json)$"
16+
)
17+
18+
args <- commandArgs(trailingOnly = TRUE)
19+
20+
if (length(args) != 1) {
21+
cat("Usage: Rscript validate_filename_simple.R <filename>\n")
22+
quit(status = 1)
23+
}
24+
25+
name <- args[[1]]
26+
if (grepl(pattern, name, perl = TRUE)) {
27+
cat("OK", name, "\n")
28+
quit(status = 0)
29+
} else {
30+
cat("INVALID", name, "\n")
31+
quit(status = 1)
32+
}

docs/content/3tr-specific/pheno-clinical-data-nomenclature.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Use this to lint filenames. Adjust only if you extend vocabularies.
7878

7979
## CLI Linter Scripts
8080

81-
Use the accompanying [Python](https://github.com/CNAG-Biomedical-Informatics/omicsdm-documentation/blob/main/docs/content/3tr-specific/3tr_validate_filename.py) or [Perl](https://github.com/CNAG-Biomedical-Informatics/omicsdm-documentation/blob/main/docs/content/3tr-specific/3tr_validate_filename.pl) scripts to validate names locally.
81+
Use the accompanying [Python](https://github.com/CNAG-Biomedical-Informatics/omicsdm-documentation/blob/main/docs/content/3tr-specific/3tr_validate_filename.py), [Perl](https://github.com/CNAG-Biomedical-Informatics/omicsdm-documentation/blob/main/docs/content/3tr-specific/3tr_validate_filename.pl) or [R](https://github.com/CNAG-Biomedical-Informatics/omicsdm-documentation/blob/main/docs/content/3tr-specific/3tr_validate_filename.R) scripts to validate names locally.
8282

8383
**Example**
8484

@@ -88,4 +88,7 @@ python3 3tr_validate_filename.py 3TR_MS_Study123_REDCAP-RAW_20231204_NA-CNAG.csv
8888

8989
# Perl 5
9090
perl 3tr_validate_filename.pl 3TR_MS_Study123_REDCAP-RAW_20231204_NA-CNAG.csv
91+
92+
# R
93+
Rscript 3tr_validate_filename.R 3TR_MS_Study123_REDCAP-RAW_20231204_NA-CNAG.csv
9194
```

0 commit comments

Comments
 (0)