pub struct Decompressor {
pub kmer_length: u32,
pub min_match_len: u32,
/* private fields */
}Expand description
AGC Decompressor
Provides thread-safe read access to AGC archives.
For concurrent access, use clone_for_thread() to create independent readers.
§Thread Safety
Decompressoris NOTSync- cannot be shared between threads- Use
clone_for_thread()to create independent readers (cheap - shares archive data) - Each clone can be used from a separate thread independently
§Example
use ragc_core::{Decompressor, DecompressorConfig};
use std::thread;
let dec = Decompressor::open("data.agc", DecompressorConfig::default())?;
let samples = dec.list_samples();
let handles: Vec<_> = samples.into_iter().map(|sample_name| {
let mut thread_dec = dec.clone_for_thread().unwrap();
thread::spawn(move || {
thread_dec.get_sample(&sample_name)
})
}).collect();Fields§
§kmer_length: u32§min_match_len: u32Implementations§
Source§impl Decompressor
impl Decompressor
Sourcepub fn open(archive_path: &str, config: DecompressorConfig) -> Result<Self>
pub fn open(archive_path: &str, config: DecompressorConfig) -> Result<Self>
Open an existing archive for decompression
Sourcepub fn list_samples(&self) -> Vec<String>
pub fn list_samples(&self) -> Vec<String>
Get list of samples in the archive
Sourcepub fn get_compression_stats(&self) -> Vec<(String, u64, u64, usize)>
pub fn get_compression_stats(&self) -> Vec<(String, u64, u64, usize)>
Get compression statistics for all streams Returns: Vec<(stream_name, raw_size, packed_size, num_parts)>
Sourcepub fn list_contigs(&mut self, sample_name: &str) -> Result<Vec<String>>
pub fn list_contigs(&mut self, sample_name: &str) -> Result<Vec<String>>
Get list of contigs for a specific sample
Sourcepub fn get_contig(
&mut self,
sample_name: &str,
contig_name: &str,
) -> Result<Contig>
pub fn get_contig( &mut self, sample_name: &str, contig_name: &str, ) -> Result<Contig>
Extract a specific contig from a sample
Sourcepub fn get_contig_segments_desc(
&mut self,
sample_name: &str,
contig_name: &str,
) -> Result<Vec<SegmentDesc>>
pub fn get_contig_segments_desc( &mut self, sample_name: &str, contig_name: &str, ) -> Result<Vec<SegmentDesc>>
Public: get segment descriptors for a contig
Sourcepub fn get_segment_data_by_desc(&mut self, desc: &SegmentDesc) -> Result<Contig>
pub fn get_segment_data_by_desc(&mut self, desc: &SegmentDesc) -> Result<Contig>
Public: get raw segment data for a specific segment descriptor
Sourcepub fn get_reference_segment(&mut self, group_id: u32) -> Result<Contig>
pub fn get_reference_segment(&mut self, group_id: u32) -> Result<Contig>
Public: get the reference segment for a group (loads and caches if needed)
Sourcepub fn get_sample(&mut self, sample_name: &str) -> Result<Vec<(String, Contig)>>
pub fn get_sample(&mut self, sample_name: &str) -> Result<Vec<(String, Contig)>>
Extract all contigs from a sample
Sourcepub fn list_samples_with_prefix(&self, prefix: &str) -> Vec<String>
pub fn list_samples_with_prefix(&self, prefix: &str) -> Vec<String>
Get all sample names that match a given prefix
This is useful for extracting all samples from a specific genome or haplotype.
§Example
use ragc_core::{Decompressor, DecompressorConfig};
let dec = Decompressor::open("data.agc", DecompressorConfig::default())?;
// Get all samples starting with "AAA"
let aaa_samples = dec.list_samples_with_prefix("AAA");
// Returns: ["AAA#0", "AAA#1", ...] if they exist
// Get all samples with haplotype 0
let hap0_samples = dec.list_samples_with_prefix("AAA#0");Sourcepub fn get_samples_by_prefix(
&mut self,
prefix: &str,
) -> Result<HashMap<String, Vec<(String, Contig)>>>
pub fn get_samples_by_prefix( &mut self, prefix: &str, ) -> Result<HashMap<String, Vec<(String, Contig)>>>
Extract multiple samples matching a prefix
Returns a HashMap mapping sample names to their contigs. Each contig is represented as (contig_name, sequence).
§Example
use ragc_core::{Decompressor, DecompressorConfig};
let mut dec = Decompressor::open("data.agc", DecompressorConfig::default())?;
// Extract all AAA samples
let aaa_samples = dec.get_samples_by_prefix("AAA")?;
for (sample_name, contigs) in aaa_samples {
println!("Sample {}: {} contigs", sample_name, contigs.len());
for (contig_name, sequence) in contigs {
println!(" {}: {} bp", contig_name, sequence.len());
}
}Sourcepub fn clone_for_thread(&self) -> Result<Self>
pub fn clone_for_thread(&self) -> Result<Self>
Clone this decompressor for use in another thread
This creates an independent reader that can be used from a different thread. The clone is lightweight as it shares the archive data structure.
§Thread Safety
Each clone is fully independent and can be used from a separate thread. The segment cache is NOT shared between clones.
§Example
use ragc_core::{Decompressor, DecompressorConfig};
use std::thread;
let dec = Decompressor::open("data.agc", DecompressorConfig::default())?;
let samples = dec.list_samples();
// Spawn threads to extract samples in parallel
let handles: Vec<_> = samples.into_iter().map(|sample_name| {
let mut thread_dec = dec.clone_for_thread().unwrap();
thread::spawn(move || {
thread_dec.get_sample(&sample_name)
})
}).collect();
// Collect results
for handle in handles {
let result = handle.join().unwrap()?;
// Process result...
}Sourcepub fn write_sample_fasta(
&mut self,
sample_name: &str,
output_path: &Path,
) -> Result<()>
pub fn write_sample_fasta( &mut self, sample_name: &str, output_path: &Path, ) -> Result<()>
Write a sample to a FASTA file
Sourcepub fn get_group_statistics(
&mut self,
) -> Result<Vec<(u32, usize, usize, usize)>>
pub fn get_group_statistics( &mut self, ) -> Result<Vec<(u32, usize, usize, usize)>>
Get archive inspection data for debugging/comparison Returns: (group_id, num_segments, num_reference_segments, num_delta_segments)
Sourcepub fn get_all_segments(
&mut self,
) -> Result<Vec<(String, String, Vec<SegmentDesc>)>>
pub fn get_all_segments( &mut self, ) -> Result<Vec<(String, String, Vec<SegmentDesc>)>>
Get detailed segment information for all contigs
Returns: Vec<(sample_name, contig_name, Vec
Auto Trait Implementations§
impl Freeze for Decompressor
impl RefUnwindSafe for Decompressor
impl Send for Decompressor
impl Sync for Decompressor
impl Unpin for Decompressor
impl UnwindSafe for Decompressor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more