pub fn nextclade_get_output_filenames(run_args: &mut NextcladeRunArgs) -> Result<(), Report> {
  let NextcladeRunArgs {
    inputs:
      NextcladeRunInputArgs {
        input_fastas,
        input_dataset,
        input_ref,
        input_tree,
        input_qc_config,
        input_virus_properties,
        input_pcr_primers,
        input_gene_map,
        genes,
        ..
      },
    outputs:
      NextcladeRunOutputArgs {
        output_all,
        output_basename,
        output_selection,
        output_fasta,
        output_translations,
        output_ndjson,
        output_json,
        output_csv,
        output_tsv,
        output_tree,
        output_insertions,
        output_errors,
        include_reference,
        in_order,
        ..
      },
    other: NextcladeRunOtherArgs { jobs },
    alignment_params,
  } = run_args;

  // If `--output-all` is provided, then we need to deduce default output filenames,
  // while taking care to preserve values of any individual `--output-*` flags,
  // as well as to honor restrictions put by the `--output-selection` flag, if provided.
  if let Some(output_all) = output_all {
    let output_basename = output_basename
      .clone()
      .unwrap_or_else(|| get_fasta_basename(input_fastas).unwrap_or_else(|| "nextclade".to_owned()));

    let default_output_file_path = output_all.join(&output_basename);

    // If `--output-selection` is empty or contains `all`, then fill it with all possible variants
    if output_selection.is_empty() || output_selection.contains(&NextcladeOutputSelection::All) {
      *output_selection = NextcladeOutputSelection::iter().collect_vec();
    }

    // We use `Option::get_or_insert()` mutable method here in order
    // to set default output filenames only if they are not provided.

    if output_selection.contains(&NextcladeOutputSelection::Fasta) {
      output_fasta.get_or_insert(default_output_file_path.with_extension("aligned.fasta"));
    }

    if output_selection.contains(&NextcladeOutputSelection::Insertions) {
      output_insertions.get_or_insert(default_output_file_path.with_extension("insertions.csv"));
    }

    if output_selection.contains(&NextcladeOutputSelection::Errors) {
      output_errors.get_or_insert(default_output_file_path.with_extension("errors.csv"));
    }

    if output_selection.contains(&NextcladeOutputSelection::Translations) {
      let output_translations_path = default_output_file_path
        .with_file_name(format!("{output_basename}_gene_{{gene}}"))
        .with_extension("translation.fasta");

      let output_translations_template = output_translations_path
        .to_str()
        .wrap_err_with(|| format!("When converting path to string: '{output_translations_path:?}'"))?
        .to_owned();

      output_translations.get_or_insert(output_translations_template);
    }

    if output_selection.contains(&NextcladeOutputSelection::Ndjson) {
      output_ndjson.get_or_insert(default_output_file_path.with_extension("ndjson"));
    }

    if output_selection.contains(&NextcladeOutputSelection::Json) {
      output_json.get_or_insert(default_output_file_path.with_extension("json"));
    }

    if output_selection.contains(&NextcladeOutputSelection::Csv) {
      output_csv.get_or_insert(default_output_file_path.with_extension("csv"));
    }

    if output_selection.contains(&NextcladeOutputSelection::Tsv) {
      output_tsv.get_or_insert(default_output_file_path.with_extension("tsv"));
    }

    if output_selection.contains(&NextcladeOutputSelection::Tree) {
      output_tree.get_or_insert(default_output_file_path.with_extension("auspice.json"));
    }
  }

  if let Some(output_translations) = output_translations {
    if !output_translations.contains("{gene}") {
      return make_error!(
        r#"
Expected `--output-translations` argument to contain a template string containing template variable {{gene}} (with curly braces), but received:

  {output_translations}

Make sure the variable is not substituted by your shell, programming language or workflow manager. Apply proper escaping as needed.
Example for bash shell:

  --output-translations='output_dir/gene_{{gene}}.translation.fasta'

      "#
      );
    }
  }

  let all_outputs_are_missing = [
    output_all,
    output_fasta,
    output_ndjson,
    output_json,
    output_csv,
    output_tsv,
    output_tree,
    output_insertions,
    output_errors,
  ]
  .iter()
  .all(|o| o.is_none())
    && output_translations.is_none();

  if all_outputs_are_missing {
    return make_error!(
      r#"No output flags provided.

At least one of the following flags is required:
  --output-all
  --output-fasta
  --output-ndjson
  --output-json
  --output-csv
  --output-tsv
  --output-tree
  --output-translations
  --output-insertions
  --output-errors"#
    );
  }

  Ok(())
}
/// Get output filenames provided by user or, if not provided, create filenames based on input fasta
Get output filenames provided by user or, if not provided, create filenames based on input fasta
Get output filenames provided by user or if not provided create filenames based on input fasta
pub fn nextclade_get_output_filenames(run_args: &mut NextcladeRunArgs) -> Result<(), Report> {
  let NextcladeRunArgs {
    inputs:
      NextcladeRunInputArgs {
        input_fastas,
        input_dataset,
        input_ref,
        input_tree,
        input_qc_config,
        input_virus_properties,
        input_pcr_primers,
        input_gene_map,
        genes,
        ..
      },
    outputs:
      NextcladeRunOutputArgs {
        output_all,
        output_basename,
        output_selection,
        output_fasta,
        output_translations,
        output_ndjson,
        output_json,
        output_csv,
        output_tsv,
        output_tree,
        output_insertions,
        output_errors,
        include_reference,
        in_order,
        ..
      },
    other: NextcladeRunOtherArgs { jobs },
    alignment_params,
  } = run_args;
  // If `--output-all` is provided, then we need to deduce default output filenames,
  // while taking care to preserve values of any individual `--output-*` flags,
  // as well as to honor restrictions put by the `--output-selection` flag, if provided.
  if let Some(output_all) = output_all {
    let output_basename = output_basename
      .clone()
      .unwrap_or_else(|| get_fasta_basename(input_fastas).unwrap_or_else(|| "nextclade".to_owned()));
    let default_output_file_path = output_all.join(&output_basename);
    // If `--output-selection` is empty or contains `all`, then fill it with all possible variants
    if output_selection.is_empty() || output_selection.contains(&NextcladeOutputSelection::All) {
      *output_selection = NextcladeOutputSelection::iter().collect_vec();
    }
    // We use `Option::get_or_insert()` mutable method here in order
    // to set default output filenames only if they are not provided.
    if output_selection.contains(&NextcladeOutputSelection::Fasta) {
      output_fasta.get_or_insert(default_output_file_path.with_extension("aligned.fasta"));
    }
    if output_selection.contains(&NextcladeOutputSelection::Insertions) {
      output_insertions.get_or_insert(default_output_file_path.with_extension("insertions.csv"));
    }
    if output_selection.contains(&NextcladeOutputSelection::Errors) {
      output_errors.get_or_insert(default_output_file_path.with_extension("errors.csv"));
    }
    if output_selection.contains(&NextcladeOutputSelection::Translations) {
      let output_translations_path = default_output_file_path
        .with_file_name(format!("{output_basename}_gene_{{gene}}"))
        .with_extension("translation.fasta");
      let output_translations_template = output_translations_path
        .to_str()
        .wrap_err_with(|| format!("When converting path to string: '{output_translations_path:?}'"))?
        .to_owned();
      output_translations.get_or_insert(output_translations_template);
    }
    if output_selection.contains(&NextcladeOutputSelection::Ndjson) {
      output_ndjson.get_or_insert(default_output_file_path.with_extension("ndjson"));
    }
    if output_selection.contains(&NextcladeOutputSelection::Json) {
      output_json.get_or_insert(default_output_file_path.with_extension("json"));
    }
    if output_selection.contains(&NextcladeOutputSelection::Csv) {
      output_csv.get_or_insert(default_output_file_path.with_extension("csv"));
    }
    if output_selection.contains(&NextcladeOutputSelection::Tsv) {
      output_tsv.get_or_insert(default_output_file_path.with_extension("tsv"));
    }
    if output_selection.contains(&NextcladeOutputSelection::Tree) {
      output_tree.get_or_insert(default_output_file_path.with_extension("auspice.json"));
    }
  }
  if let Some(output_translations) = output_translations {
    if !output_translations.contains("{gene}") {
      return make_error!(
        r#"
Expected `--output-translations` argument to contain a template string containing template variable {{gene}} (with curly braces), but received:
  {output_translations}
Make sure the variable is not substituted by your shell, programming language or workflow manager. Apply proper escaping as needed.
Example for bash shell:
  --output-translations='output_dir/gene_{{gene}}.translation.fasta'
      "#
      );
    }
  }
  let all_outputs_are_missing = [
    output_all,
    output_fasta,
    output_ndjson,
    output_json,
    output_csv,
    output_tsv,
    output_tree,
    output_insertions,
    output_errors,
  ]
  .iter()
  .all(|o| o.is_none())
    && output_translations.is_none();
  if all_outputs_are_missing {
    return make_error!(
      r#"No output flags provided.
At least one of the following flags is required:
  --output-all
  --output-fasta
  --output-ndjson
  --output-json
  --output-csv
  --output-tsv
  --output-tree
  --output-translations
  --output-insertions
  --output-errors"#
    );
  }
  Ok(())
}
pub fn nextclade_get_output_filenames ( run_args : & mut NextcladeRunArgs ) -> Result < ( ) , Report > { let NextcladeRunArgs { inputs : NextcladeRunInputArgs { input_fastas , input_dataset , input_ref , input_tree , input_qc_config , input_virus_properties , input_pcr_primers , input_gene_map , genes , .. } , outputs : NextcladeRunOutputArgs { output_all , output_basename , output_selection , output_fasta , output_translations , output_ndjson , output_json , output_csv , output_tsv , output_tree , output_insertions , output_errors , include_reference , in_order , .. } , other : NextcladeRunOtherArgs { jobs } , alignment_params , } = run_args ; // If `--output-all` is provided, then we need to deduce default output filenames, // while taking care to preserve values of any individual `--output-*` flags, // as well as to honor restrictions put by the `--output-selection` flag, if provided. if let Some ( output_all ) = output_all { let output_basename = output_basename . clone ( ) . unwrap_or_else ( | | get_fasta_basename ( input_fastas ) . unwrap_or_else ( | | " " . to_owned ( ) ) ) ; let default_output_file_path = output_all . join ( & output_basename ) ; // If `--output-selection` is empty or contains `all`, then fill it with all possible variants if output_selection . is_empty ( ) || output_selection . contains ( & NextcladeOutputSelection :: All ) { * output_selection = NextcladeOutputSelection :: iter ( ) . collect_vec ( ) ; } // We use `Option::get_or_insert()` mutable method here in order // to set default output filenames only if they are not provided. if output_selection . contains ( & NextcladeOutputSelection :: Fasta ) { output_fasta . get_or_insert ( default_output_file_path . with_extension ( " " ) ) ; } if output_selection . contains ( & NextcladeOutputSelection :: Insertions ) { output_insertions . get_or_insert ( default_output_file_path . with_extension ( " " ) ) ; } if output_selection . contains ( & NextcladeOutputSelection :: Errors ) { output_errors . get_or_insert ( default_output_file_path . with_extension ( " " ) ) ; } if output_selection . contains ( & NextcladeOutputSelection :: Translations ) { let output_translations_path = default_output_file_path . with_file_name ( format ! ( " " ) ) . with_extension ( " " ) ; let output_translations_template = output_translations_path . to_str ( ) . wrap_err_with ( | | format ! ( " " ) ) ? . to_owned ( ) ; output_translations . get_or_insert ( output_translations_template ) ; } if output_selection . contains ( & NextcladeOutputSelection :: Ndjson ) { output_ndjson . get_or_insert ( default_output_file_path . with_extension ( " " ) ) ; } if output_selection . contains ( & NextcladeOutputSelection :: Json ) { output_json . get_or_insert ( default_output_file_path . with_extension ( " " ) ) ; } if output_selection . contains ( & NextcladeOutputSelection :: Csv ) { output_csv . get_or_insert ( default_output_file_path . with_extension ( " " ) ) ; } if output_selection . contains ( & NextcladeOutputSelection :: Tsv ) { output_tsv . get_or_insert ( default_output_file_path . with_extension ( " " ) ) ; } if output_selection . contains ( & NextcladeOutputSelection :: Tree ) { output_tree . get_or_insert ( default_output_file_path . with_extension ( " " ) ) ; } } if let Some ( output_translations ) = output_translations { if ! output_translations . contains ( " " ) { return make_error ! ( r#"
Expected `--output-translations` argument to contain a template string containing template variable {{gene}} (with curly braces), but received:

  {output_translations}

Make sure the variable is not substituted by your shell, programming language or workflow manager. Apply proper escaping as needed.
Example for bash shell:

  --output-translations='output_dir/gene_{{gene}}.translation.fasta'

      "# ) ; } } let all_outputs_are_missing = [ output_all , output_fasta , output_ndjson , output_json , output_csv , output_tsv , output_tree , output_insertions , output_errors , ] . iter ( ) . all ( | o | o . is_none ( ) ) && output_translations . is_none ( ) ; if all_outputs_are_missing { return make_error ! ( r#"No output flags provided.

At least one of the following flags is required:
  --output-all
  --output-fasta
  --output-ndjson
  --output-json
  --output-csv
  --output-tsv
  --output-tree
  --output-translations
  --output-insertions
  --output-errors"# ) ; } Ok ( ( ) ) }
Get output filenames provided by user or, if not provided, create filenames based on input fasta
Get output filenames provided by user or if not provided create filenames based on input fasta
run_args
&mut NextcladeRunArgs
run_args
&mut NextcladeRunArgs