Skip to content

Commit

Permalink
Rip out entirely-unused metrics loading code.
Browse files Browse the repository at this point in the history
  • Loading branch information
macklin-10x committed Apr 18, 2024
1 parent 1772129 commit a27c913
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 125 deletions.
27 changes: 0 additions & 27 deletions enclone_args/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,3 @@ pub mod proc_args_post;
pub mod process_special_arg1;
pub mod process_special_arg2;
pub mod read_json;

// parse_csv_pure: same as parse_csv, but don't strip out quotes

pub fn parse_csv_pure(x: &str) -> Vec<&str> {
let w = x.char_indices().collect::<Vec<_>>();
let mut y = Vec::new();
let (mut quotes, mut i) = (0, 0);
while i < w.len() {
let mut j = i;
while j < w.len() {
if quotes % 2 == 0 && w[j].1 == ',' {
break;
}
if w[j].1 == '"' {
quotes += 1;
}
j += 1;
}
let (start, stop) = (w[i].0, w.get(j).map_or(x.len(), |(ind, _)| *ind));
y.push(&x[start..stop]);
i = j + 1;
}
if !w.is_empty() && w.last().unwrap().1 == ',' {
y.push("");
}
y
}
3 changes: 0 additions & 3 deletions enclone_args/src/load_gex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub fn get_gex_info(ctl: &mut EncloneControl) -> Result<GexInfo, String> {
let mut h5_paths = Vec::<String>::new();
let mut feature_metrics = Vec::<HashMap<(String, String), String>>::new();
let mut json_metrics = Vec::<HashMap<String, f64>>::new();
let mut metrics = Vec::<String>::new();
load_gex(
ctl,
&mut gex_features,
Expand All @@ -48,7 +47,6 @@ pub fn get_gex_info(ctl: &mut EncloneControl) -> Result<GexInfo, String> {
&mut h5_paths,
&mut feature_metrics,
&mut json_metrics,
&mut metrics,
)?;
if ctl.gen_opt.gene_scan.is_some() && !ctl.gen_opt.accept_inconsistent {
let mut allf = gex_features.clone();
Expand Down Expand Up @@ -151,6 +149,5 @@ pub fn get_gex_info(ctl: &mut EncloneControl) -> Result<GexInfo, String> {
have_fb,
feature_metrics,
json_metrics,
metrics,
})
}
81 changes: 3 additions & 78 deletions enclone_args/src/load_gex_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
// Load gene expression and feature barcoding (antibody, antigen) data from Cell Ranger outputs.

use crate::load_gex_util::{
find_cluster_file, find_feature_metrics_file, find_json_metrics_file, find_metrics_file,
find_pca_file,
find_cluster_file, find_feature_metrics_file, find_json_metrics_file, find_pca_file,
};
use crate::parse_csv_pure;
use enclone_core::defs::EncloneControl;
use enclone_core::slurp::slurp_h5;
use io_utils::{dir_list, open_for_read, open_userfile_for_read, path_exists};
use itertools::Itertools;
use rayon::prelude::*;
use serde_json::Value;
use std::{collections::HashMap, fmt::Write, io::BufRead};
use std::{collections::HashMap, io::BufRead};
use string_utils::{parse_csv, TextUtils};
use vector_utils::{unique_sort, VecUtils};

Expand All @@ -32,7 +29,6 @@ struct LoadResult {
h5_path: String,
feature_metrics: HashMap<(String, String), String>,
json_metrics: HashMap<String, f64>,
metrics: String,
}

pub fn load_gex(
Expand All @@ -51,7 +47,6 @@ pub fn load_gex(
h5_paths: &mut Vec<String>,
feature_metrics: &mut Vec<HashMap<(String, String), String>>,
json_metrics: &mut Vec<HashMap<String, f64>>,
metrics: &mut Vec<String>,
) -> Result<(), String> {
let mut results = Vec::<(usize, LoadResult)>::new();
for i in 0..ctl.origin_info.gex_path.len() {
Expand Down Expand Up @@ -139,10 +134,9 @@ pub fn load_gex(
let pca_file = find_pca_file(&analysis);
let cluster_file = find_cluster_file(&analysis);

let (json_metrics_file, feature_metrics_file, metrics_file) = if !ctl.cr_opt.cellranger {(
let (json_metrics_file, feature_metrics_file) = if !ctl.cr_opt.cellranger {(
find_json_metrics_file(&analysis),
find_feature_metrics_file(&analysis),
find_metrics_file(&outs)
)} else {
Default::default()
};
Expand Down Expand Up @@ -245,38 +239,6 @@ pub fn load_gex(
}
}

// Read and parse metrics file. Rewrite as metrics class, metric name, metric value.

if !metrics_file.is_empty() {
let m = std::fs::read_to_string(&metrics_file).unwrap();
let fields = parse_csv_pure(m.before("\n"));
let (mut class, mut name, mut value) = (None, None, None);
for field in fields {
if field == "Library Type" {
class = Some(i);
} else if field == "Metric Name" {
name = Some(i);
} else if field == "Metric Value" {
value = Some(i);
}
}
let (class, name, value) = (class.unwrap(), name.unwrap(), value.unwrap());
let mut lines = Vec::<String>::new();
let mut first = true;
for line in m.lines() {
if first {
first = false;
} else {
let fields = parse_csv_pure(line);
lines.push(format!(
"{},{},{}",
fields[class], fields[name], fields[value]
));
}
}
r.metrics = format!("{}\n", lines.iter().format("\n"));
}

// Read feature metrics file. Note that we do not enforce the requirement of this
// file, so it may not be present.

Expand Down Expand Up @@ -561,42 +523,6 @@ pub fn load_gex(
}
h5_paths.extend(results.iter().map(|(_, r)| r.h5_path.clone()));

// Add some metrics.

let extras = [
(
"ANTIBODY_G_perfect_homopolymer_frac",
"Antibody Capture,G Homopolymer Frac",
),
(
"GRCh38_raw_rpc_20000_subsampled_filtered_bcs_median_unique_genes_detected",
"Gene Expression,GRCh38 Median genes per cell (20k raw reads per cell)",
),
(
"GRCh38_raw_rpc_20000_subsampled_filtered_bcs_median_counts",
"Gene Expression,GRCh38 Median UMI counts per cell (20k raw reads per cell)",
),
];
for x in &extras {
let metric_name = x.0.to_string();
let metric_display_name = x.1.to_string();
let mut have = false;
for (_, result) in &results {
if result.json_metrics.contains_key(&metric_name) {
have = true;
}
}
if have {
for (_, result) in &mut results {
let mut value = String::new();
if result.json_metrics.contains_key(&metric_name) {
value = format!("{:.3}", result.json_metrics[&metric_name]);
}
writeln!(result.metrics, "{metric_display_name},{value}").unwrap();
}
}
}

for (_, r) in results {
gex_features.push(r.gex_features);
gex_barcodes.push(r.gex_barcodes);
Expand All @@ -609,7 +535,6 @@ pub fn load_gex(
cell_type_specified.push(r.cell_type_specified);
feature_metrics.push(r.feature_metrics);
json_metrics.push(r.json_metrics);
metrics.push(r.metrics);
}

// Done.
Expand Down
17 changes: 1 addition & 16 deletions enclone_args/src/load_gex_util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2022 10X Genomics, Inc. All rights reserved.

use io_utils::{dir_list, path_exists};
use vector_utils::VecUtils;
use io_utils::path_exists;

pub fn find_pca_file(analysis: &[String]) -> String {
let mut pca_file = String::new();
Expand Down Expand Up @@ -44,20 +43,6 @@ pub fn find_feature_metrics_file(analysis: &[String]) -> String {
feature_metrics_file
}

pub fn find_metrics_file(outs: &str) -> String {
let mut metrics_file = String::new();
let summary_dir = format!("{outs}/../multi_web_summary_json/metrics_summary_csv");
if path_exists(&summary_dir) {
let list = dir_list(&summary_dir);
if list.solo() {
let path = format!("{summary_dir}/{}", list[0]);
metrics_file = path;
}
}

metrics_file
}

pub fn find_cluster_file(analysis: &[String]) -> String {
let mut cluster_file = String::new();
for x in analysis {
Expand Down
1 change: 0 additions & 1 deletion enclone_core/src/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,6 @@ pub struct GexInfo {
pub have_fb: bool,
pub feature_metrics: Vec<HashMap<(String, String), String>>,
pub json_metrics: Vec<HashMap<String, f64>>,
pub metrics: Vec<String>,
}

// Every entry in a ColInfo is a vector whose number of entries is the number of chains
Expand Down

0 comments on commit a27c913

Please sign in to comment.