Skip to content

Commit

Permalink
Merge pull request #312 from theosanderson/nextstrain
Browse files Browse the repository at this point in the history
Joint with @amkram (who did most of the heavy lifting)
  • Loading branch information
theosanderson authored Jul 28, 2022
2 parents f375446 + 50e8778 commit bd80976
Show file tree
Hide file tree
Showing 7 changed files with 511 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"infra"
]
}

],
"contributorsPerLine": 7,
"projectName": "taxonium",
Expand Down
24 changes: 21 additions & 3 deletions taxonium_web_client/src/Taxonium.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { useMemo, useState } from "react";
import useBackend from "./hooks/useBackend";
import useConfig from "./hooks/useConfig";
import { useSettings } from "./hooks/useSettings";
import { useEffect } from "react";
import { useCallback } from "react";

const URL_ON_FAIL = window.location.hostname.includes(".epicov.org")
? "https://www.epicov.org/epi3/frontend"
Expand Down Expand Up @@ -54,13 +56,29 @@ function Taxonium({
const colorHook = useColor(colorMapping);

const xType = query.xType;
const setxType = (xType) => {
updateQuery({ xType });
};
const setxType = useCallback(
(xType) => {
updateQuery({ xType });
},
[updateQuery]
);

const { data, boundsForQueries, isCurrentlyOutsideBounds } =
useGetDynamicData(backend, colorBy, view.viewState, config, xType);

useEffect(() => {
// If there is no distance data, default to time
// This can happen with e.g. nextstrain json
if (data.base_data && data.base_data.nodes) {
const n = data.base_data.nodes[0];
if (!n.hasOwnProperty("x_dist")) {
setxType("x_time");
} else if (!n.hasOwnProperty("x_time")) {
setxType("x_dist");
}
}
}, [data.base_data, setxType]);

const search = useSearch({
data,
config,
Expand Down
2 changes: 2 additions & 0 deletions taxonium_web_client/src/components/InputSupplier.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const prettyTypes = {
nwk: "Newick tree",
meta_tsv: "Metadata TSV",
meta_csv: "Metadata CSV",
nextstrain: "Nextstrain JSON",
unknown: "Unknown (please select)",
};
const fileTypes = Object.keys(prettyTypes);

Expand Down
27 changes: 19 additions & 8 deletions taxonium_web_client/src/hooks/useInputHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function guessType(file_object) {
const file_extension = file_name.split(".").pop();

const tree_extensions = ["nwk", "newick", "tree", "tre", "nh"];

if (tree_extensions.includes(file_extension)) {
return "nwk";
}
Expand All @@ -27,11 +28,11 @@ function guessType(file_object) {
}
if (file_extension === "tsv") {
return "meta_tsv";
}
if (file_extension === "json") {
return "nextstrain";
} else {
window.alert(
"Alert: unrecognised file type, supported types: jsonl (taxonium), nwk (newick), csv, tsv"
);
return "jsonl";
return "unknown";
}
}

Expand Down Expand Up @@ -114,10 +115,14 @@ export const useInputHelper = ({
if (inputs.filter((input) => input.filetype === "nwk").length > 1) {
return ["invalid", "You can only use a single tree file"];
}
if (inputs.some((input) => input.filetype === "unknown")) {
return ["invalid", "Please select the type of each file"];
}
// must have a tree file or a jsonl
if (
inputs.filter((input) => input.filetype === "jsonl").length === 0 &&
inputs.filter((input) => input.filetype === "nwk").length === 0
inputs.filter((input) => input.filetype === "nwk").length === 0 &&
inputs.filter((input) => input.filetype === "nextstrain").length === 0
) {
return [
"invalid",
Expand Down Expand Up @@ -146,10 +151,13 @@ export const useInputHelper = ({
const meta_file = inputs.find((input) =>
input.filetype.startsWith("meta_")
);
const tree_file = inputs.find((input) => input.filetype === "nwk");
const tree_file = inputs.find(
(input) => input.filetype === "nwk" || input.filetype === "nextstrain"
);
const newQuery = {
treeUrl: tree_file.name,
ladderizeTree: tree_file.ladderize === true,
treeType: tree_file.filetype,
};
if (meta_file) {
newQuery.metaUrl = meta_file.name;
Expand Down Expand Up @@ -181,7 +189,10 @@ export const useInputHelper = ({
}

// if there is a tree file find it
const tree_file = inputs.find((input) => input.filetype === "nwk");
const tree_file = inputs.find(
(input) => input.filetype === "nwk" || input.filetype === "nextstrain"
);

upload_obj.filename = tree_file.name;
upload_obj.data = tree_file.data;
upload_obj.status =
Expand Down Expand Up @@ -221,7 +232,7 @@ export const useInputHelper = ({
status: "url_supplied",
filename: query.treeUrl,
ladderize: query.ladderizeTree === "true",
filetype: "nwk",
filetype: query.treeType ? query.treeType : "nwk",
...extra,
});
}
Expand Down
8 changes: 1 addition & 7 deletions taxonium_web_client/src/utils/processNewick.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,13 @@ async function cleanup(tree) {

const scale_x = 450 / ref_x;

console.log(scale_y, "scale_y");
tree.node.forEach((node) => {
node.x_dist = node.x_dist * scale_x;
node.y = node.y * scale_y;
});
}

export async function processNewick(data, sendStatusMessage) {
console.log("got data", data);
let the_data;

the_data = await fetch_or_extract(data, sendStatusMessage, "tree");
Expand Down Expand Up @@ -139,11 +137,8 @@ export async function processNewick(data, sendStatusMessage) {
}
assignNumTips(tree.root);
const total_tips = tree.root.num_tips;
console.log("tree.root.num_tips", tree.root.num_tips);

if (data.ladderize) {
console.log("ladderizing");

sortWithNumTips(tree.root);
tree.node = kn_expand_node(tree.root);
}
Expand Down Expand Up @@ -198,8 +193,6 @@ export async function processMetadataFile(data, sendStatusMessage) {

the_data = await fetch_or_extract(data, logStatusToConsole, "metadata");

console.log("Got metadata file");

const lines = the_data.split("\n");
const output = {};
let separator;
Expand Down Expand Up @@ -275,5 +268,6 @@ export async function processNewickAndMetadata(data, sendStatusMessage) {
Object.assign(node, blanks);
}
});

return tree;
}
Loading

1 comment on commit bd80976

@vercel
Copy link

@vercel vercel bot commented on bd80976 Jul 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.