Contents
generate$from.pgs.file
Import PRS models from local PGS Catalog scoring files
generate$from.pgs.file() reads PGS Catalog scoring files from disk into
PolyGenius. It is the local-file counterpart to
generate$from.pgs.catalog(), which imports the
same format over the network by accession.
Usage
generate.from.pgs.file(path)Arguments
| Argument | Description |
|---|---|
path | Character scalar or character vector of file paths, or a single directory path. A single path that is not an existing directory is read as one file, and aborts when the file does not exist. |
Value
A PGS when path is one file; a PGSLibrary when it is
a directory or a vector of paths. A returned set carries a record with
name = "generate$from.pgs.file", the deparsed call, and a sources entry
recording the path read; see the Library-level provenance section of
PGSLibrary. A single model has no library-level record -- its own
$generation names the scoring file it came from.
Details
Files written by PGS$write.pgs.file() in extended mode round-trip
losslessly, because their #polygenius_* extension keys restore gwas,
generation, liftover and any user fields. Plain PGS Catalog or third-party
files load as leaner models built from the standard header alone.
A directory containing a manifest.json (written by
PGSLibrary$write.pgs.file()) is read in the manifest's order, and
the manifest is verified twice: its position values must form a gap-free
1..M permutation, and the fingerprint of the set just read must equal the
recorded one. Either check failing aborts, so a file added, removed or edited
since the manifest was written is not silently accepted. A directory without a
manifest is read as every *.txt/*.txt.gz it holds, in list.files() order.
Weights and build
The same two guarantees as
generate$from.pgs.catalog apply, because both
paths share one import boundary. $variants$beta is converted to a log-scale
per-allele effect according to the file's #weight_type header; an unreported
scale warns, an uninterpretable one is refused, and a file whose
#genome_build is absent, NR, or an unsupported assembly is refused.
$build holds the canonical name ("hg19/GRCh37" or "hg38/GRCh38")
whichever alias the file declares, and a written file declares GRCh37 or
GRCh38.
Rows repeating a variant (same chromosome, position, other and effect allele) load once:
exact copies keep the first row, and a variant listed with different weights is dropped.
Either case warns. See PGS().
A file written by PGS$write.pgs.file() always declares #weight_type=beta,
because the conversion already happened when the model was imported, so a
write/read round-trip does not convert a second time. The scale the score
was originally published on survives in the #polygenius_generation extension
key.
Naming
The model is named after the file's #pgs_name header, falling back to its
#pgs_id accession when no usable name is declared. A file carrying neither
names no score and is refused: the path a file happens to sit at is not a name
the file gives itself.
Examples
# Round-trip a single model
model$write.pgs.file("model.txt")
model2 <- generate$from.pgs.file("model.txt")
# A whole set written to a directory
models$write.pgs.file("out/")
models2 <- generate$from.pgs.file("out/")