Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion gortools/src/main/scala/gorsat/Macros/PGor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class PGor extends MacroInfo("PGOR", CommandArguments("-nowithin", "-gordfolder"

val linkMetaOptions = LinkFileUtil.extractLinkMetaOptionData(queryAppend)
if (!Strings.isNullOrEmpty(linkMetaOptions)) {
gordict += " -linkMeta " + linkMetaOptions
gordict += String.format(" -linkMeta '%s'", linkMetaOptions)
}

val cmd = splitManager.chromosomeSplits.keys.foldLeft(gordict)((x, y) => x + " [" + theKey + "_" + y + "] " +
Expand Down
2 changes: 1 addition & 1 deletion gortools/src/main/scala/gorsat/Macros/Parallel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Parallel extends MacroInfo("PARALLEL", CommandArguments("-gordfolder", "-p

val linkMetaOptions = LinkFileUtil.extractLinkMetaOptionData(create.query)
if (!Strings.isNullOrEmpty(linkMetaOptions)) {
theCommand += " -linkMeta " + linkMetaOptions
theCommand += String.format(" -linkMeta '%s'", linkMetaOptions)
}
parGorCommands.put(createKey, ExecutionBlock(create.groupName, theCommand, create.signature, theDependencies.toArray, create.batchGroupName, cachePath, isDictionary = true, hasForkWrite = hasForkWrite))

Expand Down
36 changes: 36 additions & 0 deletions gortools/src/test/java/gorsat/UTestGorWrite.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,24 @@ public void testWriteLinkFileForGordFolder() throws IOException {
Assert.assertEquals(linkresult1, linkresult3);
}

@Test
public void testWriteLinkFileForGordFolderWithLinkMetaPgor() throws IOException {
Path p = Paths.get("../tests/data/gor/dbsnp_test.gor");
Files.copy(p, workDirPath.resolve("dbsnp.gor"));
TestUtils.runGorPipe("pgor dbsnp.gor | write -link dbsnp3.gord -linkmeta 'TEST1=T1,TEST2=T2' dbsnp2.gord", "-gorroot", workDirPath.toString());

var linkFile = LinkFile.load(new FileSource(workDirPath.resolve("dbsnp3.gord.link").toString()));

Assert.assertEquals(1, linkFile.getEntriesCount());
Assert.assertEquals(workDirPath.resolve("dbsnp2.gord"), Path.of(linkFile.getLatestEntry().url()));
Assert.assertEquals("T1", linkFile.getMeta().getProperty("TEST1"));
Assert.assertEquals("T2", linkFile.getMeta().getProperty("TEST2"));

String linkresult1 = TestUtils.runGorPipe("gor dbsnp.gor | top 1000", "-gorroot", workDirPath.toString());
String linkresult3 = TestUtils.runGorPipe("gor dbsnp3.gord | top 1000", "-gorroot", workDirPath.toString());
Assert.assertEquals(linkresult1, linkresult3);
}

@Test
public void testWriteLinkFileForGordFolderParallel() throws IOException {
Path p = Paths.get("../tests/data/gor/dbsnp_test.gor");
Expand All @@ -309,6 +327,24 @@ public void testWriteLinkFileForGordFolderParallel() throws IOException {
Assert.assertEquals(linkresult1, linkresult3);
}

@Test
public void testWriteLinkFileForGordFolderParallelWithLinkMeta() throws IOException {
Path p = Paths.get("../tests/data/gor/dbsnp_test.gor");
Files.copy(p, workDirPath.resolve("dbsnp.gor"));
TestUtils.runGorPipe("parallel -parts <(nor dbsnp.gor | select chrom | distinct) <(gor -p #{col:Chrom} dbsnp.gor) | write -link dbsnp3.gord -linkmeta 'TEST1=T1,TEST2=T2' dbsnp2.gord", "-gorroot", workDirPath.toString());

var linkFile = LinkFile.load(new FileSource(workDirPath.resolve("dbsnp3.gord.link").toString()));

Assert.assertEquals(1, linkFile.getEntriesCount());
Assert.assertEquals(workDirPath.resolve("dbsnp2.gord"), Path.of(linkFile.getLatestEntry().url()));
Assert.assertEquals("T1", linkFile.getMeta().getProperty("TEST1"));
Assert.assertEquals("T2", linkFile.getMeta().getProperty("TEST2"));

String linkresult1 = TestUtils.runGorPipe("gor dbsnp.gor | top 1000", "-gorroot", workDirPath.toString());
String linkresult3 = TestUtils.runGorPipe("gor dbsnp3.gord | top 1000", "-gorroot", workDirPath.toString());
Assert.assertEquals(linkresult1, linkresult3);
}

@Test
public void testWriteLinkFileForGordFolderInferFilename() throws IOException {
Path p = Paths.get("../tests/data/gor/dbsnp_test.gor");
Expand Down
4 changes: 2 additions & 2 deletions model/src/main/java/org/gorpipe/gor/driver/meta/DataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public enum DataType {
GORP(TABLE, ".gorp", true),
GORQ(REPORT, ".gorq"),
LINK(REFERENCE, ".link"),
VERSIONED_LINK(REFERENCE, ".versioned.link"),
GORD_INTERNAL_LINK(REFERENCE, ".internal.link"), // Gord internal link type
// VERSIONED_LINK(REFERENCE, ".versioned.link"),
GORD_INTERNAL_LINK(REFERENCE, ".link"), // Gord internal link type
CRAM(VARIANTS, ".cram", true),
CRAI(INDEX, ".crai"),
SPEC(VARIANTS, ".spec"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected TableInfoBase(String uri, FileReader inputFileReader, TableHeader head
this.rootUri = realUri;
this.folderPath = rootUri;
this.linkPath = PathUtils.resolve(rootUri, DataUtil.toFile(GorOptions.DEFAULT_FOLDER_DICTIONARY_NAME, DataType.GORD_INTERNAL_LINK));
try (var linkFileSource = fileReader.resolveUrl(linkPath)) {
try (var linkFileSource = resolveGordUrl(linkPath)) {
this.path = linkFileSource != null ? linkFileSource.getFullPath() : getNewVersionedFileName();
}
} else if (safeCheckExists(PathUtils.resolve(realUri, GorOptions.DEFAULT_FOLDER_DICTIONARY_NAME))) {
Expand Down Expand Up @@ -354,4 +354,18 @@ protected String getNewVersionedFileName() {
return PathUtils.resolve(getFolderPath(),
PathUtils.injectRandomStringIntoFileName("version" + DataType.GORD.suffix));
}

/**
* Resolve gord path. Traverses and fins thddict.gord files.
* @param path path to resolve. Should be gord path.
* @return the path to the acutal gord file.
*/
protected DataSource resolveGordUrl(String path) {
var source = fileReader.resolveUrl(path);
while (source.isDirectory()) {
path = source.getPath().resolve(GorOptions.DEFAULT_FOLDER_DICTIONARY_NAME).toString();
source = fileReader.resolveUrl(path);
}
return source;
}
}
Loading