-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1266 from nextstrain/feat/cli-read-annotation
- Loading branch information
Showing
6 changed files
with
102 additions
and
115 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages_rs/nextclade-cli/src/cli/nextclade_read_annotation.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use crate::cli::nextclade_cli::NextcladeReadAnnotationArgs; | ||
use eyre::Report; | ||
use nextclade::features::feature_tree::FeatureTree; | ||
use nextclade::gene::gene_map::GeneMap; | ||
use nextclade::gene::gene_map_display::gene_map_to_table_string; | ||
use nextclade::io::file::open_file_or_stdin; | ||
use nextclade::io::json::{json_or_yaml_write, json_stringify, JsonPretty}; | ||
use std::io::Read; | ||
|
||
pub fn nextclade_read_annotation(args: &NextcladeReadAnnotationArgs) -> Result<(), Report> { | ||
let content = { | ||
let mut content = String::new(); | ||
open_file_or_stdin(&args.input_annotation)?.read_to_string(&mut content)?; | ||
content | ||
}; | ||
|
||
if args.feature_tree { | ||
handle_feature_tree(args, &content) | ||
} else { | ||
handle_genome_annotation(args, &content) | ||
} | ||
} | ||
|
||
fn handle_genome_annotation(args: &NextcladeReadAnnotationArgs, content: &str) -> Result<(), Report> { | ||
let data = GeneMap::from_str(content)?; | ||
|
||
if args.json { | ||
println!("{}\n", json_stringify(&data, JsonPretty(true))?); | ||
} else { | ||
println!("{}", gene_map_to_table_string(&data)?); | ||
} | ||
|
||
if let Some(output) = &args.output { | ||
json_or_yaml_write(output, &data)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn handle_feature_tree(args: &NextcladeReadAnnotationArgs, content: &str) -> Result<(), Report> { | ||
let data = FeatureTree::from_gff3_str(content)?; | ||
|
||
if args.json { | ||
println!("{}\n", json_stringify(&data, JsonPretty(true))?); | ||
} else { | ||
println!("{}", data.to_pretty_string()?); | ||
} | ||
|
||
if let Some(output) = &args.output { | ||
json_or_yaml_write(output, &data)?; | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5fbe04c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nextclade – ./
nextclade-git-master-nextstrain.vercel.app
nextclade-nextstrain.vercel.app
nextclade.vercel.app