Skip to content

Commit 4f61590

Browse files
authored
Workaround for more strict jbrowse enforcement of trackId vs trix index (#163)
1 parent 5305e09 commit 4f61590

File tree

3 files changed

+22
-37
lines changed

3 files changed

+22
-37
lines changed

jbrowse/src/client/JBrowse/Browser/plugins/ExtendedVariantPlugin/ExtendedVariantWidget/ExtendedVariantWidget.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {FIELD_NAME_MAP, INFO_FIELD_GROUPS, IGNORED_INFO_FIELDS} from "./fields";
2-
import {ActionURL} from "@labkey/api";
1+
import {FIELD_NAME_MAP, IGNORED_INFO_FIELDS, INFO_FIELD_GROUPS} from "./fields";
32
import {Chart} from "react-google-charts";
43
import {style as styles} from "./style";
4+
import {getGenotypeURL} from "../../../../utils";
55

66
export default jbrowse => {
77
const {
@@ -245,8 +245,7 @@ export default jbrowse => {
245245
const start = feat["POS"];
246246
const end = feat["end"];
247247

248-
const link = ActionURL.buildURL("jbrowse", "genotypeTable.view", null, {trackId: trackId, chr: contig, start: start, stop: end})
249-
const href = <a href={link} target="_blank">Click here to view sample-level genotypes</a>
248+
const href = <a href={getGenotypeURL(trackId, contig, start, end)} target="_blank">Click here to view sample-level genotypes</a>
250249

251250
setState(
252251
<div>

jbrowse/src/client/JBrowse/utils.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export async function fetchSession(queryParam, sessionId, nativePlugins, refThem
133133
}
134134
},
135135
failure: function(res){
136-
handleFailure("There was an error: " + res.status, sessionId, trackId, isTable)
136+
handleFailure("There was an error: " + res.status, sessionId, trackId, isTable, false)
137137
},
138138
params: {session: sessionId, activeTracks: activeTracks ? activeTracks.join(',') : undefined}
139139
});
@@ -244,10 +244,10 @@ function serializeInfoFilters(track) {
244244
return track.configuration.trackId + ":" + encodeURIComponent(track.configuration.displays[0].renderer.infoFilters.valueJSON)
245245
}
246246

247-
function handleFailure(error, sessionId?, trackId?, isTable?) {
247+
function handleFailure(error, sessionId?, trackId?, isTable?, reloadOnFailure = true) {
248248
alert(error)
249249

250-
if (sessionId && trackId) {
250+
if (reloadOnFailure && sessionId && trackId) {
251251
if (isTable) {
252252
navigateToTable(sessionId, "", trackId)
253253
} else {
@@ -257,5 +257,12 @@ function handleFailure(error, sessionId?, trackId?, isTable?) {
257257
}
258258

259259
export function getGenotypeURL(trackId, contig, start, end) {
260+
// NOTE: due to jbrowse/trix behavior, the trackId that gets serialized into the trix index is the actual trackGUID plus the filename.
261+
// Since this action expects the GUID alone, detect long filenames and subset.
262+
// TODO: once this behavior is fixed in jbrowse, remove this logic
263+
if (trackId.length > 36) {
264+
trackId = trackId.substr(0,36)
265+
}
266+
260267
return ActionURL.buildURL("jbrowse", "genotypeTable.view", null, {trackId: trackId, chr: contig, start: start, stop: end})
261268
}

jbrowse/src/org/labkey/jbrowse/model/JsonFile.java

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,9 @@ private JSONObject getVcfTrack(Logger log, ExpData targetFile, ReferenceGenome r
501501
{
502502
JSONObject ret = new JSONObject();
503503
ret.put("type", getTrackType());
504-
ret.put("trackId", getObjectId());
504+
final File finalLocation = getLocationOfProcessedTrack(false);
505+
ret.put("trackId", finalLocation == null ? null : finalLocation.getName());
506+
ret.put("trackGUID", getObjectId());
505507
ret.put("name", getLabel());
506508
ret.put("assemblyNames", new JSONArray(){{
507509
put(JBrowseSession.getAssemblyName(rg));
@@ -567,7 +569,9 @@ private JSONObject getBamTrack(Logger log, ExpData targetFile, ReferenceGenome r
567569
{
568570
JSONObject ret = new JSONObject();
569571
ret.put("type", getTrackType());
570-
ret.put("trackId", getObjectId());
572+
final File finalLocation = getLocationOfProcessedTrack(false);
573+
ret.put("trackId", finalLocation == null ? null : finalLocation.getName());
574+
ret.put("trackGUID", getObjectId());
571575
ret.put("name", getLabel());
572576
ret.put("category", new JSONArray(){{
573577
put(getCategory());
@@ -651,7 +655,9 @@ private JSONObject getTabixTrack(Logger log, ExpData targetFile, ReferenceGenome
651655
{
652656
JSONObject ret = new JSONObject();
653657
ret.put("type", getTrackType());
654-
ret.put("trackId", getObjectId());
658+
final File finalLocation = getLocationOfProcessedTrack(false);
659+
ret.put("trackId", finalLocation == null ? null : finalLocation.getName());
660+
ret.put("trackGUID", getObjectId());
655661
ret.put("name", getLabel());
656662
ret.put("category", new JSONArray(){{
657663
put(getCategory());
@@ -833,8 +839,6 @@ public File prepareResource(Logger log, boolean throwIfNotPrepared, boolean forc
833839
wrapper.setWorkingDir(targetFile.getParentFile());
834840
wrapper.setThrowNonZeroExits(true);
835841

836-
//TODO: eventually remove this. see: https://github.com/GMOD/jbrowse-components/issues/2354#issuecomment-926320747
837-
wrapper.addToEnvironment("DEBUG", "*");
838842
wrapper.execute(Arrays.asList(exe.getPath(), "text-index", "--force", "--quiet", "--attributes", StringUtils.join(attributes, ","), "--prefixSize", "5", "--file", targetFile.getPath()));
839843
if (!ixx.exists())
840844
{
@@ -849,31 +853,6 @@ public File prepareResource(Logger log, boolean throwIfNotPrepared, boolean forc
849853
{
850854
throw new PipelineJobException("Unable to find file: " + ix.getPath());
851855
}
852-
853-
File ixCopy = new File(ix.getPath() + ".tmp");
854-
try (PrintWriter writer = PrintWriters.getPrintWriter(ixCopy); BufferedReader reader = Readers.getReader(ix))
855-
{
856-
String line;
857-
while ((line = reader.readLine()) != null)
858-
{
859-
line = line.replaceAll("\"" + targetFile.getName() + "\"", "\"" + getObjectId() + "\"");
860-
writer.println(line);
861-
}
862-
}
863-
catch (IOException e)
864-
{
865-
throw new PipelineJobException(e);
866-
}
867-
868-
try
869-
{
870-
ix.delete();
871-
FileUtils.moveFile(ixCopy, ix);
872-
}
873-
catch (IOException e)
874-
{
875-
throw new PipelineJobException(e);
876-
}
877856
}
878857
}
879858

0 commit comments

Comments
 (0)