Interactive wrapper for a pointer to a C++ object that stores information about haploid variants from a single reference genome.

Details

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.

Connections to ref_genome objects

Regarding 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.

See also

Methods

Public methods


Method new()

Do NOT use this; only use create_variants to make new variants.

Usage

variants$new(genomes_ptr, reference_ptr)

Arguments

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.


Method print()

Print a variants object.

Usage

variants$print()


Method ptr()

View pointer to underlying C++ object (this is not useful to end users).

Usage

variants$ptr()

Returns

An externalptr object.


Method n_chroms()

View number of chromosomes.

Usage

variants$n_chroms()

Returns

Integer number of chromosomes.


Method n_vars()

View number of variants.

Usage

variants$n_vars()

Returns

Integer number of variants.


Method sizes()

View chromosome sizes for one variant.

Usage

variants$sizes(var_ind)

Arguments

var_ind

Index for the focal variant.

Returns

Integer vector of chromosome sizes for focal variant.


Method chrom_names()

View chromosome names.

Usage

variants$chrom_names()

Returns

Character vector of chromosome names.


Method var_names()

View variant names.

Usage

variants$var_names()

Returns

Character vector of variant names.


Method chrom()

View one variant chromosome.

Usage

variants$chrom(var_ind, chrom_ind)

Arguments

var_ind

Index for the focal variant.

chrom_ind

Index for the focal chromosome.

Returns

A single string representing the chosen variant chromosome's DNA sequence.


Method gc_prop()

View GC proportion for part of one variant chromosome.

Usage

variants$gc_prop(var_ind, chrom_ind, start, end)

Arguments

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).

Returns

A double in the range [0,1] representing the proportion of DNA sequence that is either G or C.


Method nt_prop()

View nucleotide content for part of one variant chromosome

Usage

variants$nt_prop(nt, var_ind, chrom_ind, start, end)

Arguments

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).

Returns

A double in the range [0,1] representing the proportion of DNA sequence that is nt.


Method set_names()

Change variant names.

Usage

variants$set_names(new_names)

Arguments

new_names

Vector of new names to use. This must be the same length as the number of current names.

Returns

This R6 object, invisibly.


Method add_vars()

Add one or more blank, named variants

Usage

variants$add_vars(new_names)

Arguments

new_names

Vector of name(s) for the new variant(s).

Returns

This R6 object, invisibly.


Method dup_vars()

Duplicate one or more variants by name.

Usage

variants$dup_vars(var_names, new_names = NULL)

Arguments

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.

Returns

This R6 object, invisibly.


Method rm_vars()

Remove one or more variants by name.

Usage

variants$rm_vars(var_names)

Arguments

var_names

Vector of existing variant name(s) that you want to remove.

Returns

This R6 object, invisibly.


Method add_sub()

Manually add a substitution.

Usage

variants$add_sub(var_ind, chrom_ind, pos, nt)

Arguments

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.

Returns

This R6 object, invisibly.


Method add_ins()

Manually add an insertion.

Usage

variants$add_ins(var_ind, chrom_ind, pos, nts)

Arguments

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.

Returns

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.}


Method add_del()

Manually add a deletion.

Usage

variants$add_del(var_ind, chrom_ind, pos, n_nts)

Arguments

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.

Returns

This R6 object, invisibly.