Skip to main content

RegionSet

Struct RegionSet 

Source
pub struct RegionSet {
    pub regions: Vec<Region>,
    pub header: Option<String>,
    pub path: Option<PathBuf>,
}
Expand description

RegionSet struct, the representation of the interval region set file, such as bed file.

Fields§

§regions: Vec<Region>§header: Option<String>§path: Option<PathBuf>

Implementations§

Source§

impl RegionSet

Source

pub fn to_bed<T: AsRef<Path>>(&self, path: T) -> Result<()>

Save a regionset to disk as bed file

§Arguments
  • path: the path to the file to dump to
Source

pub fn to_bed_gz<T: AsRef<Path>>(&self, path: T) -> Result<()>

Save a regionset to disk as bed.gz file

§Arguments
  • path: the path to the file to dump to
Source

pub fn identifier(&self) -> String

Calculate identifier for RegionSet

This function doesn’t sort file, and identifer is based on unsorted first 3 columns.

§Returns

String containing RegionSet identifier

Source

pub fn file_digest(&self) -> String

Source

pub fn iter_chroms(&self) -> impl Iterator<Item = &String>

Iterate unique chromosomes located in RegionSet

Source

pub fn iter_chr_regions<'a>( &'a self, chr: &'a str, ) -> impl Iterator<Item = &'a Region>

Iterate through regions located on specific Chromosome in RegionSet

§Arguments
  • chr: chromosome name
Source

pub fn sort(&mut self)

Sort bed file based on first 3 columns. Sorting is happening inside the object, where original order will be overwritten

Source

pub fn is_empty(&self) -> bool

Is regionSet empty?

Source

pub fn region_widths(&self) -> Vec<u32>

Calculate all regions width

Source

pub fn mean_region_width(&self) -> f64

Calculate mean region width for whole RegionSet

Source

pub fn calc_mid_points(&self) -> HashMap<String, Vec<u32>>

Calculate middle point for each region, and return hashmap with midpoints for each chromosome

Source

pub fn calc_mid_points_with_mode( &self, mode: CoordinateMode, ) -> HashMap<String, Vec<u32>>

Calculate midpoints using the specified coordinate convention.

See Region::mid_point_with_mode for details on how each mode computes the midpoint.

Source

pub fn len(&self) -> usize

Get number of regions in RegionSet

Returns: number of regions

Source

pub fn get_max_end_per_chr(&self) -> HashMap<String, u32>

Get the furthest region location for each region

Source

pub fn nucleotides_length(&self) -> u32

Get total nucleotide count

Source§

impl RegionSet

Source

pub fn reduce(&self) -> RegionSet

Merge overlapping and adjacent intervals per chromosome.

Sorts by (chr, start), then sweeps to merge intervals where next.start <= current.end. Returns a minimal set of non-overlapping regions.

Source

pub fn concat(&self, other: &RegionSet) -> RegionSet

Combine two region sets without merging overlapping intervals.

Source

pub fn concat_into(self, other: RegionSet) -> RegionSet

Combine two region sets without merging overlapping intervals, consuming both sets.

Like RegionSet::concat, but takes ownership of self and other so the backing Vec<Region>s are moved instead of cloned. Prefer this when neither input is needed afterward. As with concat, the resulting set has no header or path (it is a pure-regions set).

Source

pub fn union(&self, other: &RegionSet) -> RegionSet

Merge two region sets into a minimal non-overlapping set.

Equivalent to self.concat(other).reduce().

Source

pub fn union_into(self, other: RegionSet) -> RegionSet

Merge two region sets into a minimal non-overlapping set, consuming both.

Equivalent to self.concat_into(other).reduce(). Saves the concat-stage clones that RegionSet::union incurs; reduce still allocates internally.

Source

pub fn trim(&self, chrom_sizes: &HashMap<String, u32>) -> RegionSet

Clamp regions to chromosome boundaries.

Source

pub fn gaps(&self, chrom_sizes: &HashMap<String, u32>) -> RegionSet

Return the gaps between regions per chromosome, bounded by chromosome sizes.

