A Rust library for parsing the output CSV files of 10x Genomics *ranger pipelines.
Many of 10x Genomics data-processing pipelines produce CSV files that summarize the data. These CSVs, while human-readable, cannot be parsed by a machine without extra effort. This small crate provides the necessary functionality to parse the values in these files. See documentation at csvranger.
use csvranger::TenxCsvValue;
fn main() {
// Sample data from test-data/cellranger_multi.10.0
let raw_csv = b"Sample ID,Sample barcodes,Sample description,GEX: Cells,GEX: Confidently mapped reads in cells,GEX: Median UMI counts per cell,GEX: Median genes per cell,GEX: Total genes detected
SOD1_G93A_mouse_spinal_cord_P112_specimen_1,,SOD1-G93A mouse spinal cord from P112 mouse,16410,0.6847850295990157,2244,1305,27219";
let mut reader = csv::Reader::from_reader(&raw_csv[..]);
for line in reader.records() {
// Don't actually call .unwrap in production!
let line = line.unwrap();
for value in line.iter() {
// This is where the magic happens
TenxCsvValue::from_csv_value(value);
}
}
}use csvranger::TenxCsvValue;
use std::collections::HashMap;
fn main() {
// Sample data from test-data/cellranger_multi.10.0
let raw_csv = b"Sample ID,Sample barcodes,Sample description,GEX: Cells,GEX: Confidently mapped reads in cells,GEX: Median UMI counts per cell,GEX: Median genes per cell,GEX: Total genes detected
SOD1_G93A_mouse_spinal_cord_P112_specimen_1,,SOD1-G93A mouse spinal cord from P112 mouse,16410,0.6847850295990157,2244,1305,27219";
let mut reader = csv::Reader::from_reader(&raw_csv[..]);
let mut parsed_data: Vec<HashMap<String, TenxCsvValue>> = Vec::new();
for deserialized_record in reader.deserialize() {
parsed_data.push(deserialized_record.unwrap())
}
}legacy: If you are parsing CSV-files from legacy 10x Genomics pipelines, you'll need to activate this feature.serde: Support for serializing aTenxCsvValueusing serde. Note that if thelegacyfeature is enabled, this will deserialize usingTenxCsvValue::from_legacy_csv_value, which may use a small regular expression to extract numerical values from the data. If this behavior is surprising and undesired, please file an issue because it's not a decision I'm 100% sold-on.schemars: Support forschemars
You can add features to your project directly to your Cargo.toml:
csvranger = { version = "0.1.0", features = ["legacy"] }or using cargo:
cargo add csvranger --features legacyThe outputs of the following pipeline-version combinations are tested, though others likely work as well:
- cellranger 6
- cellranger 8
- cellranger 9
- cellranger 10
- celranger-atac 2
- spaceranger 4
More pipeline-version combinations will be added.
If you are parsing CSVs produced by cellranger < 10, you'll want to activate the legacy feature. The outputs of cellranger-atac < 2 and spaceranger < 4 are untested, but they likely do not require the legacy feature.