Skip to content
Permalink
Browse files

Merge pull request #819 from nextstrain/include-strain-metadata-acces…

…sion

Correctly handle a strain's accession & url data
  • Loading branch information...
jameshadfield committed Nov 5, 2019
2 parents 193d616 + 304b958 commit b04ff847a35b19263b179ed24a6515656b2cc9b0
@@ -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;
}


@@ -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) => {
@@ -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);
@@ -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 */
@@ -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: {
@@ -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 (
@@ -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>
@@ -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")
@@ -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) {
@@ -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;
}
@@ -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.
You can’t perform that action at this time.