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

Details

This class should NEVER be created using haplotypes$new. Only use create_haplotypes. 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 haplotypes object, you should note the following:

  • This point is the most important. Both the ref_genome and haplotypes 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 haplotypes object. For example, if you make a haplotypes 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 haplotypes.

  • If a ref_genome object is used to create a haplotypes object, deleting the ref_genome object won't cause issues with the haplotypes object. However, the haplotypes class doesn't provide methods to edit chromosomes, so only remove the ref_genome object when you're done editing the reference genome.

Methods


Method new()

Do NOT use this; only use create_haplotypes to make new haplotypes.

Usage

haplotypes$new(genomes_ptr, reference_ptr)

Arguments

genomes_ptr

An externalptr object pointing to a C++ object that stores the information about the haplotypes.

reference_ptr

An externalptr object pointing to a C++ object that stores the information about the reference genome.


Method print()

Print a haplotypes object.

Usage

haplotypes$print()


Method ptr()

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

Usage

haplotypes$ptr()

Returns

An externalptr object.


Method n_chroms()

View number of chromosomes.

Usage

haplotypes$n_chroms()

Returns

Integer number of chromosomes.


Method n_haps()

View number of haplotypes.

Usage

haplotypes$n_haps()

Returns

Integer number of haplotypes.


Method sizes()

View chromosome sizes for one haplotype.

Usage

haplotypes$sizes(hap_ind)

Arguments

hap_ind

Index for the focal haplotype.

Returns

Integer vector of chromosome sizes for focal haplotype.


Method chrom_names()

View chromosome names.

Usage

haplotypes$chrom_names()

Returns

Character vector of chromosome names.


Method hap_names()

View haplotype names.

Usage

haplotypes$hap_names()

Returns

Character vector of haplotype names.


Method chrom()

View one haplotype chromosome.

Usage

haplotypes$chrom(hap_ind, chrom_ind)

Arguments

hap_ind

Index for the focal haplotype.

chrom_ind

Index for the focal chromosome.

Returns

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


Method gc_prop()

View GC proportion for part of one haplotype chromosome.

Usage

haplotypes$gc_prop(hap_ind, chrom_ind, start, end)

Arguments

hap_ind

Index for the focal haplotype.

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 haplotype chromosome

Usage

haplotypes$nt_prop(nt, hap_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.

hap_ind

Index for the focal haplotype.

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 haplotype names.

Usage

haplotypes$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_haps()

Add one or more blank, named haplotypes

Usage

haplotypes$add_haps(new_names)

Arguments

new_names

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

Returns

This R6 object, invisibly.


Method dup_haps()

Duplicate one or more haplotypes by name.

Usage

haplotypes$dup_haps(hap_names, new_names = NULL)

Arguments

hap_names

Vector of existing haplotype 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_haps()

Remove one or more haplotypes by name.

Usage

haplotypes$rm_haps(hap_names)

Arguments

hap_names

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

Returns

This R6 object, invisibly.


Method add_sub()

Manually add a substitution.

Usage

haplotypes$add_sub(hap_ind, chrom_ind, pos, nt)

Arguments

hap_ind

Index for the focal haplotype.

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

haplotypes$add_ins(hap_ind, chrom_ind, pos, nts)

Arguments

hap_ind

Index for the focal haplotype.

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(hap_ind, chrom_ind, pos, n_nts)`}{Manually add a deletion
    for a given haplotype (`hap_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

haplotypes$add_del(hap_ind, chrom_ind, pos, n_nts)

Arguments

hap_ind

Index for the focal haplotype.

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.