Cn-Bioinf
view release on metacpan or search on metacpan
A genotype is counted only when the call is diploid and complete: a `./.`, a
`./1`, a haploid call (the panel is autosomal) or one below `min_depth` leaves
the marker without a genotype. A site split into one record per ALT is counted
from whichever record carries the counted allele, in either order, and a record
at a marker's position whose REF is longer than one base is some other variant
and is passed over.
`hirisplex_genotypes` warns when the file holds none of the 41 markers, which
usually means the wrong build or an ID column of `.`.
Reading the markers is done in XS, in one pass, keeping one byte per sample per
marker, so a whole-genome VCF costs no more memory than a small one. A
275,879-record exome of 22 MB gzipped took 0.86 s (perl 5.44.0, 2026-10-20).
Most of the panel is intronic or intergenic, so an exome carries little of it:
that same exome held 9 of the 41 markers. A whole-genome VCF, a genotyping
array that covers the panel, or the SNaPshot assay the panel was designed for
is what the prediction expects, and `missing` and `called` are returned so that
a prediction made from a handful of markers can be seen for what it is.
## trait_predict(%args)
Applies a multinomial logistic regression -- which is what the HIrisPlex-S,
HIrisPlex and IrisPlex models are -- to genotypes, and returns a probability
for each category of each trait:
use Cn::Bioinf qw(hirisplex_genotypes trait_predict);
my $g = hirisplex_genotypes(vcf => 'genome.vcf.gz', report => 0);
my $p = trait_predict(genotypes => $g, model => 'my_model.tsv');
print $p->{NA12878}{eye}{call}; # the most probable category
print $p->{NA12878}{eye}{p}{blue}; # its probability
The model is yours to supply: see `hirisplex_genotypes` above for why this
distribution ships none. Any model written in the form below works, so this is
not limited to pigmentation.
### The model table
A tab-separated file (optionally gzipped), or a data frame as
`Stats::LikeR`'s `read_table` returns, with four columns:
trait category marker beta
eye blue (intercept) 3.94
eye blue rs12913832_T -4.81
eye brown (intercept) 0
`marker` is a key of the `genotype` hash `hirisplex_genotypes` returns, which
is `<rs number>_<input allele>`, or the literal `(intercept)` for the
category's intercept. A category whose only row is an intercept of 0 is the
reference category, which is how a model of *k* categories is written with
*k* - 1 sets of betas; every category that should appear in the result needs at
least one row. Traits and their categories come out in the order the table
first names them. A frame's rows and columns must be of one length, as
`pgs_score`'s must, and a gzipped file that ends early dies.
For each category the linear predictor is its intercept plus the sum of its
betas times the genotypes, and the probabilities are `exp` of those over their
sum. The largest is taken out before `exp`, so a linear predictor large enough
to overflow gives 1 rather than a NaN.
### Arguments
- `genotypes` (required): what `hirisplex_genotypes` returned, or a plain hash
ref of sample => { marker => 0, 1 or 2 }. A dosage may be any number from 0
to 2, as imputation gives, and `undef` is no genotype; anything else, `NA`
included, dies naming the sample and the marker. Only the markers the model
uses are looked at.
- `model` (required): the table above, as a file name or a data frame.
- `force`: 0 (the default) makes no prediction for a trait that the genotypes
say cannot be predicted -- that is, where `hirisplex_genotypes` set `eye`,
`hair` or `skin` to 0; 1 predicts it anyway. A trait the genotypes say
nothing about is always predicted.
- `report`: 1 (the default) prints a table of the samples to STDOUT; 0 returns
them only.
### What it returns
A hash ref keyed by sample and then by trait, each holding:
- `p`: a hash ref of category => probability, which sum to 1; empty when the
prediction was refused.
- `call`: the most probable category, or `undef` when it was refused. A tie is
broken by the category's name, so the answer does not depend on hash order.
- `markers` and `called`: how many markers the trait's categories use between
them, and how many this sample has a genotype for.
- `missing`: an array ref of the markers the model names and the sample has no
genotype for.
- `refused`: `undef`, or why no prediction was made.
A marker the sample has no genotype for drops out of the sum, which is the same
as counting it 0 copies of the counted allele. That is a choice, not something
the HIrisPlex-S authors specify, and it biases the result towards whatever 0
copies means for that marker; `missing` and `called` are returned so that a
prediction made from few markers can be reported as such. The webtool reports a
loss in AUC for exactly this reason.
## plot_msa(%args)
Aligns sequences with Clustal Omega and draws the alignment. Returns a hash ref
of the files made: `filename`, `msa_file`, `python_file` (see `fh` and
`execute` below), and `tree_file` if it was given. Once the image is written it
prints `wrote` and its file name to STDOUT, the name in black on yellow when
STDOUT is a terminal; with `execute => 0` it prints `will write` instead.
plot_msa(
fasta => 't/data/DEG20010421.fa',
filename => 'DEG20010421.msa.svg',
);
- `fasta`, `filename` (required): the sequences, as a FASTA file name or a
hash ref of name => sequence (the function tells the two apart by whether it
is a reference); and the image to draw, whose extension picks the format.
A name may hold spaces and punctuation: Clustal Omega is given the sequences
as `s1`, `s2` and so on, and the alignment and tree it writes get their
names back, in UTF-8. In the tree, a name with whitespace or any of
`()[]':;,` in it is quoted as newick quotes one, as `'it''s (x:1)'`.
- `msa_file`, `tree_file`: where to keep clustalo's alignment (FASTA; a
temporary file otherwise) and its guide tree (newick; not made otherwise).
Keep the tree to draw it with `plot_phylo` without aligning a second time.
( run in 0.900 second using v1.01-cache-2.11-cpan-60884a8df76 )