Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow displayed diversity data to be downloaded #1144

Merged
merged 1 commit into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/components/download/downloadModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export const publications = {
show: state.controls.showDownload,
colorBy: state.controls.colorBy,
metadata: state.metadata,
entropy: state.entropy,
mutType: state.controls.mutType,
tree: state.tree,
nodes: state.tree.nodes,
visibleStateCounts: state.tree.visibleStateCounts,
Expand Down Expand Up @@ -190,6 +192,20 @@ class DownloadModal extends React.Component {
buttons.push(["Author Metadata (TSV)", `Metadata for all samples in the dataset (n = ${this.props.metadata.mainTreeNumTips}) grouped by their ${uniqueAuthorCount} authors.`,
(<MetaIcon width={iconWidth} selected />), () => helpers.authorTSV(this.props.dispatch, filePrefix, this.props.tree)]);
}
if (this.props.entropy.loaded) {
let msg = `The data behind the diversity panel`;
msg += ` showing ${this.props.entropy.showCounts ? `a count of changes across the tree` : `normalised shannon entropy`}`;
msg += this.props.mutType === "nuc" ? " per nucleotide." : " per codon.";
if (selectedTipsCount !== this.props.metadata.mainTreeNumTips) {
msg += ` Restricted to strains which are currently displayed (n = ${selectedTipsCount}/${this.props.metadata.mainTreeNumTips}).`;
}
buttons.push([
"Genetic diversity data (TSV)",
msg,
(<MetaIcon width={iconWidth} selected />),
() => helpers.entropyTSV(this.props.dispatch, filePrefix, this.props.entropy, this.props.mutType)
]);
}
buttons.push(
["Screenshot (SVG)", "Screenshot of the current nextstrain display in SVG format.",
(<PanelsGridIcon width={iconWidth} selected />), () => helpers.SVG(this.props.dispatch, filePrefix, this.props.panelsToDisplay, this.props.panelLayout, this.makeTextStringsForSVGExport())]
Expand Down
16 changes: 16 additions & 0 deletions src/components/download/helperFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,19 @@ export const SVG = (dispatch, filePrefix, panelsInDOM, panelLayout, textStrings)
writeSVGPossiblyIncludingMap(dispatch, filePrefix, panelsInDOM, panelLayout, textStrings, undefined);
}
};

export const entropyTSV = (dispatch, filePrefix, entropy, mutType) => {
const lines = mutType === "nuc" ? ["base"] : ["gene\tposition"];
lines[0] += entropy.showCounts ? "\tevents" : "\tentropy";
entropy.bars.forEach((bar) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jameshadfield if the entropy view is "zoomed" aka only showing a subset of sites, do we want to limit the download to just those sites? Defaulting to all of them seems ok to me since getting more data that you want is the worst case, but just wanted to check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is that downloading the data shown on the screen (filtered by currently visible tips) is the better / more powerful behavior. Just need to be clear to the user that this is what's going on. It matches the way that NEWICK download works as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the newick download is always the entire tree. but we have an option to download only the metadata for the displayed tips.

There are two different zooms that are relevant ehre. I think @eharkins is talking about the fraction of the genome that the zoom currently shows, while @trvrb talks about diversity among currently zoomed/selected tips in the tree (correct me if I am wrong). In the former case, more data doesn't hurt. In the latter case the zoom/filter defines what diversity is. so here providing the current state is most sensible but it needs to be obvious IMHO...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eharkins is talking about the fraction of the genome that the zoom currently shows

Yes.

trvrb talks about diversity among currently zoomed/selected tips in the tree (correct me if I am wrong). In the former case, more data doesn't hurt.

👍

In the latter case the zoom/filter defines what diversity is. so here providing the current state is most sensible but it needs to be obvious IMHO...

The current state of this is similar to how it is done for downloading other data that is filtered according to visible tree trips:
Screen Shot 2020-05-28 at 3 22 47 PM

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fraction of the genome that the zoom currently shows

I didn't take this into account. We could, if desired.

diversity among currently zoomed/selected tips in the tree

This is taken into account, as it defines the underlying diversity data. I dynamically change the message printed in the download modal to indicate this. For instance, changing to nucleotide, events, and zoomed to a sub-tree will display "The data behind the diversity panel showing a count of changes across the tree per nucleotide. Restricted to strains which are currently displayed (n = 134/543)."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I was confused. I was thinking of the "selected metadata". I would just export the entire genome, rather than the in view portion.

if (mutType === "nuc") {
lines.push(`${bar.x}\t${bar.y}`);
} else {
lines.push(`${bar.prot}\t${bar.codon}\t${bar.y}`);
}
});
/* write out information we've collected */
const filename = `${filePrefix}_diversity.tsv`;
write(filename, MIME.tsv, lines.join("\n"));
dispatch(infoNotification({message: `Diversity data exported to ${filename}`}));
};