Skip to content

Commit 5305e09

Browse files
committed
Add code to ensure the trackId in trix indexes matches the ID used in JBrowse
1 parent ed29f60 commit 5305e09

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.labkey.api.query.FieldKey;
3333
import org.labkey.api.query.QueryService;
3434
import org.labkey.api.query.UserSchema;
35+
import org.labkey.api.reader.Readers;
3536
import org.labkey.api.security.User;
3637
import org.labkey.api.security.permissions.ReadPermission;
3738
import org.labkey.api.sequenceanalysis.SequenceAnalysisService;
@@ -46,13 +47,16 @@
4647
import org.labkey.api.util.PageFlowUtil;
4748
import org.labkey.api.util.Path;
4849
import org.labkey.api.view.UnauthorizedException;
50+
import org.labkey.api.writer.PrintWriters;
4951
import org.labkey.jbrowse.JBrowseManager;
5052
import org.labkey.jbrowse.JBrowseSchema;
5153
import org.labkey.sequenceanalysis.run.util.TabixRunner;
5254

5355
import javax.annotation.Nullable;
56+
import java.io.BufferedReader;
5457
import java.io.File;
5558
import java.io.IOException;
59+
import java.io.PrintWriter;
5660
import java.sql.SQLException;
5761
import java.util.Arrays;
5862
import java.util.Collections;
@@ -836,6 +840,40 @@ public File prepareResource(Logger log, boolean throwIfNotPrepared, boolean forc
836840
{
837841
throw new PipelineJobException("Unable to find expected index file: " + ixx.getPath());
838842
}
843+
844+
// See here: https://github.com/GMOD/jbrowse-components/issues/2344
845+
// for background. this hackery is needed to ensure the trackId listed in the ix matches the GUID, not the filename:
846+
log.info("Updating trackId in trix ix file");
847+
File ix = getExpectedLocationOfIndexFile(".ix", false);
848+
if (!ix.exists())
849+
{
850+
throw new PipelineJobException("Unable to find file: " + ix.getPath());
851+
}
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+
}
839877
}
840878
}
841879

0 commit comments

Comments
 (0)