Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1: Dynamic tree do not merge #41

Open
wants to merge 5 commits into
base: v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/bac120.tree

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/cog_global_tree.newick.REMOVED.git-id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dfec1fcd21f6ba8420045894f854363de63746f3
198 changes: 5 additions & 193 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,171 +1,13 @@
import "./App.css";
import React, { useEffect, useState, useCallback ,useMemo} from "react";
import Deck from "./Deck";
import SearchPanel from "./components/SearchPanel";
import axios from "axios";
import React, { useState, Suspense } from "react";
import AboutOverlay from "./components/AboutOverlay";
import { BrowserRouter as Router } from "react-router-dom";
import { CgListTree } from "react-icons/cg";
//import {FaGithub} from "react-icons/fa";
import { BsInfoSquare } from "react-icons/bs";


var protobuf = require("protobufjs");
protobuf.parse.defaults.keepCase = true;

const searchColors = [
[255, 0, 0],
[183, 0, 255],
[255, 213, 0],

[0, 0, 255],
[0, 255, 255],
];



const Taxodium = React.lazy(() => import("./Taxodium"));
function App() {

const [zoomToSearch, setZoomToSearch] = useState({index:null});

const [searchItems, setSearchItemsBasic] = useState([
{
id: 0.123,
category: "lineage",
value: "",
enabled: true,
},
]);




const setSearchItems = useCallback((x) => {
setSearchItemsBasic(x);
}, []);

const [colourBy, setColourBy] = useState("lineage");
const setColourByWithCheck = useCallback((x) => {
setColourBy(x);
}, []);
const [nodeData, setNodeData] = useState({
status: "not_attempted",
data: { node_data: { ids: [] } },
});

const [selectedNode, setSelectedNode] = useState(null);

const [aboutEnabled, setAboutEnabled] = useState(false);

useEffect(() => {
if (nodeData.status === "not_attempted") {
console.log("starting dl");
setNodeData({
status: "loading",
progress: 0,
data: { node_data: { ids: [] } },
});

protobuf.load("./tree.proto").then(function (root) {
axios
.get("/nodelist.pb", {
responseType: "arraybuffer",
onDownloadProgress: (progressEvent) => {
let percentCompleted = Math.floor(
1 * (progressEvent.loaded / 100000000) * 100
);
setNodeData({
status: "loading",
progress: percentCompleted,
data: { node_data: { ids: [] } },
});
},
})
.then(function (response) {
return response.data;
})
.then(function (buffer) {
console.log("buffer loaded");
var NodeList = root.lookupType("AllData");

var message = NodeList.decode(new Uint8Array(buffer));
var result = NodeList.toObject(message);
result.node_data.ids = [...Array(result.node_data.x.length).keys()];
setNodeData({ status: "loaded", data: result });
});
});
}
}, [nodeData.status]);

const data = useMemo( ()=>nodeData.status === "loaded"
? nodeData.data
: { node_data: { ids: [] } },[nodeData])



const scatterIds = useMemo(
() => data.node_data.ids.filter((x) => data.node_data.names[x] !== ""),
[data]
);


const [search_configs_initial, numSearchResults, totalSeqs] = useMemo(() => {

const configs = searchItems
.map((item, counter) => {
let filter_function;
const lowercase_query = item.value.toLowerCase().trim();
if (item.category === "mutation") {
const the_index = data.mutation_mapping.indexOf(item.value);
filter_function = (x) =>
data.node_data.mutations[x].mutation &&
data.node_data.mutations[x].mutation.includes(the_index);
}

if (item.category === "name") {
filter_function = (x) =>
data.node_data.names[x].toLowerCase().includes(lowercase_query); //TODO precompute lowercase mapping for perf?
}

if (item.category === "country") {
filter_function = (x) =>
data.country_mapping[data.node_data.countries[x]].toLowerCase() ===
lowercase_query; //TODO precompute lowercase mapping for perf
}
if (item.category === "lineage") {
filter_function = (x) =>
data.lineage_mapping[data.node_data.lineages[x]].toLowerCase() ===
lowercase_query; //TODO precompute lowercase mapping for perf
}
const enabled =
item.value !== null && item.value !== "" && item.enabled;
return {
original_index:counter,
id: "main-search-" + counter,
enabled: enabled,
data: item.value !== "" ? scatterIds.filter(filter_function) : [],
opacity: 0.7,
getRadius: 7 + counter * 2,
filled: false,
stroked: true,
radiusUnits: "pixels",
lineWidthUnits: "pixels",
lineWidthScale: 1,

getPosition: (d) => {
return [data.node_data.x[d], data.node_data.y[d]];
},
getFillColor: (d) => [0, 0, 0],
getLineColor: (d) => searchColors[counter % searchColors.length],
};
})
const num_results = configs.map(x=>x.data.length)
const filtered_configs = configs.filter((item) => item.enabled);
return [filtered_configs, num_results, scatterIds.length];
}, [data, searchItems, scatterIds]);



return (
<Router>
<AboutOverlay enabled={aboutEnabled} setEnabled={setAboutEnabled} />
Expand Down Expand Up @@ -194,41 +36,11 @@ const scatterIds = useMemo(
</div>
</div>
</div>
<div className="main_content">
<div className="md:grid md:grid-cols-12 h-full">
<div className="md:col-span-8 h-3/6 md:h-full w-full">
<Deck

search_configs_initial={search_configs_initial}
scatterIds={scatterIds}
searchColors={searchColors}
setSelectedNode={setSelectedNode}
searchItems={searchItems}
data={data}
progress={nodeData.progress}
colourBy={colourBy}
zoomToSearch={zoomToSearch}
/>
</div>
<div className="md:col-span-4 h-full bg-white border-gray-600 pl-5 shadow-xl">
<SearchPanel
setZoomToSearch={setZoomToSearch}
totalSeqs={totalSeqs}
numSearchResults = {numSearchResults}
searchColors={searchColors}
selectedNode={selectedNode}
searchItems={searchItems}
data={data}
setSearchItems={setSearchItems}
colourBy={colourBy}
setColourBy={setColourByWithCheck}
/>
</div>
</div>
</div>
<Suspense fallback={<div>Loading...</div>}>
<Taxodium />
</Suspense>
</div>
</Router>
);
}

export default App;
11 changes: 6 additions & 5 deletions src/Deck.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ function toRGB(string) {
}
return rgb;
}
function toRGBCSS(string) {
/*function toRGBCSS(string) {
const output = toRGB(string);
return `rgb(${output[0]},${output[1]},${output[2]})`;
}
}*/

let getMMatrix = (zoom) => [
1 / 2 ** (zoom - 5.6),
Expand Down Expand Up @@ -564,7 +564,8 @@ function Deck({ data, colourBy, progress, setSelectedNode,scatterIds,search_conf

const hoverStuff = useMemo(() => {
if (hoverInfo && hoverInfo.object) {
const lineage =
return <>{hoverInfo.object}</>
/*const lineage =
data.lineage_mapping[node_data.lineages[hoverInfo.object]];
const country =
data.country_mapping[node_data.countries[hoverInfo.object]];
Expand Down Expand Up @@ -604,8 +605,8 @@ function Deck({ data, colourBy, progress, setSelectedNode,scatterIds,search_conf
</div>
</div>
);
}
}, [data, node_data, hoverInfo]);
*/}
}, [hoverInfo]);
const spinnerShown = useMemo(() => node_data.ids.length === 0, [node_data]);


Expand Down
Loading