Skip to content

Commit

Permalink
Merge pull request #1330 from nextstrain/feat/dataset-name-shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-aksamentov authored Dec 7, 2023
2 parents 2972451 + 5eff749 commit d3e8b47
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages_rs/nextclade-cli/src/cli/nextclade_dataset_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn dataset_http_get(http: &mut HttpClient, name: impl AsRef<str>, tag: &Opti
})
// Filter by name
.filter(|dataset| {
dataset.path == name
dataset.path == name || dataset.shortcuts.contains(&String::from(name))
})
.collect_vec();

Expand Down
11 changes: 2 additions & 9 deletions packages_rs/nextclade-cli/src/cli/nextclade_dataset_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,14 @@ pub fn nextclade_dataset_list(
})
.filter(|dataset| {
if let Some(name) = &name {
name == &dataset.path
name == &dataset.path || dataset.shortcuts.contains(name)
} else {
true
}
})
.filter(|dataset| {
if let Some(search) = &search {
[
Some(dataset.path.as_str()),
dataset.name(),
dataset.ref_name(),
dataset.ref_accession(),
]
.iter()
.any(|candidate| candidate.unwrap_or_default().contains(search))
dataset.search_strings().any(|candidate| candidate.contains(search))
} else {
true
}
Expand Down
1 change: 1 addition & 0 deletions packages_rs/nextclade-cli/src/dataset/dataset_download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ pub fn dataset_individual_files_load(
VirusProperties {
schema_version: "".to_owned(),
attributes: BTreeMap::default(),
shortcuts: vec![],
meta: DatasetMeta::default(),
files: DatasetFiles {
reference: "".to_owned(),
Expand Down
17 changes: 15 additions & 2 deletions packages_rs/nextclade-cli/src/dataset/dataset_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use itertools::Itertools;
use nextclade::io::dataset::Dataset;
use nextclade::o;
use nextclade::utils::string::surround_with_quotes;
use std::borrow::Cow;

pub fn format_dataset_table(filtered: &[Dataset]) -> String {
let mut table = Table::new();
Expand All @@ -17,7 +18,19 @@ pub fn format_dataset_table(filtered: &[Dataset]) -> String {
table.set_header([o!("name"), o!("attributes"), o!("versions"), o!("authors")]);

for dataset in filtered.iter() {
let Dataset { attributes, .. } = dataset;
let Dataset {
path,
shortcuts,
attributes,
..
} = dataset;

let name = if !shortcuts.is_empty() {
let shortcuts = shortcuts.iter().map(surround_with_quotes).join(", ");
Cow::Owned(format!("{path}\n(shortcuts: {shortcuts})"))
} else {
Cow::Borrowed(path)
};

let attrs = attributes
.iter()
Expand All @@ -34,7 +47,7 @@ pub fn format_dataset_table(filtered: &[Dataset]) -> String {

let authors = dataset.meta.authors.join(", ");

table.add_row([&dataset.path, &attrs, &versions, &authors]);
table.add_row([&name, &attrs, &versions, &authors]);
}

table.to_string()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function DatasetSelectorList({
attrStrMaybe(dataset.attributes, 'name') ?? '',
attrStrMaybe(dataset.attributes, 'reference name') ?? '',
attrStrMaybe(dataset.attributes, 'reference accession') ?? '',
dataset.path,
...(dataset.shortcuts ?? []),
])
}, [datasetsActive, datasetsInactive, searchTerm])

Expand Down
4 changes: 2 additions & 2 deletions packages_rs/nextclade-web/src/io/fetchDatasetsIndex.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AxiosError } from 'axios'
import { get, head, mapValues, sortBy, sortedUniq } from 'lodash'
import { get, head, isNil, mapValues, sortBy, sortedUniq } from 'lodash'
import semver from 'semver'
import { takeFirstMaybe } from 'src/helpers/takeFirstMaybe'
import urljoin from 'url-join'
Expand Down Expand Up @@ -47,7 +47,7 @@ export function findDataset(datasets: Dataset[], name?: string, tag?: string) {
/** Find the datasets given name, ref and tag */
export function filterDatasets(datasets: Dataset[], name?: string, tag?: string) {
return datasets.filter((dataset) => {
let isMatch = dataset.path === name
let isMatch = !isNil(name) && (dataset.path === name || !!dataset.shortcuts?.includes(name))

if (tag) {
isMatch = isMatch && dataset.version?.tag === tag
Expand Down
3 changes: 3 additions & 0 deletions packages_rs/nextclade/src/analyze/virus_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ pub struct VirusProperties {
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub attributes: BTreeMap<String, AnyType>,

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

#[serde(default, skip_serializing_if = "DatasetMeta::is_default")]
pub meta: DatasetMeta,

Expand Down
19 changes: 18 additions & 1 deletion packages_rs/nextclade/src/io/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::io::schema_version::{SchemaVersion, SchemaVersionParams};
use crate::o;
use crate::utils::any::AnyType;
use eyre::Report;
use itertools::Itertools;
use itertools::{chain, Itertools};
use schemars::JsonSchema;
use semver::Version;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -57,6 +57,9 @@ pub struct DatasetCollection {
pub struct Dataset {
pub path: String,

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

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

Expand All @@ -83,6 +86,20 @@ impl Dataset {
self.attributes.get("name").and_then(AnyType::as_str_maybe)
}

pub fn search_strings(&self) -> impl Iterator<Item = &str> {
let names = [
Some(self.path.as_str()),
self.name(),
self.ref_name(),
self.ref_accession(),
]
.into_iter()
.flatten();

let shortcuts = self.shortcuts.iter().map(String::as_str);

chain!(names, shortcuts)
}
pub fn ref_name(&self) -> Option<&str> {
self.attributes.get("reference name").and_then(AnyType::as_str_maybe)
}
Expand Down

1 comment on commit d3e8b47

@vercel
Copy link

@vercel vercel bot commented on d3e8b47 Dec 7, 2023

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

Please sign in to comment.