Skip to content

Commit

Permalink
nextstrain#1055: add selected metadata button; filter out unselected …
Browse files Browse the repository at this point in the history
…nodes when metadata generated via this method
  • Loading branch information
frogsquire committed Apr 12, 2020
1 parent b972a23 commit 18600e0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/components/download/downloadModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ class DownloadModal extends React.Component {
const buttons = [
["Tree (newick)", (<RectangularTreeIcon width={iconWidth} selected />), () => helpers.newick(this.props.dispatch, filePrefix, this.props.nodes[0], false)],
["TimeTree (newick)", (<RectangularTreeIcon width={iconWidth} selected />), () => helpers.newick(this.props.dispatch, filePrefix, this.props.nodes[0], true)],
["Strain Metadata (TSV)", (<MetaIcon width={iconWidth} selected />), () => helpers.strainTSV(this.props.dispatch, filePrefix, this.props.nodes, this.props.metadata.colorings)]
["All Metadata (TSV)", (<MetaIcon width={iconWidth} selected />), () => helpers.strainTSV(this.props.dispatch, filePrefix, this.props.nodes, this.props.metadata.colorings, false, null)],
["Selected Metadata (TSV)", (<MetaIcon width={iconWidth} selected />), () => helpers.strainTSV(this.props.dispatch, filePrefix, this.props.nodes, this.props.metadata.colorings, true, this.props.tree.visibility)]
];
if (helpers.areAuthorsPresent(this.props.tree)) {
buttons.push(["Author Metadata (TSV)", (<MetaIcon width={iconWidth} selected />), () => helpers.authorTSV(this.props.dispatch, filePrefix, this.props.tree)]);
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 @@ -3,6 +3,8 @@ import { infoNotification, warningNotification } from "../../actions/notificatio
import { spaceBetweenTrees } from "../tree/tree";
import { getTraitFromNode, getDivFromNode, getFullAuthorInfoFromNode, getVaccineFromNode, getAccessionFromNode } from "../../util/treeMiscHelpers";
import { numericToCalendar } from "../../util/dateHelpers";
import { NODE_VISIBLE } from "../../util/globals";
import { calcVisiblity } from "../../util/treeVisibilityHelpers";

export const isPaperURLValid = (d) => {
return (
Expand Down Expand Up @@ -105,15 +107,20 @@ export const authorTSV = (dispatch, filePrefix, tree) => {
* Create & write a TSV file where each row is a strain in the tree,
* with the relevent information (accession, traits, etcetera)
*/
export const strainTSV = (dispatch, filePrefix, nodes, colorings) => {
export const strainTSV = (dispatch, filePrefix, nodes, colorings, selectedNodesOnly, nodeVisibilities) => {

/* traverse the tree & store tip information. We cannot write this out as we go as we don't know
exactly which header fields we want until the tree has been traversed. */
const tipTraitValues = {};
const headerFields = ["Strain"];

for (const node of nodes) {
for (const [i, node] of nodes.entries()) {
if (node.hasChildren) continue; /* we only consider tips */

if (selectedNodesOnly && nodeVisibilities
&& (nodeVisibilities[i] !== NODE_VISIBLE || !node.inView))
continue; /* skip unselected nodes if requested */

tipTraitValues[node.name] = {Strain: node.name};
if (!node.node_attrs) continue; /* if this is not set then we don't have any node info! */

Expand Down Expand Up @@ -189,6 +196,7 @@ export const strainTSV = (dispatch, filePrefix, nodes, colorings) => {
}

/* write out information we've collected */
// todo: filename for selected only
const filename = `${filePrefix}_metadata.tsv`;
write(filename, MIME.tsv, linesToWrite.join("\n"));
dispatch(infoNotification({message: `Metadata exported to ${filename}`}));
Expand Down
2 changes: 1 addition & 1 deletion src/util/treeVisibilityHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ FILTERS:
- filters (in this code) is a list of filters to apply
e.g. [{trait: "country", values: [...]}, ...]
*/
const calcVisibility = (tree, controls, dates) => {
export const calcVisibility = (tree, controls, dates) => {
if (tree.nodes) {
/* inView represents nodes that are within the current view window (i.e. not off the screen) */
let inView;
Expand Down

0 comments on commit 18600e0

Please sign in to comment.