bin/pheno-ranker

filter: Statementstmt 100% 16 / 16 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 100% 21 / 21 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« lib/Pheno/Ranker/Context.pm ↑ Summary lib/Pheno/Ranker/Version.pm »
1 #!/usr/bin/env perl
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 ▶use FindBin qw($Bin);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use lib "$Bin/../lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Pheno::Ranker::CLI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 exit Pheno::Ranker::CLI->new( pod_file => __FILE__ )->run(@ARGV);
10  
11 =head1 NAME
12  
13 pheno-ranker: A script that performs semantic similarity in PXF/BFF data structures and beyond (JSON|YAML)
14  
15 =head1 SYNOPSIS
16  
17 pheno-ranker -r <individuals.json> -t <patient.json> [-options]
18  
19 Arguments:
20 * Cohort mode:
21 -r, --reference <file> JSON/YAML BFF/PXF file(s) (array/object), supports .gz
22  
23 * Patient mode:
24 -t, --target <file> JSON/YAML BFF/PXF file (object or single-object array), supports .gz
25  
26 Options:
27 -age Include age-related variables; excludes agent-like terms (BFF/PXF-only) [>no-age|age]
28 -a, --align [path/basename] Write alignment file(s). If not specified, default filenames are used [default: alignment.*]
29 -append-prefixes <prefixes> Prefixes for primary_key when #cohorts >= 2 [default: C]
30 -config <file> YAML config file to modify default parameters [default: share/conf/config.yaml]
31 -cytoscape-json [file] Writes an undirected graph in Cytoscape-compatible JSON [default: graph.json]
32 -e, --export [path/basename] Export miscellaneous JSON files. If not specified, default filenames are used [default: export.*]
33 -exclude-terms <terms> Exclude BFF/PXF terms (e.g., --exclude-terms sex id) or column names in JSON-derived from CSV
34 -graph-stats [file] Generates a text file with key graph metrics, for use with <-cytoscape-json> [default: graph_stats.txt]
35 -graph-min-weight <number> Keep graph edges with weight greater than or equal to this value
36 -graph-max-weight <number> Keep graph edges with weight less than or equal to this value
37 -include-hpo-ascendants Include ascendant terms from the Human Phenotype Ontology (HPO)
38 -include-terms <terms> Include BFF/PXF terms (e.g., --include-terms diseases) or column names in JSON-derived from CSV
39 -max-matrix-records-in-ram <number> In cohort mode, set max records before switching to RAM-efficient mode (default: 5000)
40 -matrix-format <format> Matrix output format in cohort mode [>dense|mtx]
41 -max-number-vars <number> Maximum number of variables for binary string [default: 10000]
42 -max-out <number> Print only N comparisons [default: 50]
43 -o, --out-file <file> Output file path [default: -r matrix.txt | -t rank.txt]
44 -poi, --patients-of-interest <id_list> Export JSON files for the selected individual IDs during a dry-run
45 -poi-out-dir <directory> Directory for JSON files (used with --poi)
46 -prp, --precomputed-ref-prefix [path/basename] Use precomputed data for the reference cohort(s). No need to use --r
47 -retain-excluded-phenotypicFeatures Retains features set to "excluded": true by appending '_excluded' to their IDs
48 -similarity-metric-cohort <metric> Similarity metric for cohort mode [>hamming|jaccard]
49 -sort-by <metric> Sort by Hamming distance or Jaccard index [>hamming|jaccard]
50 -w, --weights <file> YAML file with weights
51  
52 Generic Options:
53 -debug <level> Print debugging (from 1 to 5, being 5 max)
54 -h, --help Brief help message
55 -log Save log file [default: pheno-ranker-log.json]
56 -man Full documentation
57 -no-color Toggle color output [>color|no-color]
58 -v, --verbose Verbosity on
59 -V, --version Print version
60  
61 =head1 SUMMARY
62  
63 Pheno-Ranker is a lightweight, easy-to-install tool for performing semantic similarity analysis on phenotypic data in JSON/YAML formats, including Beacon v2 Models and Phenopackets v2. It also supports pre-processed CSV files prepared using the included C<csv2pheno-ranker> utility.
64  
65 =head1 INSTALLATION
66  
67 If you plan to only use C<pheno-ranker> CLI, we recommend installing it via CPAN. See details below.
68  
69 =head2 Non containerized
70  
71 The Perl command-line interface is tested on Linux, macOS, and Windows via GitHub Actions. The commands below focus on Debian-based Linux systems, where Perl 5 is typically available by default and extra CPAN modules can be installed with C<cpanminus>. On Windows, use Docker, WSL, or a Perl environment such as Strawberry Perl.
72  
73 =head3 Method 1: From CPAN
74  
75 First install system level dependencies:
76  
77 sudo apt-get install cpanminus libperl-dev gcc make
78  
79 We will install Pheno-Ranker and the dependencies at C<~/perl5>
80  
81 cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
82 cpanm --notest Pheno::Ranker
83 pheno-ranker --help
84  
85 To ensure Perl recognizes your local modules every time you start a new terminal, you should type:
86  
87 echo 'eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)' >> ~/.bashrc
88  
89 To B<update> to the newest version:
90
91 cpanm Pheno::Ranker
92  
93 =head3 Method 2: From CPAN in a CONDA environment
94  
95 Please follow L<these instructions|https://cnag-biomedical-informatics.github.io/pheno-ranker/download-and-installation/#__tabbed_1_2>.
96  
97 =head3 Method 3: From GitHub
98  
99 To clone the repository for the first time:
100  
101 git clone https://github.com/cnag-biomedical-informatics/pheno-ranker.git
102 cd pheno-ranker
103  
104 To update an existing clone, navigate to the repository folder and run:
105  
106 git pull
107  
108 Install system level dependencies:
109
110 sudo apt-get install cpanminus libperl-dev
111  
112 Now you have to choose between one of the 2 options below:
113  
114 B<Option 1:> Install dependencies (they're harmless to your system) as C<sudo>:
115  
116 cpanm --notest --sudo --installdeps .
117 bin/pheno-ranker --help
118  
119 B<Option 2:> Install the dependencies at C<~/perl5>:
120  
121 cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
122 cpanm --notest --installdeps .
123 bin/pheno-ranker --help
124  
125 To ensure Perl recognizes your local modules every time you start a new terminal, you should type:
126  
127 echo 'eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)' >> ~/.bashrc
128  
129 I<Optional:> If you want to use C<utils/barcode> or C<utils/bff_pxf_plot>:
130  
131 sudo apt-get install python3-pip libzbar0
132 pip3 install -r requirements.txt
133  
134 =head2 Containerized
135  
136 =head3 Method 4: From Docker Hub
137  
138 (Estimated Time: Approximately 10 seconds)
139  
140 Download the latest version of the Docker image (supports both amd64 and arm64 architectures) from L<Docker Hub|https://hub.docker.com/r/manuelrueda/pheno-ranker> by executing:
141  
142 docker pull manuelrueda/pheno-ranker:latest
143 docker image tag manuelrueda/pheno-ranker:latest cnag/pheno-ranker:latest
144  
145 See additional instructions below.
146  
147 =head3 Method 5: With Dockerfile
148  
149 (Estimated Time: Approximately 1 minute)
150  
151 Please download the C<Dockerfile> from the repo:
152  
153 wget https://raw.githubusercontent.com/cnag-biomedical-informatics/pheno-ranker/main/Dockerfile
154  
155 And then run:
156  
157 # Docker Version 19.03 and Above (Supports buildx)
158 docker buildx build -t cnag/pheno-ranker:latest .
159  
160 # Docker Version Older than 19.03 (Does Not Support buildx)
161 docker build -t cnag/pheno-ranker:latest .
162  
163 =head3 Additional instructions for Methods 4 and 5
164  
165 To run the container (detached) execute:
166  
167 docker run -tid -e USERNAME=root --name pheno-ranker cnag/pheno-ranker:latest
168  
169 To enter:
170  
171 docker exec -ti pheno-ranker bash
172  
173 The command-line executable can be found at:
174  
175 /usr/share/pheno-ranker/bin/pheno-ranker
176  
177 The default container user is C<root> but you can also run the container as C<$UID=1000> (C<dockeruser>).
178  
179 docker run --user 1000 -tid --name pheno-ranker cnag/pheno-ranker:latest
180
181 =head3 Mounting volumes
182  
183 Docker containers are fully isolated. If you need the mount a volume to the container please use the following syntax (C<-v host:container>).
184 Find an example below (note that you need to change the paths to match yours):
185  
186 docker run -tid --volume /media/mrueda/4TBT/data:/data --name pheno-ranker-mount cnag/pheno-ranker:latest
187  
188 Then I will do something like this:
189  
190 # First I create an alias to simplify invocation (from the host)
191 alias pheno-ranker='docker exec -ti pheno-ranker-mount /usr/share/pheno-ranker/bin/pheno-ranker'
192  
193 # Now I use the alias to run the command (note that I use the flag --o to specify the filepath)
194 pheno-ranker -r /data/individuals.json -o /data/matrix.txt
195  
196 =head3 System requirements
197  
198 - OS/ARCH supported: B<linux/amd64> and B<linux/arm64>.
199 - Ideally a Debian-based distribution (Ubuntu or Mint), but any other (e.g., CentOS, OpenSUSE) should do as well (untested).
200 The Perl CLI is also tested on macOS and Windows; container images are Linux-based.
201 * Perl 5 (>= 5.26 core; installed by default in most Linux distributions). Check the version with "perl -v".
202 * >= 4GB of RAM
203 * 1 core
204 * At least 16GB HDD
205  
206 =head1 HOW TO RUN PHENO-RANKER
207  
208 For executing pheno-ranker you will need a PXF/BFF file(s) in JSON|YAML format. The reference cohort must be a JSON array, where each individual data are consolidated in one object.
209  
210 You can download examples from L<this location|https://github.com/CNAG-Biomedical-Informatics/pheno-ranker/tree/main/share/ex>.
211  
212 There are two modes of operation:
213  
214 =over 4
215  
216 =item Cohort mode:
217
218 B<Intra-cohort:> With C<--r> argument and 1 cohort.
219  
220 B<Inter-cohort:> With C<--r> and multiple cohort files. It can be used in combination with C<--append-prefixes> to add prefixes to each individual id.
221  
222 =item Patient Mode:
223  
224 With C<-r> reference cohort(s) and C<--t> patient data.
225  
226 =back
227  
228 B<Examples:>
229  
230 $ bin/pheno-ranker -r phenopackets.json # intra-cohort
231  
232 $ bin/pheno-ranker -r phenopackets.yaml -o my_matrix.txt # intra-cohort
233  
234 $ bin/pheno-ranker -r phenopackets.json -w weights.yaml --exclude-terms sex ethnicity exposures # intra-cohort with weights
235  
236 $ $path/pheno-ranker -r individuals.json others.yaml --append-prefixes CANCER CONTROL # inter-cohort
237  
238 $ $path/pheno-ranker -r individuals.json -t patient.yaml -max-out 100 # mode patient
239  
240  
241 =head2 COMMON ERRORS AND SOLUTIONS
242  
243 * Error message: R plotting
244 Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, :
245 line 1 did not have X elements
246 Calls: as.matrix -> read.table -> scan
247 Execution halted
248 Solution: Make sure that the values of your primary key (e.g., "id") do not contain spaces (e.g., "my fav id" must be "my_fav_id")
249  
250 * Error message: Foo
251 Solution: Bar
252  
253 =head1 CITATION
254  
255 The author requests that any published work that utilizes C<Pheno-Ranker> includes a cite to the following reference:
256  
257 Leist, I.C. et al., (2024). Pheno-Ranker: a toolkit for comparison of phenotypic data stored in GA4GH standards and beyond. I<BMC Bioinformatics>. DOI: 10.1186/s12859-024-05993-2
258  
259 =head1 AUTHOR
260  
261 Written by Manuel Rueda, PhD. Info about CNAG can be found at L<https://www.cnag.eu>.
262  
263 =head1 COPYRIGHT AND LICENSE
264  
265 This PERL file is copyrighted. See the LICENSE file included in this distribution.
266  
267 =cut
« lib/Pheno/Ranker/Context.pm ↑ Summary lib/Pheno/Ranker/Version.pm »