Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 25, 2025
1 parent 24cf702 commit def419e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion taxonium_component/src/webworkers/treenomeWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const computeVariationData = async (data, type, ntBounds, jobId) => {

const preorder_nodes = pre_order(nodes);
const root = preorder_nodes.find((id) => id === lookup[id].parent_id);

// Use rootSequences from config
if (data.data && data.data.config && data.data.config.rootSequences) {
ref = data.data.config.rootSequences;
Expand Down
41 changes: 31 additions & 10 deletions taxonium_data_handling/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ const getNumericFilterFunction = (number_method, number_value) => {
throw new Error("Invalid number_method: " + number_method);
};

const getRevertantMutationsSet = (all_data, node_to_mut, mutations, rootSequences) => {
const getRevertantMutationsSet = (
all_data,
node_to_mut,
mutations,
rootSequences
) => {
// Initialize gene_sequence - preferably from rootSequences, fallback to rootMutations
let gene_sequence;

if (rootSequences && rootSequences.aa) {
// Use rootSequences if available
gene_sequence = rootSequences.aa;
Expand All @@ -41,7 +46,7 @@ const getRevertantMutationsSet = (all_data, node_to_mut, mutations, rootSequence
gene_sequence[m.gene][m.residue_pos] = m.new_residue;
});
}

const revertant_mutations = mutations.filter(
(m) =>
m.gene in gene_sequence &&
Expand Down Expand Up @@ -397,7 +402,14 @@ function searchFilteringIfUncached({
position: spec.position,
new_residue: spec.new_residue,
};
return filterByGenotype(data, genotype, mutations, node_to_mut, all_data, rootSequences);
return filterByGenotype(
data,
genotype,
mutations,
node_to_mut,
all_data,
rootSequences
);
} else if (spec.method === "number") {
if (spec.number == "") {
return [];
Expand Down Expand Up @@ -550,7 +562,14 @@ const getTipAtts = (input, node_id, attribute) => {
return allAtts;
};

const filterByGenotype = (data, genotype, mutations, node_to_mut, all_data, rootSequences) => {
const filterByGenotype = (
data,
genotype,
mutations,
node_to_mut,
all_data,
rootSequences
) => {
const genotype_cache = {};
const { gene, position, new_residue } = genotype;

Expand Down Expand Up @@ -613,11 +632,13 @@ const filterByGenotype = (data, genotype, mutations, node_to_mut, all_data, root
if (cur_node.parent_id === cur_node.node_id) {
// We've reached the root node
// Check if we have rootSequences data
if (rootSequences &&
rootSequences.aa &&
rootSequences.aa[gene] &&
rootSequences.aa[gene][position] === new_residue) {
to_label.forEach(node_id => {
if (
rootSequences &&
rootSequences.aa &&
rootSequences.aa[gene] &&
rootSequences.aa[gene][position] === new_residue
) {
to_label.forEach((node_id) => {
genotype_cache[node_id] = true;
});
return true;
Expand Down
12 changes: 6 additions & 6 deletions taxonium_data_handling/importing.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,13 @@ export const processJsonl = async (
const rootSequences = { nt: {}, aa: {} };
if (rootMutations && rootMutations.length > 0) {
// Group mutations by gene
rootMutations.forEach(mutIndex => {
const mut = new_data.header.mutations ?
new_data.header.mutations[mutIndex] :
new_data.header.aa_mutations[mutIndex];
rootMutations.forEach((mutIndex) => {
const mut = new_data.header.mutations
? new_data.header.mutations[mutIndex]
: new_data.header.aa_mutations[mutIndex];

if (!mut) return;

if (mut.gene === "nt") {
rootSequences.nt[mut.residue_pos] = mut.new_residue;
} else {
Expand Down

0 comments on commit def419e

Please sign in to comment.