Interactive wrapper for a pointer to a C++ object that stores reference genome information.

Details

This class should NEVER be created using ref_genome$new. Only use read_fasta or create_genome. 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.

Methods


Method new()

Do NOT use this; only use read_fasta or create_genome to make a new ref_genome.

Usage

ref_genome$new(genome_ptr)

Arguments

genome_ptr

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


Method print()

Print a ref_genome object.

Usage

ref_genome$print()


Method ptr()

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

Usage

ref_genome$ptr()

Returns

An externalptr object.


Method n_chroms()

View number of chromosomes.

Usage

ref_genome$n_chroms()

Returns

Integer number of chromosomes.


Method sizes()

View chromosome sizes.

Usage

ref_genome$sizes()

Returns

Integer vector of chromosome sizes.


Method chrom_names()

View chromosome names.

Usage

ref_genome$chrom_names()

Returns

Character vector of chromosome names.


Method chrom()

View one reference chromosome.

Usage

ref_genome$chrom(chrom_ind)

Arguments

chrom_ind

Index for the focal chromosome.

Returns

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


Method gc_prop()

View GC proportion for part of one reference chromosome.

Usage

ref_genome$gc_prop(chrom_ind, start, end)

Arguments

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

Usage

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

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

Usage

ref_genome$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.

Examples

ref <- create_genome(4, 10)
ref$set_names(c("a", "b", "c", "d"))


Method clean_names()

Clean chromosome names, converting " :;=%,\\|/\"\'" to "_".

Usage

ref_genome$clean_names()

Returns

This R6 object, invisibly.

Examples

ref <- create_genome(4, 10)
ref$set_names(c("a:", "b|", "c;", "d'"))
ref$clean_names()


Method add_chroms()

Add one or more chromosomes.

Usage

ref_genome$add_chroms(new_chroms, new_names = NULL)

Arguments

new_chroms

Character vector of DNA strings representing new chromosomes.

new_names

Optional character vector of names for the new chromosomes. It should be the same length as new_chroms. If NULL, new names will be automatically generated. Defaults to NULL.

Returns

This R6 object, invisibly.

Examples

ref <- create_genome(4, 10)
ref$add_chroms("TCAGTCAG")


Method rm_chroms()

Remove one or more chromosomes by name

Usage

ref_genome$rm_chroms(chrom_names)

Arguments

chrom_names

Vector of the name(s) of the chromosome(s) to remove.

Returns

This R6 object, invisibly.

Examples

ref <- create_genome(4, 10)
ref$set_names(c("a", "b", "c", "d"))
ref$rm_chroms("b")


Method merge_chroms()

Merge chromosomes into one.

Usage

ref_genome$merge_chroms(chrom_names)

Arguments

chrom_names

Vector of the names of the chromosomes to merge into one. Duplicates are not allowed, and chromosomes are merged in the order they're provided. If this is NULL, then all chromosomes are merged after first shuffling their order.

Returns

This R6 object, invisibly.

Examples

ref <- create_genome(4, 10)
ref$merge_chroms(ref$chrom_names()[1:2])
ref$merge_chroms(NULL)


Method filter_chroms()

Filter chromosomes by size or for a proportion of total bases.

Usage

ref_genome$filter_chroms(threshold, method)

Arguments

threshold

Number used as a threshold. If method == "size", then this is the minimum length of a chromosome that will remain after filtering. If method == "prop", chromosomes are first size-sorted, then the largest N chromosomes are retained that allow at least threshold * sum(<all chromosome sizes>) base pairs remaining after filtering.

method

String indicating which filter method to use: chromosome size (method = "size") or proportion of total bases (method = "prop").

Returns

This R6 object, invisibly.

Examples

ref <- create_genome(4, 100, 50)
ref$filter_chroms(90, "size")
ref$filter_chroms(0.4, "prop")


Method replace_Ns()

Replace Ns in the reference genome.

Usage

ref_genome$replace_Ns(pi_tcag, n_threads = 1, show_progress = FALSE)

Arguments

pi_tcag

Numeric vector (length 4) indicating the sampling weights for T, C, A, and G, respectively, for generating new nucleotides with which to replace the Ns.

n_threads

Optional integer specifying the threads to use. Ignored if the package wasn't compiled with OpenMP. Defaults to 1.

show_progress

Optional logical indicating whether to show a progress bar. Defaults to FALSE.

Returns

This R6 object, invisibly.

Examples


## ------------------------------------------------
## Method `ref_genome$set_names`
## ------------------------------------------------

ref <- create_genome(4, 10)
ref$set_names(c("a", "b", "c", "d"))


## ------------------------------------------------
## Method `ref_genome$clean_names`
## ------------------------------------------------

ref <- create_genome(4, 10)
ref$set_names(c("a:", "b|", "c;", "d'"))
ref$clean_names()


## ------------------------------------------------
## Method `ref_genome$add_chroms`
## ------------------------------------------------

ref <- create_genome(4, 10)
ref$add_chroms("TCAGTCAG")

## ------------------------------------------------
## Method `ref_genome$rm_chroms`
## ------------------------------------------------

ref <- create_genome(4, 10)
ref$set_names(c("a", "b", "c", "d"))
ref$rm_chroms("b")


## ------------------------------------------------
## Method `ref_genome$merge_chroms`
## ------------------------------------------------

ref <- create_genome(4, 10)
ref$merge_chroms(ref$chrom_names()[1:2])
ref$merge_chroms(NULL)


## ------------------------------------------------
## Method `ref_genome$filter_chroms`
## ------------------------------------------------

ref <- create_genome(4, 100, 50)
ref$filter_chroms(90, "size")
#> Error: Desired minimum chromosome size is too large. None found. The largest chromosome is 65
ref$filter_chroms(0.4, "prop")