Skip to content

Commit

Permalink
Merge pull request #819 from nextstrain/include-strain-metadata-acces…
Browse files Browse the repository at this point in the history
…sion

Correctly handle a strain's accession & url data
  • Loading branch information
jameshadfield authored Nov 5, 2019
2 parents 193d616 + 304b958 commit b04ff84
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cli/server/convertJsonSchemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ const setNodeBranchAttrs = (v2) => {
traverseTree(v2.tree, (node) => {

if (node.attr) {
if (node.attr.url) node.url = node.node_attrs.url;
if (node.attr.accession) node.accession = node.node_attrs.accession;
if (node.attr.url) node.node_attrs.url = node.attr.url;
if (node.attr.accession) node.node_attrs.accession = node.attr.accession;
}


Expand Down
12 changes: 10 additions & 2 deletions src/components/download/helperFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React from "react";
import { infoNotification, warningNotification } from "../../actions/notifications";
import { spaceBetweenTrees } from "../tree/tree";
import { getTraitFromNode, getDivFromNode, getFullAuthorInfoFromNode, getVaccineFromNode } from "../../util/treeMiscHelpers";
import { getTraitFromNode, getDivFromNode, getFullAuthorInfoFromNode, getVaccineFromNode, getAccessionFromNode } from "../../util/treeMiscHelpers";
import { numericToCalendar } from "../../util/dateHelpers";

export const isPaperURLValid = (d) => {
Expand Down Expand Up @@ -111,7 +111,7 @@ export const strainTSV = (dispatch, filePrefix, nodes, colorings) => {

/* collect values (as writable strings) of the same "traits" as can be viewed by the modal displayed
when clicking on tips. Note that "num_date", "author" and "vaccine" are considered seperately below */
const nodeAttrsToIgnore = ["author", "div", "num_date", "vaccine"];
const nodeAttrsToIgnore = ["author", "div", "num_date", "vaccine", "accession"];
const traits = Object.keys(node.node_attrs).filter((k) => !nodeAttrsToIgnore.includes(k));
for (const trait of traits) {
if (!headerFields.includes(trait)) headerFields.push(trait);
Expand Down Expand Up @@ -156,6 +156,14 @@ export const strainTSV = (dispatch, filePrefix, nodes, colorings) => {
if (!headerFields.includes(traitName)) headerFields.push(traitName);
tipTraitValues[node.name][traitName] = vaccine.selection_date;
}

/* handle `accession` specially */
const accession = getAccessionFromNode(node);
if (accession) {
const traitName = "Accession";
if (!headerFields.includes(traitName)) headerFields.push(traitName);
tipTraitValues[node.name][traitName] = accession;
}
}

/* turn the information into a string to be written */
Expand Down
9 changes: 5 additions & 4 deletions src/components/tree/infoPanels/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { isValueValid } from "../../../util/globals";
import { infoPanelStyles } from "../../../globalStyles";
import { numericToCalendar } from "../../../util/dateHelpers";
import { getTraitFromNode, getFullAuthorInfoFromNode, getVaccineFromNode } from "../../../util/treeMiscHelpers";
import { getTraitFromNode, getFullAuthorInfoFromNode, getVaccineFromNode, getAccessionFromNode, getUrlFromNode } from "../../../util/treeMiscHelpers";

export const styles = {
container: {
Expand Down Expand Up @@ -51,8 +51,9 @@ const formatURL = (url) => {
};

const AccessionAndUrl = ({node}) => {
const accession = getTraitFromNode(node, "accession");
const url = getTraitFromNode(node, "url");
const accession = getAccessionFromNode(node);
const url = getUrlFromNode(node);


if (isValueValid(accession) && isValueValid(url)) {
return (
Expand All @@ -70,7 +71,7 @@ const AccessionAndUrl = ({node}) => {
} else if (isValueValid(url)) {
return (
<tr>
<th style={infoPanelStyles.item}>URL</th>
<th style={infoPanelStyles.item}>Strain URL</th>
<td style={infoPanelStyles.item}>
<a href={formatURL(url)} target="_blank"><em>click here</em></a>
</td>
Expand Down
25 changes: 23 additions & 2 deletions src/util/treeMiscHelpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@

import { isValueValid } from "./globals";

/* --- TO IMPROVE -----
These "getter" functions for node-related data require knowledge of
the semantics of how data is stored on a node. For instance, you need
to know that `num_date` is stored in a different structure to `div`.
This logic should be encapsulated within `getTraitFromNode` so we
don't need separate `getDivFromNode` functions etc.
james hadfield, nov 2019.
*/

/**
* Given a coloring key or a geographic resolution key
* (sometimes referred to as a "trait")
Expand All @@ -18,7 +26,6 @@ import { isValueValid } from "./globals";
* which don't share the same structure as traits. See the JSON spec for more details.
*/
export const getTraitFromNode = (node, trait, {entropy=false, confidence=false}={}) => {

if (!node.node_attrs) return undefined;

if (!entropy && !confidence) {
Expand All @@ -36,13 +43,15 @@ export const getTraitFromNode = (node, trait, {entropy=false, confidence=false}=
};

export const getDivFromNode = (node) => {
/* see comment at top of this file */
if (node.node_attrs && node.node_attrs.div !== undefined) {
return node.node_attrs.div;
}
return undefined;
};

export const getVaccineFromNode = (node) => {
/* see comment at top of this file */
if (node.node_attrs && node.node_attrs.vaccine) {
return node.node_attrs.vaccine;
}
Expand All @@ -53,3 +62,15 @@ export const getFullAuthorInfoFromNode = (node) =>
(node.node_attrs && node.node_attrs.author && node.node_attrs.author.value) ?
node.node_attrs.author :
undefined;

export const getAccessionFromNode = (node) => {
/* see comment at top of this file */
if (node.node_attrs && node.node_attrs.accession) {
return node.node_attrs.accession;
}
return undefined;
};

/* see comment at top of this file */
export const getUrlFromNode = (node) =>
(node.node_attrs && node.node_attrs.url) ? node.node_attrs.url : undefined;

0 comments on commit b04ff84

Please sign in to comment.