Title: | Estimating Frequencies, Prevalence and Multiplicity of Infection |
---|---|
Description: | The implemented methods reach out to scientists that seek to estimate multiplicity of infection (MOI) and lineage (allele) frequencies and prevalences at molecular markers using the maximum-likelihood method described in Schneider (2018) <doi:10.1371/journal.pone.0194148>, and Schneider and Escalante (2014) <doi:10.1371/journal.pone.0097899>. Users can import data from Excel files in various formats, and perform maximum-likelihood estimation on the imported data by the package's moimle() function. |
Authors: | Meraj Hashemi [cre, aut, com], Kristan Schneider [aut, ths] |
Maintainer: | Meraj Hashemi <[email protected]> |
License: | GPL-3 |
Version: | 0.1.2 |
Built: | 2024-10-31 18:35:55 UTC |
Source: | https://github.com/mhashemihsmw/mlmoi |
The MLMOI package provides three functions:
moimport();
moimle();
moimerge().
The package reaches out to scientists that seek to
estimate MOI and lineage frequencies at molecular markers
using the maximum-likelihood method described in
(Schneider 2018),
(Schneider and Escalante 2018) and
(Schneider and Escalante 2014). Users can
import data from Excel files in various formats, and
perform maximum-likelihood estimation on the imported data
by the package's moimle()
function.
Molecular data can be of types:
microsatellite repeats (STRs);
single nucleotide polymorphisms (SNPs);
amino acids;
codons (base triplets).
The function moimport()
, is
designed to import molecular data. It imports molecular
data in various formats and transforms them into a
standard format.
Two datasets in standard format
can be merged with the function moimerge()
.
The function
moimle()
is designed to derive MLE from molecular
data in standard format.
Schneider KA (2018). “Large and finite sample properties of a maximum-likelihood estimator for multiplicity of infection.” PLOS ONE, 13(4), 1-21. doi:10.1371/journal.pone.0194148.
Schneider KA, Escalante AA (2018). “Correction: A Likelihood Approach to Estimate the Number of Co-Infections.” PLOS ONE, 13(2), 1-3. doi:10.1371/journal.pone.0192877.
Schneider KA, Escalante AA (2014). “A Likelihood Approach to Estimate the Number of Co-Infections.” PLoS ONE, 9(7), e97899. http://dx.doi.org/10.1371%2Fjournal.pone.0097899.
The function is designed to merge two datasets from separate Excel files. The data in each Excel file is placed in the first worksheet.
moimerge( file1, file2, nummtd1, nummtd2, keepmtd = FALSE, export = NULL, keepwarnings = NULL )
moimerge( file1, file2, nummtd1, nummtd2, keepmtd = FALSE, export = NULL, keepwarnings = NULL )
file1 |
string; specifying the path of the first dataset. |
file2 |
string; specifying the path of the second dataset. |
nummtd1 |
numeric; number of metadata columns (see
|
nummtd2 |
numeric; number of metadata columns (see
|
keepmtd |
logical; determining whether metadata
(e.g., date) should be retained (default as
|
export |
string; the path where the data is stored. |
keepwarnings |
string; the path where the warnings are stored. |
The two datasets should be already in standard
format (see moimport()
). The datasets
are placed in the first worksheet of the two different
Excel files. Notice that marker labels (=column
labels) need to be unique.
The output is a dataset in standard format which constitutes of an assembly of the input datasets.
Warnings are generated if potential
inconsistencies are detected. E.g., if the same sample
occurs in both datasets and have contradicting metadata
entries. The function only prints the first 50 warnings.
If the number of warnings are more than 50, the user is
recommended to set the argument keepwarnings
,
in order to save the warnings in an Excel file.
To import and transform data into standard
format, please see the function moimport()
.
#The datasets 'testDatamerge1.xlsx' and 'testDatamerge1.xlsx' are already in standard format: infile1 <- system.file("extdata", "testDatamerge1.xlsx", package = "MLMOI") infile2 <- system.file("extdata", "testDatamerge2.xlsx", package = "MLMOI") outfile <- moimerge(infile1, infile2, nummtd1 = 1, nummtd2 = 2, keepmtd = TRUE)
#The datasets 'testDatamerge1.xlsx' and 'testDatamerge1.xlsx' are already in standard format: infile1 <- system.file("extdata", "testDatamerge1.xlsx", package = "MLMOI") infile2 <- system.file("extdata", "testDatamerge2.xlsx", package = "MLMOI") outfile <- moimerge(infile1, infile2, nummtd1 = 1, nummtd2 = 2, keepmtd = TRUE)
moimle()
derives the maximum-likelihood
estimate (MLE) of the MOI parameter (Poisson parameter)
and the lineage (allele) frequencies for each molecular
marker in a dataset. Additionally, the lineage
prevalence counts are derived.
moimle(file, nummtd = 0, bounds = c(NA, NA))
moimle(file, nummtd = 0, bounds = c(NA, NA))
file |
string or data.frame; if file is a path it
must specify the path to the file to be imported. The
dataset can also be a data.frame object in R. The dataset
must be in standard format (see |
nummtd |
numeric; number of metadata columns (e.g.
date, sample location, etc.) in the dataset (default
value is |
bounds |
numeric vector; a vector of size 2, specifying a lower bound (1st element) and an upper bound (2nd element) for the MOI parameter. The function derives lineage frequency ML estimates by profiling the likelihood function on one of the bounds. For a marker without sign of super-infections, the lower bound is employed. If one allele is contained in every sample, the upper bound is employed. |
moimle()
requires a dataset in standard
format which is free of typos (e.g. incompatible and
unidentified entries). Therefore, users need to
standardize the dataset by employing the
moimport()
function.
If one or more molecular markers contain pathological
data, the ML estimate for the Poisson parameter is
either 0 or does not exist. Both estimates are
meaningless, however, in the former case frequency
estimates exist while they do not in the later. By
setting the option bounds
as a range for MOI
parameter . i.e.,
bounds =
c(<>, <
>), this
problem is bypassed and the ML estimates are calculated
by profiling at
or
.
If no super-infections are observed at a marker,
moimle()
uses as the MOI
parameter estimate,
if one lineage is
present in all samples. For regular data, the
profile-likelihood estimate using
or
is returned depending on whether the
ML estimate falls below
or above
.
moimle()
returns a nested list, where the
outer elements correspond to molecular markers in the
dataset. The inner elements for each molecular marker
contain the following information:
sample size,
allele prevalence counts,
observed prevalences
log likelihood at MLE,
maximum-likelihood estimate of MOI parameter,
maximum-likelihood estimates of lineage frequencies.
Warnings are issued, if data is
pathological at one or multiple markers. If the option
bounds
is set, but MLE of MOI parameter at a
molecular marker takes a lower or higher value than
respectively, a warning
is generated.
To import and transform data to standard format,
please see the function moimport()
.
#basic data analysis infile1 <- system.file("extdata", "testDatamerge1.xlsx", package = "MLMOI") mle1 <- moimle(infile1, nummtd = 1)
#basic data analysis infile1 <- system.file("extdata", "testDatamerge1.xlsx", package = "MLMOI") mle1 <- moimle(infile1, nummtd = 1)
moimport()
imports molecular data from
Excel workbooks. The function handles various types of
molecular data (e.g. STRs, SNPs), codings (e.g. 4-letter
vs. IUPAC format for SNPs), and detects inconsistencies
(e.g. typos, incorrect entries). moimport()
allows users to import data from single or multiple
worksheets.
moimport( file, multsheets = FALSE, nummtd = 0, molecular = "str", coding = "integer", transposed = FALSE, keepmtd = FALSE, export = NULL, keepwarnings = NULL )
moimport( file, multsheets = FALSE, nummtd = 0, molecular = "str", coding = "integer", transposed = FALSE, keepmtd = FALSE, export = NULL, keepwarnings = NULL )
file |
string; specifying the path to the file to be imported. |
multsheets |
logical; indicating whether data is
contained in a single or multiple worksheets. The
default value is |
nummtd |
numeric number or vector; number of metadata
columns (e.g. date, sample location, etc.) in the
worksheet(s) to be imported (default value |
molecular |
string vector or list; specifies the type
of molecular data to be imported. STR, SNP, amino acid
and codon markers are specified with 'STR', 'SNP',
'amino' and 'codon' values, respectively (default value
|
coding |
string vector or list; specifies the coding
of each data variable (marker) depending on their type.
Admissible values for |
transposed |
logical or logical vector; if markers
are entered in rows and samples in columns, set
|
keepmtd |
logical; determines whether metadata (e.g.,
date) should be retained during import (default value
|
export |
string; the path where the imported data is
stored in standardized format. Data is not stored if no
path is specified (default value |
keepwarnings |
string; the path where the warnings
are stored. Warnings are not stored if no path is
specified (default value |
Each worksheet of the data to be imported must have one of the following formats: i) one row per sample and one column per marker. Here cells can have multiple entries, separated by a special character (separator), e.g. a punctuation character. ii) one column per marker and multiple rows per sample (standard format). iii) one row per sample and multiple columns per marker. Importantly, within one worksheet formats ii) and iii) cannot be combined (see section Warnings and Errors). Combinations of other formats are permitted but might result in warnings. Additionally, Occurrence of different separators are reported (see section Warnings and Errors).
Users should check the following before data import:
the dataset is placed in the first worksheet of the workbook;
in case of multiple worksheets, all worksheets contain data (additional worksheets need to be removed);
sample IDs are placed in the first column (first row in case of transposed data; see section Exceptions);
marker labels are placed in the first row (first column in case of transposed data; see section Exceptions);
sample IDs and as well the marker labels are unique (the duplication of ID/labels are allowed when sample/marker contains data in consecutive rows/columns);
entries such as sentences (e.g. comments in the worksheet) or meaningless words (e.g. 'missing' for missing data) are removed from data;
metadata columns (rows in case of transposed data) are placed between sample IDs and molecular-marker columns.
If data is contained in multiple worksheets, above requirements need to be fulfilled for every worksheet in the Excel workbook. Not all sample IDs must occur in every worksheet. The sample ID must not be confused with the patient's ID, the former refers to a particular sample taken from a patient, the latter to a unique patient. Several sample IDs can have the same patient's ID. In case of multiple-worksheet datasets, all marker labels across all worksheets need to be unique.
The option molecular
needs to be specified as a
vector, for single-worksheet data (multsheets =
FALSE
) containing different types of molecular markers.
A list is specified, if data spread across multiple
worksheets with different types of molecular across the
worksheets. List elements are vectors or single values,
referring to the types of molecular data of the
corresponding worksheets. Users do not need to set a
vector if all markers are of the same molecular type
(single or multiple worksheet dataset).
Setting the option coding
as vector or list is
similar to setting molecular type by molecular
.
Every molecular data type has a pre-specified coding
class as default which users do not need to specify.
Namely, 'integer' for STRs, '4let' for SNPs, '3let' for
amino acids and 'triplet' for codons.
returns a data frame. moimport()
imports
heterogeneous data formats and converts them into a
standard format which are free from typos (e.g.
incompatible and unidentified entries) appropriate for
further analyses. Metadata is retained (if keepmtd
= TRUE
) and, in case of data from multiple worksheets,
unified if metadata variables have the same labels
across two or more worksheets. If the argument
export
is set, then the result is saved in the
first worksheet of the workbook of the file specified by
export
. The imported/exported dataset will be
appropriate for other functions of the package.
Usually warnings are generated if data is corrected pointing to suspicious entries in the original data. Users should read warnings carefully and check respective entries and apply manual corrections if necessary. In case of issues an error occurs and the function is stopped.
Usually, if arguments are not set properly, errors occur. Other cases of errors are: i) if sample IDs in a worksheet are not uniquely defined, i.e., two samples in non-consecutive rows have the same sample ID; ii) if formats 'one column per marker and multiple rows per sample' and 'one row per sample and multiple columns per marker' are mixed.
Warnings are issued in several cases. Above all, when typos (e.g., punctuation characters) are found. Entries which cannot be identified as a molecular type/coding class specified by the user are also reported (e.g., '9' is reported when marker is of type SNPs, or 'L' is reported when coding class of an amino-acid marker is '3let').
Empty rows and columns are deleted and eventually reported. Samples with ambiguous metadata (in a worksheet or across worksheets in case of multiple worksheet dataset), or missing are also reported.
The function only prints the first 50 warnings.
If the number of warnings are more than 50, the user is
recommended to set the argument keepwarnings
,
in order to save the warnings in an Excel file.
Transposed data: usually data is
entered with samples in rows and markers in columns.
However, on the contrary some users might enter data the
opposite way. That is the case of transposed data. If
so, the argument transposed = TRUE
is set, or a
vector in case of multiple worksheets with at least one
worksheet being transposed.
For further details, see the following vignettes:
vignette("dataimportcheck-list", package =
"MLMOI")
vignette("StandardAmbiguityCodes", package =
"MLMOI")
vignette("moimport-arguments", package = "MLMOI")
#datasets are provided by the package #importing dataset with metadata variables: infile <- system.file("extdata", "testDatametadata.xlsx", package = "MLMOI") moimport(infile, nummtd = 3, keepmtd = TRUE) ##more examples are included in 'examples' vignette: #vignette("examples", package = "MLMOI")
#datasets are provided by the package #importing dataset with metadata variables: infile <- system.file("extdata", "testDatametadata.xlsx", package = "MLMOI") moimport(infile, nummtd = 3, keepmtd = TRUE) ##more examples are included in 'examples' vignette: #vignette("examples", package = "MLMOI")