Interactive wrapper for a pointer to a C++ object that stores information about haploid variants from a single reference genome.
This class should NEVER be created using variants$new
.
Only use create_variants
.
Because this class wraps a pointer to a C++ object, there are no fields to
manipulate directly.
All manipulations are done through this class's methods.
ref_genome
objectsRegarding the ref_genome
object you use to create a variants
object, you should
note the following:
This point is the most important.
Both the ref_genome
and variants
objects use the same underlying
C++ object to store reference genome information.
Thus, if you make any changes to the ref_genome
object, those changes will
also show up in the variants
object.
For example, if you make a variants
object named V
based on an existing ref_genome
object named R
,
then you merge chromosomes in R
,
V
will now have merged chromosomes.
If you've already started adding mutations to V
,
then all the indexes used to store those mutations will be inaccurate.
So when you do anything with V
later, your R session will crash
or have errors.
The lesson here is that you shouldn't edit the reference
genome after using it to create variants.
If a ref_genome
object is used to create a variants
object, deleting the ref_genome
object won't cause issues with
the variants
object.
However, the variants
class doesn't provide methods to edit
chromosomes, so only remove the ref_genome
object when you're done
editing the reference genome.
new()
Do NOT use this; only use create_variants
to make new variants
.
variants$new(genomes_ptr, reference_ptr)
genomes_ptr
An externalptr
object pointing to a C++ object that
stores the information about the variants.
reference_ptr
An externalptr
object pointing to a C++ object that
stores the information about the reference genome.
print()
Print a variants
object.
variants$print()
ptr()
View pointer to underlying C++ object (this is not useful to end users).
variants$ptr()
An externalptr
object.
n_chroms()
View number of chromosomes.
variants$n_chroms()
Integer number of chromosomes.
n_vars()
View number of variants.
variants$n_vars()
Integer number of variants.
sizes()
View chromosome sizes for one variant.
variants$sizes(var_ind)
var_ind
Index for the focal variant.
Integer vector of chromosome sizes for focal variant.
chrom_names()
View chromosome names.
variants$chrom_names()
Character vector of chromosome names.
var_names()
View variant names.
variants$var_names()
Character vector of variant names.
chrom()
View one variant chromosome.
variants$chrom(var_ind, chrom_ind)
var_ind
Index for the focal variant.
chrom_ind
Index for the focal chromosome.
A single string representing the chosen variant chromosome's DNA sequence.
gc_prop()
View GC proportion for part of one variant chromosome.
variants$gc_prop(var_ind, chrom_ind, start, end)
var_ind
Index for the focal variant.
chrom_ind
Index for the focal chromosome.
start
Point on the chromosome at which to start the calculation (inclusive).
end
Point on the chromosome at which to end the calculation (inclusive).
A double in the range [0,1]
representing the proportion of DNA
sequence that is either G
or C
.
nt_prop()
View nucleotide content for part of one variant chromosome
variants$nt_prop(nt, var_ind, chrom_ind, start, end)
nt
Which nucleotide to calculate the proportion that the DNA
sequence is made of. Must be one of T
, C
, A
, G
, or N
.
var_ind
Index for the focal variant.
chrom_ind
Index for the focal chromosome.
start
Point on the chromosome at which to start the calculation (inclusive).
end
Point on the chromosome at which to end the calculation (inclusive).
A double in the range [0,1]
representing the proportion of DNA
sequence that is nt
.
set_names()
Change variant names.
variants$set_names(new_names)
new_names
Vector of new names to use. This must be the same length as the number of current names.
This R6
object, invisibly.
add_vars()
Add one or more blank, named variants
variants$add_vars(new_names)
new_names
Vector of name(s) for the new variant(s).
This R6
object, invisibly.
dup_vars()
Duplicate one or more variants by name.
variants$dup_vars(var_names, new_names = NULL)
var_names
Vector of existing variant name(s) that you want to duplicate.
new_names
Optional vector specifying the names of the duplicates.
If NULL
, their names are auto-generated. Defaults to NULL
.
This R6
object, invisibly.
rm_vars()
Remove one or more variants by name.
variants$rm_vars(var_names)
var_names
Vector of existing variant name(s) that you want to remove.
This R6
object, invisibly.
add_sub()
Manually add a substitution.
variants$add_sub(var_ind, chrom_ind, pos, nt)
var_ind
Index for the focal variant.
chrom_ind
Index for the focal chromosome.
pos
Position at which to add the mutation.
nt
Single character representing the nucleotide to change the current one to.
This R6
object, invisibly.
add_ins()
Manually add an insertion.
variants$add_ins(var_ind, chrom_ind, pos, nts)
var_ind
Index for the focal variant.
chrom_ind
Index for the focal chromosome.
pos
Position at which to add the mutation.
nts
String representing the nucleotide(s) that will be inserted after the designated position.
This R6
object, invisibly.
\item{`add_del(var_ind, chrom_ind, pos, n_nts)`}{Manually add a deletion for a given variant (`var_ind`), chromosome (`chrom_ind`), and position (`pos`). The designated number of nucleotides to delete (`n_nts`) will be deleted starting at `pos`, unless `pos` is near the chromosome end and doesn't have `n_nts` nucleotides to remove; it simply stops at the chromosome end in this case.}
add_del()
Manually add a deletion.
variants$add_del(var_ind, chrom_ind, pos, n_nts)
var_ind
Index for the focal variant.
chrom_ind
Index for the focal chromosome.
pos
Position at which to add the mutation.
n_nts
Single integer specifying the number of nucleotides to delete.
These will be deleted starting at pos
.
If pos
is near the chromosome end and doesn't have n_nts
nucleotides
to remove, it simply removes nucleotides from pos
to the chromosome end.
This R6
object, invisibly.