Reduces the input first, then emits intervals that tile the peak-free regions of each chromosome listed in chrom_sizes:

  • a leading gap from position 0 to the first region’s start (omitted if the first region starts at 0),
  • an inter-region gap between each consecutive pair of reduced regions,
  • a trailing gap from the last region’s end to the chromosome size (omitted if the last region already reaches the chromosome end, or extends past it due to assembly mismatch),
  • a full-chromosome gap 0..chrom_size for any chromosome in chrom_sizes that has no regions at all.

Regions on chromosomes not present in chrom_sizes are skipped. Regions that extend past the stated chromosome size are clipped to chrom_size when computing the trailing gap, matching the clipping behavior of trim().

Source

pub fn shift(&self, offset: i64) -> RegionSet

Shift all regions by a fixed offset.

Source

pub fn flank(&self, width: u32, use_start: bool, both: bool) -> RegionSet

Generate flanking regions.

Source

pub fn resize(&self, width: u32, fix: &str) -> RegionSet

Resize regions to a fixed width, anchored at start, end, or center.

Source

pub fn narrow( &self, start: Option<u32>, end: Option<u32>, width: Option<u32>, ) -> RegionSet

Narrow each region by specifying a relative sub-range within it.

Source

pub fn promoters(&self, upstream: u32, downstream: u32) -> RegionSet

Generate promoter regions relative to each region’s start position.

Source

pub fn pintersect(&self, other: &RegionSet) -> RegionSet

Pairwise intersection of two region sets by index position.

Source

pub fn disjoin(&self) -> RegionSet

Break all regions into non-overlapping disjoint pieces.

Internal boundaries (starts and ends of overlapping input regions) split the covered intervals into non-overlapping pieces. Only pieces that are covered by at least one input region are emitted; gaps between disjoint regions are never filled. This matches the semantics of R’s GenomicRanges disjoin.

Source

pub fn cluster(&self, max_gap: u32) -> Vec<u32>

Cluster nearby regions.

Source

pub fn closest(&self, other: &RegionSet) -> Vec<(usize, usize, i64)>

Find the nearest region in other for each region in self.

Trait Implementations§

Source§

impl Clone for RegionSet

Source§

fn clone(&self) -> RegionSet

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RegionSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RegionSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&[u8]> for RegionSet

Source§

fn from(value: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Region>> for RegionSet

Source§

fn from(regions: Vec<Region>) -> Self

Converts to this type from the input type.
Source§

impl IntervalSetOps for RegionSet

Source§

fn setdiff(&self, other: &RegionSet) -> RegionSet

Set difference: remove portions of self that overlap with other.
Source§

fn intersect(&self, other: &RegionSet) -> RegionSet

Range-level intersection: positions covered by both sets.
Source§

fn jaccard(&self, other: &RegionSet) -> f64

Nucleotide-level Jaccard similarity: |intersection| / |union|.
Source§

fn coverage(&self, other: &RegionSet) -> f64

Fraction of self’s base pairs covered by other.
Source§

fn overlap_coefficient(&self, other: &RegionSet) -> f64

Overlap coefficient: |intersection| / min(|self|, |other|).
Source§

fn closest(&self, other: &RegionSet) -> Vec<(usize, usize, i64)>

Find the nearest region in other for each region in self. Read more
Source§

impl<'a> IntoIterator for &'a RegionSet

Source§

type Item = &'a Region

The type of the elements being iterated over.
Source§

type IntoIter = RegionSetIterator<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl TryFrom<&Path> for RegionSet

Source§

fn try_from(value: &Path) -> Result<Self, RegionSetError>

Create a new RegionSet from a bed file.

§Arguments:
  • value: path to bed file on disk.
Source§

type Error = RegionSetError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&str> for RegionSet

Source§

type Error = RegionSetError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &str) -> Result<Self, RegionSetError>

Performs the conversion.
Source§

impl TryFrom<PathBuf> for RegionSet

Source§

type Error = RegionSetError

The type returned in the event of a conversion error.
Source§

fn try_from(value: PathBuf) -> Result<Self, RegionSetError>

Performs the conversion.
Source§

impl TryFrom<String> for RegionSet

Source§

type Error = RegionSetError

The type returned in the event of a conversion error.
Source§

fn try_from(value: String) -> Result<Self, RegionSetError>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.