Skip to content

Commit e3a7969

Browse files
committed
Update views.py and archived_image.html
1 parent b6f5594 commit e3a7969

3 files changed

Lines changed: 33 additions & 61 deletions

File tree

idr_gallery/templates/idr_gallery/archived_image.html

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,9 @@ <h3>Download Image Files</h3>
6666
{% endif %}
6767

6868
<ul class="download_list">
69-
{% for file in fileset.file_urls %}
69+
{% for path in fileset.client_paths %}
7070
<li>
71-
{% if file.url %}
72-
<a class="file_download" target="_blank" href="{{ file.url }}">{{ file.path }}</a>
73-
{% else %} {{ file.path }} {% endif %}
71+
<a class="file_download" target="_blank" href="#">{{ path }}</a>
7472
</li>
7573
{% endfor %}
7674
</ul>
@@ -131,9 +129,13 @@ <h3>Download Image Files</h3>
131129

132130
document.addEventListener("DOMContentLoaded", function () {
133131
// Load download URLs from TSV file in GitHub to fix the download URL for this image
134-
fetch(
135-
"https://raw.githubusercontent.com/IDR/idr.openmicroscopy.org/refs/heads/master/_data/download_urls.tsv",
136-
)
132+
let TABLE_URL = 'https://raw.githubusercontent.com/IDR/idr.openmicroscopy.org/refs/heads/master/_data/download_urls.tsv';
133+
// check query params for ?tsv= to allow testing with a different TSV file
134+
const urlParams = new URLSearchParams(window.location.search);
135+
if (urlParams.has('tsv')) {
136+
TABLE_URL = urlParams.get('tsv');
137+
}
138+
fetch(TABLE_URL)
137139
.then((response) => response.text())
138140
.then((data) => {
139141
const lines = data.split("\n");
@@ -158,15 +160,20 @@ <h3>Download Image Files</h3>
158160
link.textContent = downloadUrl;
159161
link.href = downloadUrl;
160162
}
161-
const baseUrl = downloadUrl.split(IDR_ID)[0]; // e.g. https://ftp.ebi.ac.uk/pub/databases/IDR/
162-
console.log(`Download URL for ${IDR_ID}:`, downloadUrl);
163-
if (downloadUrl && downloadUrl !== DOWNLOAD_URL) {
164-
console.log(`Updating download URLs from ${DOWNLOAD_URL} to ${downloadUrl}`);
163+
164+
// Load "replaceThis" and "withThis" from the TSV file to allow replacing the download URL in the links on this page
165+
const replaceThisIndex = headers.indexOf("replace_this");
166+
const withThisIndex = headers.indexOf("with_this");
167+
const replaceThis = cells[replaceThisIndex];
168+
const withThis = cells[withThisIndex] || "";
169+
console.log(`replaceThis: ${replaceThis}, withThis: ${withThis}`);
170+
if (replaceThis) {
171+
// if (downloadUrl && downloadUrl !== DOWNLOAD_URL) {
165172
// update all ".file_download" links to this download URL
166173
const fileDownloadLinks =
167174
document.querySelectorAll(".file_download");
168175
fileDownloadLinks.forEach((link) => {
169-
link.href = link.href.replace(DOWNLOAD_URL, downloadUrl);
176+
link.href = link.textContent.replace(replaceThis, withThis);
170177
});
171178
}
172179
} else {

idr_gallery/templates/idr_gallery/download_urls.html

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ <h1>Download URLs</h1>
6565
}
6666

6767
// Fetch the TSV file and display it in a table
68-
fetch('https://raw.githubusercontent.com/IDR/idr.openmicroscopy.org/refs/heads/master/_data/download_urls.tsv')
68+
let TABLE_URL = 'https://raw.githubusercontent.com/IDR/idr.openmicroscopy.org/refs/heads/master/_data/download_urls.tsv';
69+
// check query params for ?tsv= to allow testing with a different TSV file
70+
const urlParams = new URLSearchParams(window.location.search);
71+
if (urlParams.has('tsv')) {
72+
TABLE_URL = urlParams.get('tsv');
73+
}
74+
fetch(TABLE_URL)
6975
.then(response => response.text())
7076
.then(data => {
7177
const lines = data.split('\n');
@@ -91,6 +97,8 @@ <h1>Download URLs</h1>
9197
let idrIdIndex = headers.indexOf('idrid');
9298
let imageIdIndex = headers.indexOf('image_id');
9399
let dataLocationIndex = headers.indexOf('data_location');
100+
let replaceThisIndex = headers.indexOf('replace_this');
101+
let withThisIndex = headers.indexOf('with_this');
94102

95103
// Create table body - update client_path to URL, based on the download_url column...
96104
const tbody = table.createTBody();
@@ -103,34 +111,12 @@ <h1>Download URLs</h1>
103111
let clientPath = cells[clientPathIndex];
104112
let downloadUrl = cells[downloadUrlIndex];
105113
let dataLocation = cells[dataLocationIndex];
114+
let replaceThis = cells[replaceThisIndex];
115+
let withThis = cells[withThisIndex];
106116
let clientPathUrl;
107-
if (dataLocation == "Github") {
108-
let branch = "main";
109-
// e.g. data/idr-metadata/idr0106-kubota-lunglightsheet/experimentA/companions/Mosaic_Image.companion.ome
110-
// links to https://github.com/IDR/idr0106-kubota-lunglightsheet/blob/main/experimentA/companions/Mosaic_Image.companion.ome
111-
// uod/idr/metadata/idr0052-walther-condensinmap/experimentA/companions/160719_NCAPD2gfpc272c78_MitoSys2/conc/cell0005_R0001.companion.ome
112-
// links to https://github.com/IDR/idr0052-walther-condensinmap/blob/master/experimentA/companions/160719_NCAPD2gfpc272c78_MitoSys2/conc/cell0005_R0001.companion.ome
113-
// uod/idr/metadata/idr0079-hartmann-lateralline/companions/experimentA/056F63395C/056F63395C.companion.ome
114-
// https://github.com/IDR/idr0079-hartmann-lateralline/blob/master/companions/experimentA/056F63395C/056F63395C.companion.ome
115-
let relativePath = clientPath.split("metadata/idr")[1];
116-
let githubRepo = "idr" + relativePath.split("/")[0];
117-
// some repos use "master" branch, so check for those...
118-
if ("idr0079,idr0052,idr0065,idr0075,idr0100".includes(githubRepo.split("-")[0])) {
119-
branch = "master";
120-
}
121-
relativePath = relativePath.split("/").slice(1).join("/");
122-
clientPathUrl = `https://github.com/IDR/${githubRepo}/blob/${branch}/${relativePath}`;
123-
124-
} else if (downloadUrl.includes(idrId) && clientPath.includes(idrId)) {
125-
// e.g. https://ftp.ebi.ac.uk/pub/databases/IDR/idr0001-graml-sysgro
126-
let urlBase = downloadUrl.split(idrId)[0];
127-
let urlPath = clientPath.split(idrId)[1];
128-
clientPathUrl = urlBase + idrId + urlPath;
129-
}
130-
if (clientPathUrl) {
131-
// client_path needs patching for /idr0045-reichmann-zygotespindle/
132-
clientPathUrl = clientPathUrl.replace("/idr0045-reichmann/", "/idr0045-reichmann-zygotespindle/");
133-
}
117+
118+
// Simple replace one prefix with another. We rely on the TSV file for correct values...
119+
clientPathUrl = clientPath.replace(replaceThis, withThis);
134120

135121
cells.forEach((cellText, colIndex) => {
136122
const td = document.createElement('td');

idr_gallery/views.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -586,31 +586,10 @@ def image_viewer(request, iid, conn=None, **kwargs):
586586
}
587587
if image.fileset is not None:
588588
paths = image.getImportedImageFilePaths()
589-
file_urls = []
590-
for path in paths["client_paths"]:
591-
if idrid in path:
592-
# we want path *after* /idr0002-heriche-condensation/
593-
# split on idrid handles mismatch like idr0047-neuert-yeastmrna with path idr0047-neuert-yeastmRNA
594-
file_path = path.split(idrid, 1)[-1]
595-
# remove before first "/" if present
596-
file_path = file_path.split("/", 1)[-1] if "/" in file_path else file_path
597-
if data_location == "Github":
598-
file_urls.append({"url": f"{github_url}/{urllib.parse.quote(file_path)}", "path": file_path})
599-
else:
600-
file_urls.append({"url": f"{download_url}/{urllib.parse.quote(file_path)}", "path": file_path})
601-
elif path.startswith("bia-idr/S-BIAD582/"):
602-
# for idr0151 path is e.g. bia-idr/S-BIAD582/05_wt_wg488-opa546-cadintron594-OPAprotein647/overlays/6a_05_wt_wg488-opa546-cadintron594-OPAprotein647_014_closeup_overlay.tif
603-
# Need to manually map to e.g...
604-
# https://ftp.ebi.ac.uk/biostudies/fire/S-BIAD/582/S-BIAD582/Files/05_wt_wg488-opa546-cadintron594-OPAprotein647/overlays/6a_05_wt_wg488-opa546-cadintron594-OPAprotein647_014_closeup_overlay.tif
605-
url = path.replace("bia-idr/S-BIAD582/", "https://ftp.ebi.ac.uk/biostudies/fire/S-BIAD/582/S-BIAD582/Files/")
606-
file_urls.append({"url": url, "path": path})
607-
else:
608-
file_urls.append({"url": None, "path": path})
609589
fileset_id = image.fileset.id.val
610590
rsp_json["fileset"] = {
611591
"id": fileset_id,
612592
"client_paths": paths["client_paths"],
613-
"file_urls": file_urls,
614593
}
615594
rsp_json["is_pattern"] = paths["client_paths"][0].endswith("pattern")
616595

0 commit comments

Comments
 (0)