pub struct Decompressor { /* 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();Implementations§
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 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_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...
}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