Skip to content

Commit

Permalink
2024/10/27-17:26:20 (Linux VDI0092.zit.bam.de x86_64)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbenner committed Oct 27, 2024
1 parent 5783971 commit 7c0d81f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/granges_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ use crate::granges_find_endpoint::{EndPoint, EndPointList};

impl GRanges {

/// Merges overlapping or contiguous genomic ranges from the given `GRanges` object.
///
/// This function processes an `EndPointList` for a specific sequence name, combining
/// overlapping and contiguous intervals into larger ranges. The resulting ranges are appended
/// to the provided `GRanges` object.
///
/// # Arguments
/// - `r`: A reference to a `GRanges` object where the merged ranges will be appended.
/// - `seqname`: A string representing the name of the genomic sequence being processed.
/// - `entry`: A reference to an `EndPointList`, which contains the start and end points of genomic ranges.
///
/// # Returns
/// A `GRanges` object containing the merged ranges from the specified sequence name.
///
/// # Panics
/// This function will panic if it encounters an invalid state in the `EndPointList`,
/// specifically if it does not start with a start position.
fn merge_impl(r: &GRanges, seqname: String, entry: &EndPointList) -> GRanges {

let mut seqnames = vec![];
Expand Down Expand Up @@ -65,6 +82,29 @@ impl GRanges {
r.append(&GRanges::new(seqnames, from, to, vec![])).unwrap()
}

/// Merges a collection of `GRanges` objects into a single `GRanges` object.
///
/// This function iterates through a slice of `GRanges`, collects start and end points for each range,
/// and merges overlapping or contiguous ranges based on sequence names. The resulting merged ranges are returned.
///
/// # Arguments
/// - `granges`: A slice of `GRanges` objects to be merged.
///
/// # Returns
/// A new `GRanges` object containing the merged ranges.
///
/// # Example
/// ```
/// use rustynetics::granges::GRanges;
///
/// let seqnames = vec!["chr1", "chr1", "chr1", "chr2", "chr2"].iter().map(|&x| x.into()).collect();
/// let from = vec![6, 10, 24, 6, 10];
/// let to = vec![21, 31, 81, 21, 31];
/// let strand = vec![];
///
/// let granges = GRanges::new(seqnames, from, to, strand);
/// let merged = GRanges::merge(&[granges]);
/// ```
pub fn merge(granges: &[GRanges]) -> GRanges {

let mut r = GRanges::default();
Expand Down

0 comments on commit 7c0d81f

Please sign in to comment.