Skip to content

Commit

Permalink
Fix missing num tips in ushertools (#130)
Browse files Browse the repository at this point in the history
* Fix missing num tips in ushertools

* Prettified Code!

Co-authored-by: theosanderson <[email protected]>
  • Loading branch information
theosanderson and theosanderson authored Apr 25, 2022
1 parent ff72a95 commit bc280eb
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
7 changes: 3 additions & 4 deletions taxonium_data_handling/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ function searchFiltering({ data, spec, mutations, node_to_mut, all_data }) {
.filter((line) => line !== "")
);



filtered = data.filter((node) => {
const to_test = node[spec.type].toLowerCase().trim();
//console.log(to_test);
Expand All @@ -165,17 +163,18 @@ function searchFiltering({ data, spec, mutations, node_to_mut, all_data }) {
);
})
.map((mutation) => mutation.mutation_id);
//console.log("relevant_mutations:", relevant_mutations);
console.log("relevant_mutations:", relevant_mutations);
const relevant_mutations_set = new Set(relevant_mutations);
//console.log("node_to_mut:", node_to_mut);
console.log("NODE", data[0]);

filtered = data.filter(
(node) =>
node_to_mut[node.node_id].some((mutation_id) =>
relevant_mutations_set.has(mutation_id)
) && node.num_tips > spec.min_tips
);
//console.log("filtered:", filtered);
console.log("filtered:", filtered);
return filtered;
} else if (spec.method === "revertant") {
if (!all_data) {
Expand Down
8 changes: 4 additions & 4 deletions taxonium_data_handling/importing.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,23 @@ export const processJsonl = async (jsonl, sendStatusMessage) => {

const scale_x = 10;
const scale_y = 24e2 / new_data.nodes.length;
console.log("Scaling")
console.log("Scaling");
for (const node of new_data.nodes) {
node.x_dist = node.x_dist * scale_x;
node.x = node.x_dist;
node.y = node.y * scale_y;
}
console.log("Calculating y positions")
console.log("Calculating y positions");
const y_positions = new_data.nodes.map((node) => node.y);

console.log("Calculating coord extremes")
console.log("Calculating coord extremes");

const overallMaxY = reduceMaxOrMin(new_data.nodes, (node) => node.y, "max");
const overallMinY = reduceMaxOrMin(new_data.nodes, (node) => node.y, "min");
const overallMaxX = reduceMaxOrMin(new_data.nodes, (node) => node.x, "max");
const overallMinX = reduceMaxOrMin(new_data.nodes, (node) => node.x, "min");

console.log("Creating output obj")
console.log("Creating output obj");
const output = {
nodes: new_data.nodes,
overallMaxX,
Expand Down
1 change: 0 additions & 1 deletion taxonium_web_client/src/components/NodeHoverTip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const fixName = (name) => {
return name.replace("hCoV-19/", "hCoV-19/\n");
};


const NodeHoverTip = ({
hoverInfo,
hoverDetails,
Expand Down
4 changes: 1 addition & 3 deletions taxonium_web_client/src/hooks/useSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ const useSearch = (
return JSON.parse(query.srch);
}, [query.srch]);

console.log("spec", searchSpec);

const [zoomToSearch, setZoomToSearch] = useState(
query.zoomToSearch ? { index: query.zoomToSearch } : null
);
const searchesEnabled = query.enabled ? JSON.parse(query.enabled) : {};
console.log("searchesEnabled", searchesEnabled);

const setEnabled = (key, enabled) => {
console.log("setEnabled", key, enabled);
const newSearchesEnabled = { ...searchesEnabled, [key]: enabled };
Expand Down
2 changes: 2 additions & 0 deletions taxoniumtools/src/taxoniumtools/usher_to_taxonium.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ def get_node_object(node, node_to_index, metadata, aa_mut_tuple_to_index,
node.parent] if node.parent else node_to_index[node]
object['node_id'] = node_to_index[
node] # We don't strictly need this, but it doesn't add much to the space

object['num_tips'] = node.num_tips
return object


Expand Down
8 changes: 8 additions & 0 deletions taxoniumtools/src/taxoniumtools/ushertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def __init__(self, tree_file, genbank_file=None):
if genbank_file:
self.load_genbank_file(genbank_file)
self.perform_aa_analysis()
self.assign_num_tips()

def perform_aa_analysis(self):
seq = str(self.genbank.seq)
Expand Down Expand Up @@ -197,3 +198,10 @@ def get_condensed_nodes_dict(self, condensed_nodes_dict):
output_dict[
condensed_node.node_name] = condensed_node.condensed_leaves
return output_dict

def assign_num_tips(self):
for node in self.tree.traverse_postorder():
if node.is_leaf():
node.num_tips = 1
else:
node.num_tips = sum(child.num_tips for child in node.children)

1 comment on commit bc280eb

@vercel
Copy link

@vercel vercel bot commented on bc280eb Apr 25, 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.