From 5869b1b9f7f76b6fda4430fd1046820e7a54e388 Mon Sep 17 00:00:00 2001 From: an-altosian Date: Wed, 5 Feb 2025 20:23:08 +0000 Subject: [PATCH] add gene_id_to_name file to index folder --- src/simpleaf_commands/indexing.rs | 13 +++++++++++-- src/simpleaf_commands/quant.rs | 4 +++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/simpleaf_commands/indexing.rs b/src/simpleaf_commands/indexing.rs index a589c14..4915a37 100644 --- a/src/simpleaf_commands/indexing.rs +++ b/src/simpleaf_commands/indexing.rs @@ -264,7 +264,7 @@ pub fn build_ref_and_index(af_home_path: &Path, opts: IndexOpts) -> anyhow::Resu // these may or may not be set, so must be // mutable. let mut t2g = None; - let mut _gene_id_to_name = None; + let mut gene_id_to_name = None; let mut roers_duration = None; let mut roers_aug_ref_opt = None; let outref = output.join("ref"); @@ -334,7 +334,7 @@ pub fn build_ref_and_index(af_home_path: &Path, opts: IndexOpts) -> anyhow::Resu reference_sequence = Some(ref_file); // set the splici_t2g option t2g = Some(t2g_file); - _gene_id_to_name = Some(gene_id_to_name_file); + gene_id_to_name = Some(gene_id_to_name_file); } else if let Some(ref_seq) = &opts.ref_seq { // if we have a ref-seq fasta file min_seq_len = None; @@ -669,11 +669,20 @@ simpleaf"#, std::fs::copy(t2g_file, index_t2g_path)?; } + // copy over the gene_id_to_name.tsv file to the index + let mut gene_id_to_name_out_path: Option = None; + if let Some(gene_id_to_name_file) = gene_id_to_name { + let index_id2name_path = output_index_dir.join("gene_id_to_name.tsv"); + gene_id_to_name_out_path = Some(PathBuf::from("gene_id_to_name.tsv")); + std::fs::copy(gene_id_to_name_file, index_id2name_path)?; + } + let index_json_file = output_index_dir.join("simpleaf_index.json"); let index_json = json!({ "cmd" : index_cmd_string, "index_type" : "salmon", "t2g_file" : t2g_out_path, + "gene_id_to_name_file" : gene_id_to_name_out_path, "salmon_index_parameters" : { "k" : opts.kmer_length, "overwrite" : opts.overwrite, diff --git a/src/simpleaf_commands/quant.rs b/src/simpleaf_commands/quant.rs index aa574e4..8fc02b4 100644 --- a/src/simpleaf_commands/quant.rs +++ b/src/simpleaf_commands/quant.rs @@ -323,7 +323,9 @@ pub fn map_and_quant(af_home_path: &Path, opts: MapQuantOpts) -> anyhow::Result< // if the user used simpleaf for index construction, then we also built the // reference and populated the gene_id_to_name.tsv file. See if we can grab // that as well. - if let Some(index_parent) = index.parent() { + if index.join("gene_id_to_name.tsv").exists() { + gene_id_to_name_opt = Some(index.join("gene_id_to_name.tsv")); + } else if let Some(index_parent) = index.parent() { // we are doing index_dir/../ref/gene_id_to_name.tsv let gene_name_path = index_parent.join("ref").join("gene_id_to_name.tsv"); if gene_name_path.exists() && gene_name_path.is_file() {