|
30 | 30 | import org.labkey.api.query.UserSchema; |
31 | 31 | import org.labkey.api.settings.AppProps; |
32 | 32 | import org.labkey.api.util.DOM; |
33 | | -import org.labkey.api.util.DOM.Renderable; |
34 | 33 | import org.labkey.api.util.FileUtil; |
35 | 34 | import org.labkey.api.util.HtmlString; |
36 | 35 | import org.labkey.api.util.LinkBuilder; |
@@ -284,65 +283,10 @@ public boolean isSortable() |
284 | 283 | return false; |
285 | 284 | } |
286 | 285 |
|
287 | | - private String getAnalyticsScript(String eventAction, String fileName, boolean addWaitTime) |
| 286 | + private HtmlString externalHeatmapViewerLink(String fileName, LincsModule.LincsAssay assayType) |
288 | 287 | { |
289 | | - if (!StringUtils.isBlank(AnalyticsService.getTrackingScript())) |
290 | | - { |
291 | | - // http://www.blastam.com/blog/how-to-track-downloads-in-google-analytics |
292 | | - // Tell the browser to wait 400ms before going to the download. This is to ensure |
293 | | - // that the GA tracking request goes through. Some browsers will interrupt the tracking |
294 | | - // request if the download opens on the same page. |
295 | | - String timeout = addWaitTime ? "that=this; setTimeout(function(){location.href=that.href;},400);return false;" : ""; |
296 | | - |
297 | | - // GA4 variant |
298 | | - String onClickScript = "try {gtag('event', 'Lincs', {eventAction: " + PageFlowUtil.qh(eventAction) + ", fileName: " + PageFlowUtil.qh(fileName) + "}); } catch(err) {}"; |
299 | | - onClickScript += timeout; |
300 | | - return onClickScript; |
301 | | - } |
302 | | - return null; |
303 | | - } |
304 | | - |
305 | | - private Renderable externalHeatmapViewerLink(String fileName, LincsModule.LincsAssay assayType) |
306 | | - { |
307 | | - String gctFileUrl = davUrl + "GCT/" + PageFlowUtil.encodePath(fileName); |
308 | | - String morpheusUrl = getMorpheusUrl(gctFileUrl, assayType); |
309 | | - |
310 | | - String analyticsScript = getAnalyticsScript("Morpheus", fileName, false); |
311 | | - |
312 | | - String imgUrl = AppProps.getInstance().getContextPath() + "/lincs/GENE-E_icon.png"; |
313 | | - |
314 | | - LinkBuilder viewInMorpheusLink = LinkBuilder.simpleLink("View in Morpheus", morpheusUrl).target("_blank"); |
315 | | - if (analyticsScript != null) |
316 | | - { |
317 | | - viewInMorpheusLink.onClick(analyticsScript); |
318 | | - } |
319 | | - |
320 | | - return DOM.SPAN("[", |
321 | | - HtmlString.NBSP, |
322 | | - viewInMorpheusLink, |
323 | | - IMG(at(src, imgUrl).at(width, 13).at(height, 13)), |
324 | | - HtmlString.NBSP, |
325 | | - "]"); |
326 | | - } |
327 | | - |
328 | | - private String getMorpheusUrl(String gctFileUrl, LincsModule.LincsAssay assayType) |
329 | | - { |
330 | | - String morpheusJson = "{\"dataset\":\"" + gctFileUrl + "\","; |
331 | | - if(assayType == LincsModule.LincsAssay.P100) |
332 | | - { |
333 | | - morpheusJson += "\"rows\":[{\"field\":\"pr_p100_modified_peptide_code\",\"display\":\"Text\"},{\"field\":\"pr_gene_symbol\",\"display\":\"Text\"},{\"field\":\"pr_p100_phosphosite\",\"display\":\"Text\"},{\"field\":\"pr_uniprot_id\",\"display\":\"Text\"}],"; |
334 | | - } |
335 | | - if(assayType == LincsModule.LincsAssay.GCP) |
336 | | - { |
337 | | - morpheusJson += "\"rows\":[{\"field\":\"pr_gcp_histone_mark\",\"display\":\"Text\"},{\"field\":\"pr_gcp_modified_peptide_code\",\"display\":\"Text\"}],"; |
338 | | - } |
339 | | - morpheusJson += "\"columns\":[{\"field\":\"pert_iname\",\"display\":\"Text\"},{\"field\":\"det_well\",\"display\":\"Text\"}],"; |
340 | | - morpheusJson += "\"colorScheme\":{\"type\":\"fixed\",\"map\":[{\"value\":-3,\"color\":\"blue\"},{\"value\":0,\"color\":\"white\"},{\"value\":3,\"color\":\"red\"}]}"; |
341 | | - morpheusJson += "}"; |
342 | | - |
343 | | - String morpheusUrl= "http://www.broadinstitute.org/cancer/software/morpheus/?json="; |
344 | | - morpheusUrl += PageFlowUtil.encodeURIComponent(morpheusJson); |
345 | | - return morpheusUrl; |
| 288 | + String gctFileUrl = getDavUrl() + "GCT/" + PageFlowUtil.encodePath(fileName); |
| 289 | + return LincsDataTable.externalHeatmapViewerLink(fileName, assayType, gctFileUrl); |
346 | 290 | } |
347 | 291 |
|
348 | 292 | @Override |
@@ -378,12 +322,12 @@ public void renderGridCellContents(RenderContext ctx, HtmlWriter out) |
378 | 322 |
|
379 | 323 | String actionName = (getLevel() == LincsModule.LincsLevel.Config) ? "DownloadConfig" : "DownloadGCT"; |
380 | 324 | String analyticsScript = getAnalyticsScript(actionName, downloadFileName, true); |
381 | | - Renderable morpheusUrl = externalHeatmapViewerLink(downloadFileName, getAssayType(), getLevel()); |
| 325 | + HtmlString morpheusUrl = externalHeatmapViewerLink(downloadFileName, getAssayType(), getLevel()); |
382 | 326 | String downloadText = (getLevel() == LincsModule.LincsLevel.Config) ? "CFG" : "GCT"; |
383 | 327 | renderGridCell(out, analyticsScript, getGctDavUrlUnencoded(downloadFileName), downloadText, morpheusUrl); |
384 | 328 | } |
385 | 329 |
|
386 | | - private void renderGridCell(HtmlWriter out, String analyticsScript, String downloadUrl, String downloadText, Renderable morpheusUrl) |
| 330 | + private void renderGridCell(HtmlWriter out, String analyticsScript, String downloadUrl, String downloadText, HtmlString morpheusUrl) |
387 | 331 | { |
388 | 332 | // <span style="white-space: nowrap;"> is recommended instead of deprecated <nobr></nobr> |
389 | 333 | SPAN( |
@@ -421,7 +365,7 @@ private boolean fileAvailable(Integer runId, String downloadFileName) |
421 | 365 | } |
422 | 366 | } |
423 | 367 |
|
424 | | - @Nullable Renderable externalHeatmapViewerLink(String fileName, LincsModule.LincsAssay assayType, LincsModule.LincsLevel level) |
| 368 | + @Nullable HtmlString externalHeatmapViewerLink(String fileName, LincsModule.LincsAssay assayType, LincsModule.LincsLevel level) |
425 | 369 | { |
426 | 370 | if(level == LincsModule.LincsLevel.Config) |
427 | 371 | { |
@@ -497,4 +441,65 @@ public Object getDisplayValue(RenderContext ctx) |
497 | 441 | return getValue(ctx); |
498 | 442 | } |
499 | 443 | } |
| 444 | + |
| 445 | + private static String getAnalyticsScript(String eventAction, String fileName, boolean addWaitTime) |
| 446 | + { |
| 447 | + if (!StringUtils.isBlank(AnalyticsService.getTrackingScript())) |
| 448 | + { |
| 449 | + // http://www.blastam.com/blog/how-to-track-downloads-in-google-analytics |
| 450 | + // Tell the browser to wait 400ms before going to the download. This is to ensure |
| 451 | + // that the GA tracking request goes through. Some browsers will interrupt the tracking |
| 452 | + // request if the download opens on the same page. |
| 453 | + String timeout = addWaitTime ? "that=this; setTimeout(function(){location.href=that.href;},400);return false;" : ""; |
| 454 | + |
| 455 | + // GA4 variant |
| 456 | + String onClickScript = "try {gtag('event', 'Lincs', {eventAction: " + PageFlowUtil.qh(eventAction) + ", fileName: " + PageFlowUtil.qh(fileName) + "}); } catch(err) {}"; |
| 457 | + onClickScript += timeout; |
| 458 | + return onClickScript; |
| 459 | + } |
| 460 | + return null; |
| 461 | + } |
| 462 | + |
| 463 | + public static HtmlString externalHeatmapViewerLink(String fileName, LincsModule.LincsAssay assayType, String gctFileDavUrl) |
| 464 | + { |
| 465 | + String morpheusUrl = getMorpheusUrl(gctFileDavUrl, assayType); |
| 466 | + |
| 467 | + String analyticsScript = getAnalyticsScript("Morpheus", fileName, false); |
| 468 | + |
| 469 | + String imgUrl = AppProps.getInstance().getContextPath() + "/lincs/GENE-E_icon.png"; |
| 470 | + |
| 471 | + LinkBuilder viewInMorpheusLink = LinkBuilder.simpleLink("View in Morpheus", morpheusUrl).target("_blank"); |
| 472 | + if (analyticsScript != null) |
| 473 | + { |
| 474 | + viewInMorpheusLink.onClick(analyticsScript); |
| 475 | + } |
| 476 | + |
| 477 | + return HtmlString.of(DOM.SPAN("[", |
| 478 | + HtmlString.NBSP, |
| 479 | + viewInMorpheusLink, |
| 480 | + HtmlString.NBSP, |
| 481 | + IMG(at(src, imgUrl).at(width, 13).at(height, 13)), |
| 482 | + HtmlString.NBSP, |
| 483 | + "]")); |
| 484 | + } |
| 485 | + |
| 486 | + private static String getMorpheusUrl(String gctFileUrl, LincsModule.LincsAssay assayType) |
| 487 | + { |
| 488 | + String morpheusJson = "{\"dataset\":\"" + gctFileUrl + "\","; |
| 489 | + if(assayType == LincsModule.LincsAssay.P100) |
| 490 | + { |
| 491 | + morpheusJson += "\"rows\":[{\"field\":\"pr_p100_modified_peptide_code\",\"display\":\"Text\"},{\"field\":\"pr_gene_symbol\",\"display\":\"Text\"},{\"field\":\"pr_p100_phosphosite\",\"display\":\"Text\"},{\"field\":\"pr_uniprot_id\",\"display\":\"Text\"}],"; |
| 492 | + } |
| 493 | + if(assayType == LincsModule.LincsAssay.GCP) |
| 494 | + { |
| 495 | + morpheusJson += "\"rows\":[{\"field\":\"pr_gcp_histone_mark\",\"display\":\"Text\"},{\"field\":\"pr_gcp_modified_peptide_code\",\"display\":\"Text\"}],"; |
| 496 | + } |
| 497 | + morpheusJson += "\"columns\":[{\"field\":\"pert_iname\",\"display\":\"Text\"},{\"field\":\"det_well\",\"display\":\"Text\"}],"; |
| 498 | + morpheusJson += "\"colorScheme\":{\"type\":\"fixed\",\"map\":[{\"value\":-3,\"color\":\"blue\"},{\"value\":0,\"color\":\"white\"},{\"value\":3,\"color\":\"red\"}]}"; |
| 499 | + morpheusJson += "}"; |
| 500 | + |
| 501 | + String morpheusUrl= "http://www.broadinstitute.org/cancer/software/morpheus/?json="; |
| 502 | + morpheusUrl += PageFlowUtil.encodeURIComponent(morpheusJson); |
| 503 | + return morpheusUrl; |
| 504 | + } |
500 | 505 | } |
0 commit comments