Skip to content

Commit

Permalink
Merge pull request #1473 from nextstrain/feat/dataset-capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-aksamentov authored Jun 4, 2024
2 parents feca45d + ea9c071 commit 259b5c6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
24 changes: 22 additions & 2 deletions packages/nextclade-cli/src/dataset/dataset_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ pub fn format_dataset_table(filtered: &[Dataset]) -> String {
.apply_modifier(UTF8_SOLID_INNER_BORDERS)
.set_content_arrangement(ContentArrangement::Dynamic);

table.set_header([o!("name"), o!("attributes"), o!("versions")]);
table.set_header([o!("name"), o!("attributes"), o!("versions"), o!("capabilities")]);

for dataset in filtered {
let Dataset {
path,
shortcuts,
attributes,
capabilities,
..
} = dataset;

Expand All @@ -45,7 +46,26 @@ pub fn format_dataset_table(filtered: &[Dataset]) -> String {

let versions = dataset.versions.iter().map(|ver| &ver.tag).join("\n");

table.add_row([&name, &attrs, &versions]);
let capabilities = {
let mut caps = vec![];
if let Some(n_clades) = capabilities.clades {
caps.push(format!("clade ({n_clades})"));
}

capabilities.custom_clades.iter().for_each(|(attr, n_attrs)| {
caps.push(format!("{attr} ({n_attrs})"));
});

capabilities.qc.iter().for_each(|rule| {
caps.push(format!("qc.{rule}"));
});

caps.extend_from_slice(&capabilities.other);

caps.join("\n")
};

table.add_row([&name, &attrs, &versions, &capabilities]);
}

table.to_string()
Expand Down
11 changes: 10 additions & 1 deletion packages/nextclade/src/io/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,23 @@ pub struct DatasetCollectionMeta {
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct DatasetCapabilities {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub clades: Option<usize>,

#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub custom_clades: BTreeMap<String, usize>,

#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub qc: Vec<String>,

#[serde(default, skip_serializing_if = "Option::is_none")]
pub primers: Option<bool>,

#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub other: Vec<String>,

#[serde(flatten)]
pub other: serde_json::Value,
pub rest: serde_json::Value,
}

impl DatasetCapabilities {
Expand Down

0 comments on commit 259b5c6

Please sign in to comment.