| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # A software toolkit for the interconversion of standard data models for phenotypic data | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # This file is part of Convert::Pheno | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # Last Modified: Apr/09/2024 | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # $VERSION taken from Convert::Pheno | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # Copyright (C) 2022-2026 Manuel Rueda - CNAG (manuel.rueda@cnag.eu) | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # License: Artistic License 2.0 | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | package main; | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 59 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 59 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 59 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 59 | ▶ | use feature qw(say); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 59 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 59 | ▶ | use Sys::Hostname; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 59 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 59 | ▶ | use File::Spec::Functions qw(catdir catfile); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 59 | ▶ | use File::ShareDir::ProjectDistDir qw(dist_dir); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 59 | ▶ | use FindBin qw($Bin); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 59 | ▶ | use lib "$Bin/../lib"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 59 | ▶ | use Term::ANSIColor qw(:constants); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 59 | ▶ | use Convert::Pheno; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 59 | ▶ | use Convert::Pheno::CLI::Args qw(build_cli_request); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 59 | ▶ | use Convert::Pheno::Execution::Files qw(execute_file_conversion); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 59 | ▶ | use Convert::Pheno::IO::Atomic qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | write_atomically | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 59 | ); | |||||||||||||||||||||||||||||||||||||||||
| 35 | 59 | ▶ | use Convert::Pheno::Sink::FileSet qw(resolve_entity_output_file); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 59 | $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | # Error decoration belongs to the CLI process, not to module consumers. | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | $SIG{__WARN__} = sub { warn "Warn: ", @_ }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 59 | ▶ | $SIG{__DIE__} = sub { die "Error: ", @_ }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | # Defining a few variables | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 59 | my $out_dir = '.'; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 59 | my $share_dir = dist_dir('Convert-Pheno'); | |||||||||||||||||||||||||||||||||||||||||
| 46 | 59 | my $schema_file = catfile( $share_dir, 'schema', 'mapping-v2.json' ); | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | sub print_help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_help: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | my $out = shift || *STDOUT; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || *STDOUT
MC/DC0%0/2
shift() || *STDOUT
shift()
*STDOUT
Truth table33%1/3
A || B
A= shift()B= *STDOUT
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | print {$out} <<'EOF'; | |||||||||||||||||||||||||||||||||||||||||
| 51 | Usage: | ||||||||||||||||||||||||||||||||||||||||||
| 52 | convert-pheno -i <input-type> <infile> -o <output-type> <outfile> [options] | ||||||||||||||||||||||||||||||||||||||||||
| 53 | convert-pheno -ipxf <infile> -obff <outfile> [options] | ||||||||||||||||||||||||||||||||||||||||||
| 54 | convert-pheno -ipxf <infile> -obff --entities <list> --out-dir <dir> [options] | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | Common input flags: | ||||||||||||||||||||||||||||||||||||||||||
| 57 | -i <type> <file> Generic input form | ||||||||||||||||||||||||||||||||||||||||||
| 58 | (pxf|bff|cbioportal|omop|redcap|cdisc-odm|dataset-json|dataset-xml|fhir|i2b2|pcornet|sentinel|csv|openehr) | ||||||||||||||||||||||||||||||||||||||||||
| 59 | -ibff <file> Beacon v2 Models ('individuals' JSON|YAML) | ||||||||||||||||||||||||||||||||||||||||||
| 60 | -ipxf <file> Phenopackets v2 (JSON|YAML) | ||||||||||||||||||||||||||||||||||||||||||
| 61 | -icbioportal <path> | ||||||||||||||||||||||||||||||||||||||||||
| 62 | Experimental cBioPortal clinical study directory or ZIP | ||||||||||||||||||||||||||||||||||||||||||
| 63 | (input-only; BFF, PXF, or OMOP output) | ||||||||||||||||||||||||||||||||||||||||||
| 64 | -iomop <inputs...> | ||||||||||||||||||||||||||||||||||||||||||
| 65 | OMOP-CDM CSV/TSV files, one directory or ZIP package, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | or a PostgreSQL dump | ||||||||||||||||||||||||||||||||||||||||||
| 67 | -iopenehr <files...> | ||||||||||||||||||||||||||||||||||||||||||
| 68 | Experimental openEHR canonical JSON/YAML compositions | ||||||||||||||||||||||||||||||||||||||||||
| 69 | (currently EHRbase-oriented; input-only; BFF/PXF output) | ||||||||||||||||||||||||||||||||||||||||||
| 70 | -iredcap <file> REDCap export CSV | ||||||||||||||||||||||||||||||||||||||||||
| 71 | -icdisc-odm <file> | ||||||||||||||||||||||||||||||||||||||||||
| 72 | CDISC-ODM Snapshot XML (1.3.1, 1.3.2, or 2.0) | ||||||||||||||||||||||||||||||||||||||||||
| 73 | -idataset-json <files...> | ||||||||||||||||||||||||||||||||||||||||||
| 74 | Experimental CDISC Dataset-JSON v1.1 SDTM datasets | ||||||||||||||||||||||||||||||||||||||||||
| 75 | (input-only; loaded in memory; BFF, PXF, or OMOP output) | ||||||||||||||||||||||||||||||||||||||||||
| 76 | -idataset-xml <files...> | ||||||||||||||||||||||||||||||||||||||||||
| 77 | Experimental CDISC Dataset-XML v1.0 SDTM datasets | ||||||||||||||||||||||||||||||||||||||||||
| 78 | (requires --define-xml; loaded in memory) | ||||||||||||||||||||||||||||||||||||||||||
| 79 | -ifhir <files...> Experimental FHIR R4 JSON Bundles, including mCODE | ||||||||||||||||||||||||||||||||||||||||||
| 80 | (input-only; loaded in memory; BFF, PXF, or OMOP output) | ||||||||||||||||||||||||||||||||||||||||||
| 81 | -ii2b2 <paths...> Experimental i2b2 table exports | ||||||||||||||||||||||||||||||||||||||||||
| 82 | -ipcornet <paths...> | ||||||||||||||||||||||||||||||||||||||||||
| 83 | Experimental PCORnet CDM table exports | ||||||||||||||||||||||||||||||||||||||||||
| 84 | -isentinel <paths...> | ||||||||||||||||||||||||||||||||||||||||||
| 85 | Experimental Sentinel CDM table exports | ||||||||||||||||||||||||||||||||||||||||||
| 86 | Each accepts delimited files, one directory, or one ZIP; | ||||||||||||||||||||||||||||||||||||||||||
| 87 | input-only and loaded in memory for BFF, PXF, or OMOP output | ||||||||||||||||||||||||||||||||||||||||||
| 88 | -icsv <file> Raw CSV | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | Common output flags: | ||||||||||||||||||||||||||||||||||||||||||
| 91 | -o <type> <file> Generic output form (bff|pxf|omop|csv|jsonf|jsonld) | ||||||||||||||||||||||||||||||||||||||||||
| 92 | -obff [file] Beacon-oriented JSON/YAML output | ||||||||||||||||||||||||||||||||||||||||||
| 93 | Use -obff FILE for individuals-only BFF output | ||||||||||||||||||||||||||||||||||||||||||
| 94 | Use -obff with --entities --out-dir for entity-aware BFF | ||||||||||||||||||||||||||||||||||||||||||
| 95 | -opxf <file> Phenopackets v2 output | ||||||||||||||||||||||||||||||||||||||||||
| 96 | -oomop OMOP-CDM CSV table output (use with --out-dir) | ||||||||||||||||||||||||||||||||||||||||||
| 97 | -ocsv <file> Flattened CSV (with -ibff or -ipxf) | ||||||||||||||||||||||||||||||||||||||||||
| 98 | -ojsonf <file> Flattened 1D JSON/YAML (with -ibff or -ipxf) | ||||||||||||||||||||||||||||||||||||||||||
| 99 | -ojsonld <file> JSON-LD / YAML-LD (with -ibff or -ipxf) | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | Output behavior: | ||||||||||||||||||||||||||||||||||||||||||
| 102 | --out-dir <dir> Output directory (required for entity-aware BFF mode) | ||||||||||||||||||||||||||||||||||||||||||
| 103 | --entities <list> Beacon entities for BFF output [individuals] | ||||||||||||||||||||||||||||||||||||||||||
| 104 | Supported: individuals, biosamples, datasets, cohorts | ||||||||||||||||||||||||||||||||||||||||||
| 105 | biosamples are emitted from -ipxf, cBioPortal samples, | ||||||||||||||||||||||||||||||||||||||||||
| 106 | FHIR Specimen, OMOP SPECIMEN, or mapping rules | ||||||||||||||||||||||||||||||||||||||||||
| 107 | datasets and cohorts are synthesized from individuals | ||||||||||||||||||||||||||||||||||||||||||
| 108 | Use with -obff and --out-dir | ||||||||||||||||||||||||||||||||||||||||||
| 109 | --out-name k=file Override one multi-file output name; repeat as needed | ||||||||||||||||||||||||||||||||||||||||||
| 110 | Use entity keys for BFF and table keys for OMOP | ||||||||||||||||||||||||||||||||||||||||||
| 111 | -O Overwrite output file(s) | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | Mapping and search: | ||||||||||||||||||||||||||||||||||||||||||
| 114 | --mapping-file <file> Mapping V2 YAML or JSON file targeting | ||||||||||||||||||||||||||||||||||||||||||
| 115 | Beacon schema 2.0.0, or optional terminology | ||||||||||||||||||||||||||||||||||||||||||
| 116 | correspondences for BFF-to-OMOP CDM 5.4 | ||||||||||||||||||||||||||||||||||||||||||
| 117 | Optional for cBioPortal clinical packages | ||||||||||||||||||||||||||||||||||||||||||
| 118 | and CDISC Dataset terminology enrichment | ||||||||||||||||||||||||||||||||||||||||||
| 119 | Optional compact dataset/cohort metadata for | ||||||||||||||||||||||||||||||||||||||||||
| 120 | built-in BFF input routes | ||||||||||||||||||||||||||||||||||||||||||
| 121 | ODM uses source.profile redcap for REDCap | ||||||||||||||||||||||||||||||||||||||||||
| 122 | exports, or cdisc-odm for embedded metadata | ||||||||||||||||||||||||||||||||||||||||||
| 123 | --redcap-dictionary|-rcd <file> REDCap data dictionary CSV file; required | ||||||||||||||||||||||||||||||||||||||||||
| 124 | for REDCap CSV and REDCap-origin ODM only | ||||||||||||||||||||||||||||||||||||||||||
| 125 | --define-xml <file> Define-XML v2.0/v2.1 metadata required by | ||||||||||||||||||||||||||||||||||||||||||
| 126 | Dataset-XML and optional for Dataset-JSON | ||||||||||||||||||||||||||||||||||||||||||
| 127 | --schema-file <file> Alternative JSON Schema for mapping files | ||||||||||||||||||||||||||||||||||||||||||
| 128 | --self-validate-schema|-svs Self-validate the mapping JSON Schema | ||||||||||||||||||||||||||||||||||||||||||
| 129 | (mainly for author/development checks) | ||||||||||||||||||||||||||||||||||||||||||
| 130 | --search <type> Ontology label search mode [exact|mixed|fuzzy] | ||||||||||||||||||||||||||||||||||||||||||
| 131 | Default: exact | ||||||||||||||||||||||||||||||||||||||||||
| 132 | --text-similarity-method <m> Token similarity for mixed/fuzzy search | ||||||||||||||||||||||||||||||||||||||||||
| 133 | [cosine|dice], default: cosine | ||||||||||||||||||||||||||||||||||||||||||
| 134 | --min-text-similarity-score <s> Minimum score for mixed/fuzzy search | ||||||||||||||||||||||||||||||||||||||||||
| 135 | Default: 0.8 | ||||||||||||||||||||||||||||||||||||||||||
| 136 | --levenshtein-weight <w> Levenshtein weight in fuzzy composite score | ||||||||||||||||||||||||||||||||||||||||||
| 137 | Default: 0.1, range: 0-1 | ||||||||||||||||||||||||||||||||||||||||||
| 138 | --term-audit <file> Write terminology decisions and candidate | ||||||||||||||||||||||||||||||||||||||||||
| 139 | scores [.tsv|.tsv.gz|.xlsx] | ||||||||||||||||||||||||||||||||||||||||||
| 140 | --source-info|--no-source-info Preserve or omit raw source provenance in BFF | ||||||||||||||||||||||||||||||||||||||||||
| 141 | output [source-info] | ||||||||||||||||||||||||||||||||||||||||||
| 142 | --include-dataset-id Copy beacon.datasets.defaults.id to top-level | ||||||||||||||||||||||||||||||||||||||||||
| 143 | datasetId in individuals and biosamples | ||||||||||||||||||||||||||||||||||||||||||
| 144 | (backend compatibility extension; off by default) | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | OMOP: | ||||||||||||||||||||||||||||||||||||||||||
| 147 | --ohdsi-db Enable Athena-OHDSI lookup | ||||||||||||||||||||||||||||||||||||||||||
| 148 | --path-to-ohdsi-db <dir> Directory containing <ohdsi.db> | ||||||||||||||||||||||||||||||||||||||||||
| 149 | --omop-tables <list> Restrict OMOP tables | ||||||||||||||||||||||||||||||||||||||||||
| 150 | --exposures-file <file> OMOP concept_id list treated as exposures | ||||||||||||||||||||||||||||||||||||||||||
| 151 | --stream|--no-stream Incremental OMOP processing with single-file | ||||||||||||||||||||||||||||||||||||||||||
| 152 | line-delimited JSON output [no-stream] | ||||||||||||||||||||||||||||||||||||||||||
| 153 | Supports individuals-only <-obff FILE>, or | ||||||||||||||||||||||||||||||||||||||||||
| 154 | entity-aware <-obff --entities individuals | ||||||||||||||||||||||||||||||||||||||||||
| 155 | biosamples --out-dir DIR> | ||||||||||||||||||||||||||||||||||||||||||
| 156 | --sql2csv Print SQL tables instead of converting | ||||||||||||||||||||||||||||||||||||||||||
| 157 | --max-lines-sql <n> OMOP processing cap: rows per SQL table and | ||||||||||||||||||||||||||||||||||||||||||
| 158 | individuals in non-stream mode [500] | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | Other useful options: | ||||||||||||||||||||||||||||||||||||||||||
| 161 | --default-vital-status <s> Fallback PXF subject vitalStatus | ||||||||||||||||||||||||||||||||||||||||||
| 162 | [ALIVE|DECEASED|UNKNOWN_STATUS] | ||||||||||||||||||||||||||||||||||||||||||
| 163 | Used only with PXF output when no source | ||||||||||||||||||||||||||||||||||||||||||
| 164 | vitalStatus is available | ||||||||||||||||||||||||||||||||||||||||||
| 165 | --separator|--sep <char> Delimiter for CSV input [; for .csv] | ||||||||||||||||||||||||||||||||||||||||||
| 166 | --username|-u <name> Override username stored in metadata | ||||||||||||||||||||||||||||||||||||||||||
| 167 | --test Skip time-varying metadata for stable tests | ||||||||||||||||||||||||||||||||||||||||||
| 168 | --log [file] Write resolved request JSON log | ||||||||||||||||||||||||||||||||||||||||||
| 169 | [convert-pheno-log.json] | ||||||||||||||||||||||||||||||||||||||||||
| 170 | --color|--no-color Enable or disable colored terminal output | ||||||||||||||||||||||||||||||||||||||||||
| 171 | [color] | ||||||||||||||||||||||||||||||||||||||||||
| 172 | --debug <level> Print internal request/debug data | ||||||||||||||||||||||||||||||||||||||||||
| 173 | (level >= 2 also prints DB lookup summary) | ||||||||||||||||||||||||||||||||||||||||||
| 174 | --verbose|-v Print progress information | ||||||||||||||||||||||||||||||||||||||||||
| 175 | --version|-V | ||||||||||||||||||||||||||||||||||||||||||
| 176 | --help | ||||||||||||||||||||||||||||||||||||||||||
| 177 | --man | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | Examples: | ||||||||||||||||||||||||||||||||||||||||||
| 180 | convert-pheno -i pxf pxf.json -o bff individuals.json | ||||||||||||||||||||||||||||||||||||||||||
| 181 | convert-pheno -ipxf pxf.json -obff individuals.json | ||||||||||||||||||||||||||||||||||||||||||
| 182 | convert-pheno -ipxf pxf.json -obff --entities biosamples --out-dir out/ | ||||||||||||||||||||||||||||||||||||||||||
| 183 | convert-pheno -ipxf pxf.json -obff --entities individuals biosamples --out-dir out/ --out-name biosamples=samples.json | ||||||||||||||||||||||||||||||||||||||||||
| 184 | convert-pheno -ipxf pxf.json -obff --entities individuals datasets cohorts --out-dir out/ | ||||||||||||||||||||||||||||||||||||||||||
| 185 | convert-pheno -icbioportal study/ -obff --entities individuals biosamples datasets cohorts --out-dir out/ | ||||||||||||||||||||||||||||||||||||||||||
| 186 | convert-pheno -i cbioportal study.zip -o pxf phenopackets.json | ||||||||||||||||||||||||||||||||||||||||||
| 187 | convert-pheno -icsv data.csv --mapping-file mapping.yaml -obff --entities individuals datasets cohorts --out-dir out/ | ||||||||||||||||||||||||||||||||||||||||||
| 188 | convert-pheno -iredcap data.csv -rcd dictionary.csv --mapping-file mapping.yaml -obff --entities individuals biosamples --out-dir out/ | ||||||||||||||||||||||||||||||||||||||||||
| 189 | convert-pheno -icdisc-odm study.xml --mapping-file odm-mapping.yaml -obff individuals.json | ||||||||||||||||||||||||||||||||||||||||||
| 190 | convert-pheno -icdisc-odm redcap.xml -rcd dictionary.csv --mapping-file redcap-mapping.yaml -obff individuals.json | ||||||||||||||||||||||||||||||||||||||||||
| 191 | convert-pheno -idataset-json dm.json mh.json lb.json --mapping-file sdtm-terms.yaml -obff individuals.json | ||||||||||||||||||||||||||||||||||||||||||
| 192 | convert-pheno -i dataset-json dm.json mh.json lb.json -o pxf phenopackets.json | ||||||||||||||||||||||||||||||||||||||||||
| 193 | convert-pheno -idataset-json dm.json mh.json lb.json -oomop --out-dir omop_out/ --ohdsi-db | ||||||||||||||||||||||||||||||||||||||||||
| 194 | convert-pheno -idataset-xml dm.xml mh.xml lb.xml --define-xml define.xml -obff individuals.json | ||||||||||||||||||||||||||||||||||||||||||
| 195 | convert-pheno -i dataset-xml dm.xml mh.xml lb.xml --define-xml define.xml -o pxf phenopackets.json | ||||||||||||||||||||||||||||||||||||||||||
| 196 | convert-pheno -ifhir bundle.json -obff individuals.json | ||||||||||||||||||||||||||||||||||||||||||
| 197 | convert-pheno -ifhir bundle.json -obff --entities individuals biosamples --out-dir out/ | ||||||||||||||||||||||||||||||||||||||||||
| 198 | convert-pheno -i fhir bundle.json -o pxf phenopacket.json | ||||||||||||||||||||||||||||||||||||||||||
| 199 | convert-pheno -ii2b2 i2b2-export/ -obff individuals.json | ||||||||||||||||||||||||||||||||||||||||||
| 200 | convert-pheno -ipcornet pcornet-tables.zip -opxf phenopackets.json | ||||||||||||||||||||||||||||||||||||||||||
| 201 | convert-pheno -i sentinel sentinel-export/ -o omop --out-dir omop_out/ --ohdsi-db | ||||||||||||||||||||||||||||||||||||||||||
| 202 | convert-pheno -iomop PERSON.csv CONCEPT.csv SPECIMEN.csv -obff --entities biosamples --out-dir out/ | ||||||||||||||||||||||||||||||||||||||||||
| 203 | convert-pheno -ibff individuals.json -oomop --out-dir omop_out/ --ohdsi-db | ||||||||||||||||||||||||||||||||||||||||||
| 204 | convert-pheno -ibff individuals.json -oomop --out-dir omop_out/ --out-name PERSON=patients.csv --ohdsi-db | ||||||||||||||||||||||||||||||||||||||||||
| 205 | convert-pheno -iomop dump.sql.gz -opxf phenopackets.json.gz --default-vital-status UNKNOWN_STATUS --ohdsi-db | ||||||||||||||||||||||||||||||||||||||||||
| 206 | convert-pheno -iomop dump.sql.gz -obff individuals.json.gz --stream --ohdsi-db | ||||||||||||||||||||||||||||||||||||||||||
| 207 | convert-pheno -iomop dump.sql.gz -obff --stream --entities individuals biosamples --out-dir out/ --ohdsi-db | ||||||||||||||||||||||||||||||||||||||||||
| 208 | convert-pheno -i openehr patient-set.json -o bff individual.json | ||||||||||||||||||||||||||||||||||||||||||
| 209 | convert-pheno -i openehr patient-set.json -o pxf phenopacket.json | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | BFF output modes: | ||||||||||||||||||||||||||||||||||||||||||
| 212 | -obff FILE keeps the individuals-only BFF behavior. | ||||||||||||||||||||||||||||||||||||||||||
| 213 | -obff --entities ... --out-dir DIR writes one file per requested BFF entity. | ||||||||||||||||||||||||||||||||||||||||||
| 214 | -oomop --out-dir DIR writes one file per emitted OMOP table. | ||||||||||||||||||||||||||||||||||||||||||
| 215 | If a PXF input also contains biosamples, convert-pheno warns and preserves them | ||||||||||||||||||||||||||||||||||||||||||
| 216 | under info.phenopacket.biosamples unless --entities is used. | ||||||||||||||||||||||||||||||||||||||||||
| 217 | PXF output still defaults subject.vitalStatus to ALIVE unless a preserved | ||||||||||||||||||||||||||||||||||||||||||
| 218 | source vitalStatus or --default-vital-status is available. | ||||||||||||||||||||||||||||||||||||||||||
| 219 | openEHR input support is currently experimental and limited to BFF or PXF output. | ||||||||||||||||||||||||||||||||||||||||||
| 220 | Dataset-JSON input support is experimental, SDTM-oriented, and processed in memory. | ||||||||||||||||||||||||||||||||||||||||||
| 221 | Dataset-XML input support is experimental, SDTM-oriented, requires Define-XML, | ||||||||||||||||||||||||||||||||||||||||||
| 222 | and is processed in memory. | ||||||||||||||||||||||||||||||||||||||||||
| 223 | FHIR input support is experimental, targets R4 JSON Bundles including mCODE, | ||||||||||||||||||||||||||||||||||||||||||
| 224 | and is processed in memory. | ||||||||||||||||||||||||||||||||||||||||||
| 225 | i2b2, PCORnet CDM, and Sentinel CDM input support is experimental, reads | ||||||||||||||||||||||||||||||||||||||||||
| 226 | exported tables rather than live databases, and is processed in memory. | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | Docs: | ||||||||||||||||||||||||||||||||||||||||||
| 229 | Site: https://cnag-biomedical-informatics.github.io/convert-pheno | ||||||||||||||||||||||||||||||||||||||||||
| 230 | CLI: https://cnag-biomedical-informatics.github.io/convert-pheno/use-as-a-command-line-interface/ | ||||||||||||||||||||||||||||||||||||||||||
| 231 | Install: | ||||||||||||||||||||||||||||||||||||||||||
| 232 | https://cnag-biomedical-informatics.github.io/convert-pheno/download-and-installation/ | ||||||||||||||||||||||||||||||||||||||||||
| 233 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 6 | ▶ | sub print_usage_summary { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_usage_summary: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 6 | ▶ | my $out = shift || *STDERR; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || *STDERR
MC/DC0%0/2
shift() || *STDERR
shift()
*STDERR
Truth table33%1/3
A || B
A= shift()B= *STDERR
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 6 | print {$out} <<'EOF'; | |||||||||||||||||||||||||||||||||||||||||
| 239 | Usage: | ||||||||||||||||||||||||||||||||||||||||||
| 240 | convert-pheno -i <input-type> <infile> -o <output-type> <outfile> [options] | ||||||||||||||||||||||||||||||||||||||||||
| 241 | convert-pheno -ipxf <infile> -obff <outfile> [options] | ||||||||||||||||||||||||||||||||||||||||||
| 242 | convert-pheno -ipxf <infile> -obff --entities <list> --out-dir <dir> [options] | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | Run `convert-pheno --help` for full usage | ||||||||||||||||||||||||||||||||||||||||||
| 245 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 6 | ▶ | sub usage_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage_error: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 6 | my ($message) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 250 | 6 | print STDERR "Error: $message"; | |||||||||||||||||||||||||||||||||||||||||
| 251 | 6 | ▶ | print STDERR "\n" unless $message =~ /\n\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 6 | print STDERR "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 6 | print_usage_summary(*STDERR); | |||||||||||||||||||||||||||||||||||||||||
| 254 | 6 | exit 1; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | sub print_man { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_man: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | print <<'EOF'; | |||||||||||||||||||||||||||||||||||||||||
| 259 | Full CLI documentation now lives in Markdown instead of POD. | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | Documentation site: | ||||||||||||||||||||||||||||||||||||||||||
| 262 | https://cnag-biomedical-informatics.github.io/convert-pheno | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | CLI guide: | ||||||||||||||||||||||||||||||||||||||||||
| 265 | https://cnag-biomedical-informatics.github.io/convert-pheno/use-as-a-command-line-interface/ | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | Installation: | ||||||||||||||||||||||||||||||||||||||||||
| 268 | https://cnag-biomedical-informatics.github.io/convert-pheno/download-and-installation/ | ||||||||||||||||||||||||||||||||||||||||||
| 269 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 59 | my $cli = build_cli_request( | |||||||||||||||||||||||||||||||||||||||||
| 273 | argv => \@ARGV, | ||||||||||||||||||||||||||||||||||||||||||
| 274 | usage_error => \&usage_error, | ||||||||||||||||||||||||||||||||||||||||||
| 275 | schema_file => $schema_file, | ||||||||||||||||||||||||||||||||||||||||||
| 276 | out_dir => $out_dir, | ||||||||||||||||||||||||||||||||||||||||||
| 277 | color => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 278 | stream => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 279 | ohdsi_db => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 280 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 53 | ▶ | if ( $cli->{action} eq 'help' ) { print_help(); exit 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | if ( $cli->{action} eq 'man' ) { print_man(); exit 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | if ( $cli->{action} eq 'version' ) { say "$0 Version $VERSION"; exit 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 52 | my $data = $cli->{data}; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 52 | my $out_file = $cli->{out_file}; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 52 | my $log_file = $cli->{log_file}; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 52 | my $overwrite = $cli->{overwrite}; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 52 | my $verbose = $cli->{verbose}; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 52 | my $stream = $cli->{stream}; | |||||||||||||||||||||||||||||||||||||||||
| 292 | 52 | my $color = $cli->{color}; | |||||||||||||||||||||||||||||||||||||||||
| 293 | 52 | my $log = $data->{log}; | |||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 52 | ▶ | $ENV{'ANSI_COLORS_DISABLED'} = 1 unless $color; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 52 | ▶ | print Dumper $data if defined $data->{debug}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | # Start printing to STDOUT | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 52 | ▶ | say BOLD CYAN program_header($VERSION), RESET if $verbose; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | # Save log file if $log (before $data gets blessed) | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 52 | ▶ | write_log( $log_file, $data ) if defined $log; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | ############################# | ||||||||||||||||||||||||||||||||||||||||||
| 306 | # START DATA TRANSFORMATION # | ||||||||||||||||||||||||||||||||||||||||||
| 307 | ############################# | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 52 | convert( $out_file, $data ); | |||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | ########################### | ||||||||||||||||||||||||||||||||||||||||||
| 312 | # END DATA TRANSFORMATION # | ||||||||||||||||||||||||||||||||||||||||||
| 313 | ########################### | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 52 | ▶ | sub convert { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
convert: called CC=7 SCAR=20.0
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 52 | my ( $o_file, $l_data ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | my $entity_mode = | ||||||||||||||||||||||||||||||||||||||||||
| 319 | $l_data->{method} =~ /2bff$/ | ||||||||||||||||||||||||||||||||||||||||||
| 320 | && ( | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 33 | ▶ | @{ $l_data->{entities} || [] } != 1 | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$l_data->{'entities'} || []
$l_data->{'entities'}[0] || 'individuals'
MC/DC0%0/1
$l_data->{'entities'} || []
$l_data->{'entities'}
MC/DC0%0/1
$l_data->{'entities'}[0] || 'individuals'
$l_data->{'entities'}[0]
Truth table50%1/2
A
A= $l_data->{'entities'}
Truth table50%1/2
A
A= $l_data->{'entities'}[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 52 | ▶ | || ( $l_data->{entities}[0] || 'individuals' ) ne 'individuals' | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$l_data->{'method'} =~ /2bff$/ && (@{$l_data->{'entities'} or [];} != 1 || ($l_data->{'entities'}[0] || 'individuals') ne 'individuals')
@{$l_data->{"entities"} or [];} != 1 or ($l_data->{"entities"}[0] || "individuals") ne "individuals"
MC/DC33%1/3
$l_data->{'method'} =~ /2bff$/ && (@{$l_data->{'entities'} or [];} != 1 || ($l_data->{'entities'}[0] || 'individuals') ne 'individuals')
$l_data->{'method'} =~ /2bff$/
@{$l_data->{"entities"} or [];} != 1
($l_data->{"entities"}[0] || "individuals") ne "individuals"
Truth table75%3/4
A && B or C
A= $l_data->{'method'} =~ /2bff$/B= @{$l_data->{"entities"} or [];} != 1C= ($l_data->{"entities"}[0] || "individuals") ne "individuals"
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 52 | maybe_warn_single_file_pxf_biosamples( $l_data, $entity_mode ); | |||||||||||||||||||||||||||||||||||||||||
| 326 | 51 | prepare_output_targets( $l_data, $o_file, $entity_mode ); | |||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | # Start verbose | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 51 | ▶ | print BOLD BLUE program_body($l_data), RESET if $verbose; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | # Creating object | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 51 | my $convert = Convert::Pheno->new($l_data); | |||||||||||||||||||||||||||||||||||||||||
| 333 | execute_file_conversion($convert, { %$l_data, out_file => $o_file }, | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 12 | ▶ | before_write => sub { ask_overwrite($_[0]) unless $overwrite; return 1 }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 58 | ▶ | on_write => sub { say BOLD GREEN "Writing <$_[0]> file\n", RESET if $verbose; return 1 }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 51 | ); | |||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | # Finish | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 50 | ▶ | print BOLD GREEN program_footer(), RESET if $verbose; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 52 | ▶ | sub maybe_warn_single_file_pxf_biosamples { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
maybe_warn_single_file_pxf_biosamples: called CC=12 SCAR=27.6
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 52 | my ( $l_data, $entity_mode ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | 52 | ▶ | return if $entity_mode; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 42 | ▶ | return unless $l_data->{method} eq 'pxf2bff'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 4 | ▶ | return unless defined $l_data->{in_file}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | my $input = io_yaml_or_json( | ||||||||||||||||||||||||||||||||||||||||||
| 350 | { | ||||||||||||||||||||||||||||||||||||||||||
| 351 | filepath => $l_data->{in_file}, | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 4 | mode => 'read', | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 3 | ▶ | my @items = ref($input) eq 'ARRAY' ? @$input : ($input); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 3 | for my $item (@items) { | |||||||||||||||||||||||||||||||||||||||||
| 359 | 3 | ▶ | next unless ref($item) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | my $phenopacket = | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 3 | ▶ | exists $item->{phenopacket} ? $item->{phenopacket} : $item; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 3 | ▶ | next unless ref($phenopacket) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | next | ||||||||||||||||||||||||||||||||||||||||||
| 364 | unless exists $phenopacket->{biosamples} | ||||||||||||||||||||||||||||||||||||||||||
| 365 | && ref( $phenopacket->{biosamples} ) eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 366 | 3 | ▶ | && @{ $phenopacket->{biosamples} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
exists $phenopacket->{"biosamples"} and ref $phenopacket->{"biosamples"} eq "ARRAY" and @{$phenopacket->{"biosamples"};}
exists $phenopacket->{"biosamples"} and ref $phenopacket->{"biosamples"} eq "ARRAY"
MC/DC0%0/3
exists $phenopacket->{"biosamples"} and ref $phenopacket->{"biosamples"} eq "ARRAY" and @{$phenopacket->{"biosamples"};}
exists $phenopacket->{"biosamples"}
ref $phenopacket->{"biosamples"} eq "ARRAY"
@{$phenopacket->{"biosamples"};}
Truth table25%1/4
A and B and C
A= exists $phenopacket->{"biosamples"}B= ref $phenopacket->{"biosamples"} eq "ARRAY"C= @{$phenopacket->{"biosamples"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | 3 | print STDERR <<'EOF'; | |||||||||||||||||||||||||||||||||||||||||
| 369 | Warning: input PXF contains biosamples. Single-file <-obff FILE> mode emits only <individuals>; biosamples were preserved under <info.phenopacket.biosamples>. Use <-obff --entities biosamples --out-dir DIR> or <-obff --entities individuals biosamples --out-dir DIR> for first-class biosample output. | ||||||||||||||||||||||||||||||||||||||||||
| 370 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 51 | ▶ | sub prepare_output_targets { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_output_targets: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 51 | my ( $l_data, $o_file, $entity_mode ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | 51 | ▶ | if ($entity_mode) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 10 | for my $entity ( @{ $l_data->{entities} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 382 | 17 | my $entity_file = resolve_entity_output_file( $l_data, $entity ); | |||||||||||||||||||||||||||||||||||||||||
| 383 | 17 | ▶ | ask_overwrite($entity_file) unless $overwrite; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 10 | return; | |||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 41 | ▶ | return if $l_data->{method} =~ /2omop$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | 38 | ▶ | ask_overwrite($o_file) unless $overwrite; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | sub program_header { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
program_header: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | my $version = shift; | |||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | my $str = <<EOF; | |||||||||||||||||||||||||||||||||||||||||
| 396 | **************************************** | ||||||||||||||||||||||||||||||||||||||||||
| 397 | * Phenotypic Data Model Convert Tool * | ||||||||||||||||||||||||||||||||||||||||||
| 398 | * - CONVERT-PHENO - * | ||||||||||||||||||||||||||||||||||||||||||
| 399 | * Version: $version * | ||||||||||||||||||||||||||||||||||||||||||
| 400 | * (C) 2022-2026 Manuel Rueda, CNAG * | ||||||||||||||||||||||||||||||||||||||||||
| 401 | * The Artistic License 2.0 * | ||||||||||||||||||||||||||||||||||||||||||
| 402 | **************************************** | ||||||||||||||||||||||||||||||||||||||||||
| 403 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | sub program_footer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
program_footer: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | my $str = <<EOF; | |||||||||||||||||||||||||||||||||||||||||
| 409 | All done! | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | sub program_body { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
program_body: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | my $l_data = shift; | |||||||||||||||||||||||||||||||||||||||||
| 417 | my $file = | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | @{ $l_data->{in_files} || [] } | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$l_data->{'in_files'} || []
MC/DC0%0/1
$l_data->{'in_files'} || []
$l_data->{'in_files'}
Truth table0%0/2
A
A= $l_data->{'in_files'}
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ? join ',', @{ $l_data->{in_files} } | |||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | : $l_data->{in_file}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | my $msg = <<EOF; | |||||||||||||||||||||||||||||||||||||||||
| 422 | ==== METHOD: <$l_data->{method}> ==== | ||||||||||||||||||||||||||||||||||||||||||
| 423 | Processing: <$file> | ||||||||||||||||||||||||||||||||||||||||||
| 424 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | return $msg; | |||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | sub write_log { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_log: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | my ( $log, $data ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | # Detecting the number of logical CPUs across different OSes | ||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | my $os = $^O; | |||||||||||||||||||||||||||||||||||||||||
| 433 | chomp( | ||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | my $threadshost = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/2
`/usr/bin/nproc` // 1
MC/DC0%0/1
`/usr/bin/nproc` // 1
`/usr/bin/nproc`
Truth table0%0/2
A
A= `/usr/bin/nproc`
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | lc($os) eq 'darwin' ? qx{/usr/sbin/sysctl -n hw.logicalcpu} | ||||||||||||||||||||||||||||||||||||||||||
| 436 | : lc($os) eq 'freebsd' ? qx{sysctl -n hw.ncpu} | ||||||||||||||||||||||||||||||||||||||||||
| 437 | : $os eq 'MSWin32' ? qx{wmic cpu get NumberOfLogicalProcessors} | ||||||||||||||||||||||||||||||||||||||||||
| 438 | : qx{/usr/bin/nproc} // 1 | ||||||||||||||||||||||||||||||||||||||||||
| 439 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | # For the Windows command, the result will also contain the string | ||||||||||||||||||||||||||||||||||||||||||
| 442 | # "NumberOfLogicalProcessors" which is the header of the output. | ||||||||||||||||||||||||||||||||||||||||||
| 443 | # So we need to extract the actual number from it: | ||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | if ( $os eq 'MSWin32' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ($threadshost) = $threadshost =~ /(\d+)/; | |||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | $threadshost = 0 + $threadshost; # coercing it to be a number | |||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | my $info = { | ||||||||||||||||||||||||||||||||||||||||||
| 450 | date => ( strftime "%a %b %e %H:%M:%S %Y", localtime ), | ||||||||||||||||||||||||||||||||||||||||||
| 451 | threadshost => $threadshost, | ||||||||||||||||||||||||||||||||||||||||||
| 452 | hostname => hostname, | ||||||||||||||||||||||||||||||||||||||||||
| 453 | id => $data->{id}, # string | ||||||||||||||||||||||||||||||||||||||||||
| 454 | version => $VERSION, | ||||||||||||||||||||||||||||||||||||||||||
| 455 | user => $ENV{'LOGNAME'} | ||||||||||||||||||||||||||||||||||||||||||
| 456 | || $ENV{'USER'} | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | || $ENV{'USERNAME'} | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/8
$ENV{'LOGNAME'} || $ENV{'USER'} || $ENV{'USERNAME'} || 'dummy-user'
$ENV{"LOGNAME"} or $ENV{"USER"} or $ENV{"USERNAME"}
$ENV{"LOGNAME"} or $ENV{"USER"}
MC/DC0%0/3
$ENV{'LOGNAME'} || $ENV{'USER'} || $ENV{'USERNAME'} || 'dummy-user'
$ENV{"LOGNAME"}
$ENV{"USER"}
$ENV{"USERNAME"}
Truth table0%0/4
A or B or C
A= $ENV{"LOGNAME"}B= $ENV{"USER"}C= $ENV{"USERNAME"}
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | || 'dummy-user' | ||||||||||||||||||||||||||||||||||||||||||
| 459 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | # Saving file | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | say BOLD GREEN "Writing <$log> file\n" if $verbose; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | write_atomically( | ||||||||||||||||||||||||||||||||||||||||||
| 464 | $log, | ||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | my ($staged) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | io_yaml_or_json( | |||||||||||||||||||||||||||||||||||||||||
| 468 | { | ||||||||||||||||||||||||||||||||||||||||||
| 469 | filepath => $staged, | ||||||||||||||||||||||||||||||||||||||||||
| 470 | mode => 'write', | ||||||||||||||||||||||||||||||||||||||||||
| 471 | data => { info => $info, data => $data } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||
| 473 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | sub ask_overwrite { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ask_overwrite: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | my $filepath = shift; | |||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | # Check if the file exists | ||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | ▶ | if ( -f $filepath ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | my $attempt_count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | my $max_attempts = 5; | |||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | ▶ | while ( $attempt_count < $max_attempts ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | print BOLD RED "<$filepath> exists. Overwrite? [Y/n]: "; | |||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | my $input = <STDIN>; | |||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | chomp $input; | |||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | if ( $input eq 'Y' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | print RESET; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | return; # Exit after successful deletion | |||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 495 | elsif ( $input eq 'n' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | die "Operation aborted by the user.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 498 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | say "Invalid input. Please enter 'Y' or 'n'."; | |||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | $attempt_count++; | |||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | die "Too many invalid attempts. Operation aborted.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||