| haplotypes {jackalope} | R Documentation |
An R6 Class Representing Haploid Variants
Description
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_genomeandhaplotypesobjects use the same underlying C++ object to store reference genome information. Thus, if you make any changes to theref_genomeobject, those changes will also show up in thehaplotypesobject. For example, if you make ahaplotypesobject namedVbased on an existingref_genomeobject namedR, then you merge chromosomes inR,Vwill now have merged chromosomes. If you've already started adding mutations toV, then all the indexes used to store those mutations will be inaccurate. So when you do anything withVlater, 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_genomeobject is used to create ahaplotypesobject, deleting theref_genomeobject won't cause issues with thehaplotypesobject. However, thehaplotypesclass doesn't provide methods to edit chromosomes, so only remove theref_genomeobject when you're done editing the reference genome.
Methods
Public methods
Method new()
Do NOT use this; only use create_haplotypes to make new haplotypes.
Usage
haplotypes$new(genomes_ptr, reference_ptr)
Arguments
genomes_ptrAn
externalptrobject pointing to a C++ object that stores the information about the haplotypes.reference_ptrAn
externalptrobject 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_indIndex 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_indIndex for the focal haplotype.
chrom_indIndex 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_indIndex for the focal haplotype.
chrom_indIndex for the focal chromosome.
startPoint on the chromosome at which to start the calculation (inclusive).
endPoint 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
ntWhich nucleotide to calculate the proportion that the DNA sequence is made of. Must be one of
T,C,A,G, orN.hap_indIndex for the focal haplotype.
chrom_indIndex for the focal chromosome.
startPoint on the chromosome at which to start the calculation (inclusive).
endPoint 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_namesVector 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_namesVector 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_namesVector of existing haplotype name(s) that you want to duplicate.
new_namesOptional vector specifying the names of the duplicates. If
NULL, their names are auto-generated. Defaults toNULL.
Returns
This R6 object, invisibly.
Method rm_haps()
Remove one or more haplotypes by name.
Usage
haplotypes$rm_haps(hap_names)
Arguments
hap_namesVector 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_indIndex for the focal haplotype.
chrom_indIndex for the focal chromosome.
posPosition at which to add the mutation.
ntSingle 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_indIndex for the focal haplotype.
chrom_indIndex for the focal chromosome.
posPosition at which to add the mutation.
ntsString 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_indIndex for the focal haplotype.
chrom_indIndex for the focal chromosome.
posPosition at which to add the mutation.
n_ntsSingle integer specifying the number of nucleotides to delete. These will be deleted starting at
pos. Ifposis near the chromosome end and doesn't haven_ntsnucleotides to remove, it simply removes nucleotides fromposto the chromosome end.
Returns
This R6 object, invisibly.