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

Add Terra manifest to download options #715

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
49 changes: 49 additions & 0 deletions packages/data-portal-explore/src/components/FileTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {

const CDS_MANIFEST_FILENAME = 'cds_manifest.csv';
const GEN3_MANIFEST_FILENAME = 'gen3_manifest.json';
const TERRA_MANIFEST_FILENAME = 'terra_manifest.tsv';

interface IFileDownloadModalProps {
files: Entity[];
Expand Down Expand Up @@ -104,6 +105,26 @@ function generateGen3ManifestFile(files: Entity[]): string | undefined {
return data.length > 0 ? JSON.stringify(data, null, 2) : undefined;
}

function generateTerraManifestFile(files: Entity[]): string | undefined {
const columns = [
'entity:filename',
'drs_uri'
];
const data = _(files)
.filter((f) => !!f.viewers?.cds)
.map((f) => [
f.name, // Use `name` property for the filename
f.viewers?.cds?.drs_uri
])
.value();

if (data.length > 0) {
return [columns, ...data].map((row) => row.join('\t')).join('\n'); // Join with tabs for TSV format
} else {
return undefined;
}
}


const FilenameWithAccessIcon: React.FunctionComponent<{
file: Entity;
Expand Down Expand Up @@ -244,6 +265,32 @@ const gen3ManifestInstructions = (gen3manifestFile: string | undefined) => {
);
};

const terra3ManifestInstructions = (terra3manifestFile: string | undefined) => {
if (!terra3manifestFile) return null;

return (
<div>
<p></p>
<p>
<strong>Access files in Terra:</strong>{' '}
First link your Terra account to NCI CRDC Framework Services from your{' '}
<a href="https://app.terra.bio/#profile?tab=externalIdentities" target="_blank" rel="noopener noreferrer">
Terra profile External Identities
</a> page.{' '}
You can then add these files to Terra using the following manifest file.
</p>
<p>
<button
className="btn btn-light"
onClick={() => fileDownload(terra3manifestFile, TERRA_MANIFEST_FILENAME)}
>
<FontAwesomeIcon icon={faDownload} /> Download <code>terra_manifest.tsv</code>
</button>
</p>
</div>
);
};

const CDSInstructions: React.FunctionComponent<{ files: Entity[] }> = ({ files }) => {
const dbgapFiles = files.filter(
(f) => f.downloadSource === DownloadSourceCategory.dbgap
Expand All @@ -254,6 +301,7 @@ const CDSInstructions: React.FunctionComponent<{ files: Entity[] }> = ({ files }

const manifestFile = generateCdsManifestFile(files);
const gen3manifestFile = generateGen3ManifestFile(files);
const terra3manifestFile = generateTerraManifestFile(files);

return (
<div>
Expand Down Expand Up @@ -292,6 +340,7 @@ const CDSInstructions: React.FunctionComponent<{ files: Entity[] }> = ({ files }

{/* CDS and Gen3 manifest instructions */}
{cdsManifestInstructions(manifestFile)}
{terra3ManifestInstructions(terra3manifestFile)}
{gen3ManifestInstructions(gen3manifestFile)}
</div>
);
Expand Down