Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into fb_event_handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-tchad committed Aug 16, 2023
2 parents d6b80d1 + 67dbb11 commit 729ecbd
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 16 deletions.
10 changes: 5 additions & 5 deletions data/GPAT/plate-metadata-1.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"control" : {
"positive" : {"dilution": 0.005},
"negative" : {"dilution": 1.0}
"negative" : {"dilution": 1.01}
},
"sample" : {
"SA01" : {"dilution": 1.0, "ID" : 111, "Barcode" : "BC_111", "Concentration" : 0.0125},
"SA02" : {"dilution": 2.0, "ID" : 222, "Barcode" : "BC_222"},
"SA03" : {"dilution": 3.0, "ID" : 333, "Barcode" : "BC_333"},
"SA04" : {"dilution": 4.0, "ID" : 444, "Barcode" : "BC_444"}
"SA01" : {"dilution": 1.01, "ID" : 111, "Barcode" : "BC_111", "Concentration" : 0.0125},
"SA02" : {"dilution": 2.01, "ID" : 222, "Barcode" : "BC_222"},
"SA03" : {"dilution": 3.01, "ID" : 333, "Barcode" : "BC_333"},
"SA04" : {"dilution": 4.01, "ID" : 444, "Barcode" : "BC_444"}
}
}
22 changes: 20 additions & 2 deletions data/qc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,30 @@ project.tasks.register('transformJar', Jar) {
archiveFileName.set("transform.jar")
destinationDirectory = project.projectDir
manifest {
attributes 'Implementation-Title': 'Assay Validator Jar',
attributes 'Implementation-Title': 'Assay Transform Testing Jar',
'Implementation-Version': project.version,
'Built-By': System.getProperty("user.name"),
'Main-Class': 'org.labkey.AssayTransform'
}
}

project.tasks.register('transformNoopJar', Jar) {
group = "QC"
description = "Builds no-op transform jar for testing assay transforms"

from sourceSets.main.output
from { configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveFileName.set("transformNoop.jar")
destinationDirectory = project.projectDir
manifest {
attributes 'Implementation-Title': 'Assay No-Op Transform Jar',
'Implementation-Version': project.version,
'Built-By': System.getProperty("user.name"),
'Main-Class': 'org.labkey.AssayTransformNoOp'
}
}

project.tasks.register('transformWarningJar', Jar) {
group = "QC"
description = "Builds jar for doing assay transform warnings"
Expand All @@ -60,7 +77,7 @@ project.tasks.register('transformWarningJar', Jar) {
archiveFileName.set("transformWarning.jar")
destinationDirectory = project.projectDir
manifest {
attributes 'Implementation-Title': 'Assay Validator Jar',
attributes 'Implementation-Title': 'Assay Transform Warning Jar',
'Implementation-Version': project.version,
'Built-By': System.getProperty("user.name"),
'Main-Class': 'org.labkey.AssayTransformWarning'
Expand All @@ -72,6 +89,7 @@ var jarTask = project.tasks.named('jar')
jarTask.configure {
dependsOn(project.tasks.validatorJar)
dependsOn(project.tasks.transformJar)
dependsOn(project.tasks.transformNoopJar)
dependsOn(project.tasks.transformWarningJar)
}

Expand Down
55 changes: 55 additions & 0 deletions data/qc/src/org/labkey/AssayTransformNoOp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2015-2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.labkey;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class AssayTransformNoOp extends AbstractAssayValidator
{
public static void main(String[] args)
{
if (args.length < 4)
throw new IllegalArgumentException("Input data file not passed in");

File runProperties = new File(args[0]);
if (runProperties.exists())
{
AssayTransformNoOp transform = new AssayTransformNoOp();

transform.runTransform(runProperties, args[1], args[2], args[3]);
}
else
throw new IllegalArgumentException("Input data file does not exist");
}

public void runTransform(File inputFile, String username, String password, String host)
{
setEmail(username);
setPassword(password);
setHost(host);
parseRunProperties(inputFile);
}

}
7 changes: 7 additions & 0 deletions src/org/labkey/test/TestFileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@ public static File getTestTempDir()
return new File(buildDir, "testTemp");
}

public static File ensureTestTempDir() throws IOException
{
File file = getTestTempDir();
FileUtils.forceMkdir(file);
return file;
}

public static void delete(File file)
{
LOG.info("Deleting from filesystem: " + file.toString());
Expand Down
47 changes: 42 additions & 5 deletions src/org/labkey/test/tests/GpatPlateTemplateTest.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
package org.labkey.test.tests;

import org.apache.commons.io.FileUtils;
import org.jetbrains.annotations.Nullable;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.labkey.remoteapi.assay.ImportRunCommand;
import org.labkey.remoteapi.assay.ImportRunResponse;
import org.labkey.test.BaseWebDriverTest;
import org.labkey.test.Locator;
import org.labkey.test.TestFileUtils;
import org.labkey.test.TestTimeoutException;
import org.labkey.test.categories.Assays;
import org.labkey.test.categories.Daily;
import org.labkey.test.pages.ReactAssayDesignerPage;
import org.labkey.test.pages.assay.plate.PlateDesignerPage;
import org.labkey.test.util.APIAssayHelper;
import org.labkey.test.util.DataRegionTable;
import org.labkey.test.util.QCAssayScriptHelper;
import org.labkey.test.util.UIAssayHelper;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Category({Assays.class, Daily.class})
@BaseWebDriverTest.ClassTimeout(minutes = 7)
public class GpatPlateTemplateTest extends BaseWebDriverTest
{
private static final File TRANSFORM_SCRIPT = TestFileUtils.getSampleData("qc/transformNoop.jar");
private static final File TEST_PLATE_DATA = TestFileUtils.getSampleData("GPAT/plateData.xlsx");
// Issue 48470: Conversion error during assay API import with plate metadata
private static final File TEST_PLATE_METADATA = TestFileUtils.getSampleData("GPAT/plate-metadata-1.json");
private static final String ASSAY_NAME = "Assay with plate template";
private static final String templateName = "GPAT";
Expand All @@ -36,12 +47,18 @@ public static void setUpProject()

private void doSetup()
{
new QCAssayScriptHelper(this).ensureEngineConfig();

_containerHelper.createProject(getProjectName(), "Assay");
setPipelineRoot(TestFileUtils.getSampleData("GPAT").getAbsolutePath(), false);

goToProjectHome();
APIAssayHelper assayHelper = new APIAssayHelper(this);
assayHelper.createAssayWithPlateSupport(ASSAY_NAME);
new UIAssayHelper(this)
.createAssayDesign("General", ASSAY_NAME)
.setPlateMetadata(true)
// Regression check for Issue 48293: Standard Assay with Plate Metadata & Transformation Script throws an error
.addTransformScript(TRANSFORM_SCRIPT)
.clickFinish();
createPlateTemplate(templateName, "blank", "Standard", true);
}

Expand Down Expand Up @@ -69,6 +86,23 @@ public void doCleanup(boolean afterTest) throws TestTimeoutException
_containerHelper.deleteProject(getProjectName(), afterTest);
}

@Test
public void testApiWithPlateTemplateAndPlateMetadata() throws Exception
{
String runName = "ImportRun API with plate template and plate metadata";
int assayId = new APIAssayHelper(this).getIdFromAssayName(ASSAY_NAME, getProjectName());
File plateDataCopy = new File(TestFileUtils.ensureTestTempDir(), "API_" + TEST_PLATE_DATA.getName());

FileUtils.copyFile(TEST_PLATE_DATA, plateDataCopy);
ImportRunCommand importRunCommand = new ImportRunCommand(assayId, plateDataCopy);
importRunCommand.setProperties(Map.of("PlateTemplate", new APIAssayHelper(this).getPlateTemplateLsid(getProjectName(), templateName)));
importRunCommand.setPlateMetadata(new JSONObject(TestFileUtils.getFileContents(TEST_PLATE_METADATA)));
importRunCommand.setName(runName);
ImportRunResponse response = importRunCommand.execute(createDefaultConnection(), getProjectName());

Assert.assertTrue((Boolean)response.getParsedData().get("success"));
}

@Test
public void testWithPlateTemplateAndPlateMetadata()
{
Expand All @@ -83,15 +117,17 @@ public void testWithPlateTemplateAndPlateMetadata()

table.setFilter("Run/PlateTemplate", "Does Not Equal", templateName);
checker().verifyEquals("Only GPAT should be present", 0, table.getDataRowCount());
checker().screenShotIfNewError("rowsWithoutPlateTemplate");
table.clearAllFilters();

table.setFilter("PlateData/control_well_groups", "Is Not Blank");
checker().verifyEquals("Control well data is incorrect", Arrays.asList("positive", "negative"),
table.getColumnDataAsText("PlateData/control_well_groups"));
checker().verifyEquals("Well location is incorrect", Arrays.asList("A11", "A12"),
table.getColumnDataAsText("WellLocation"));
checker().verifyEquals("Dilution is incorrect", Arrays.asList("0.005", "1.0"),
table.getColumnDataAsText(" PlateData/dilution"));
checker().verifyEquals("Dilution is incorrect", Arrays.asList("0.005", "1.01"),
table.getColumnDataAsText("PlateData/dilution"));
checker().screenShotIfNewError("rowsInControlWells");
table.clearAllFilters();

table.setFilter("PlateData/control_well_groups", "Is Blank");
Expand All @@ -101,8 +137,9 @@ public void testWithPlateTemplateAndPlateMetadata()
table.getColumnDataAsText("PlateData/sample_well_groups"));
checker().verifyEquals("Barcode is incorrect", Arrays.asList("BC_111", "BC_111", "BC_111", "BC_222", "BC_222", "BC_222", "BC_333", "BC_333", "BC_444", "BC_444"),
table.getColumnDataAsText("PlateData/Barcode"));
checker().verifyEquals("Dilution is incorrect", Arrays.asList("1.0", "1.0", "1.0", "2.0", "2.0", "2.0", "3.0", "3.0", "4.0", "4.0"),
checker().verifyEquals("Dilution is incorrect", Arrays.asList("1.01", "1.01", "1.01", "2.01", "2.01", "2.01", "3.01", "3.01", "4.01", "4.01"),
table.getColumnDataAsText(" PlateData/dilution"));
checker().screenShotIfNewError("rowsOutsideControlWells");
table.clearAllFilters();
}

Expand Down
31 changes: 27 additions & 4 deletions src/org/labkey/test/util/APIAssayHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.labkey.test.WebTestHelper;
import org.labkey.test.pages.ReactAssayDesignerPage;
import org.labkey.test.params.assay.AssayDesign;
import org.openqa.selenium.NotFoundException;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -311,14 +312,36 @@ public void createAssayWithPlateSupport(String name)

public String getPlateTemplateLsid(String folderPath) throws Exception
{
SelectRowsCommand selectRowsCmd = new SelectRowsCommand("assay.General", "PlateTemplate");
selectRowsCmd.setColumns(List.of("Lsid"));

SelectRowsResponse resp = selectRowsCmd.execute(_test.createDefaultConnection(), folderPath);
SelectRowsResponse resp = getPlateTemplates(folderPath);

return String.valueOf(resp.getRows().get(0).get("Lsid"));
}

public String getPlateTemplateLsid(String folderPath, String name) throws Exception
{
SelectRowsResponse resp = getPlateTemplates(folderPath);
List<String> names = new ArrayList<>();
for (Map<String, Object> row : resp.getRows())
{
String rowName = (String) row.get("name");
if (rowName.equals(name))
{
return (String) row.get("Lsid");
}
names.add(rowName);
}

throw new NotFoundException("No plate template '%s'. Found: %s".formatted(name, names.toString()));
}

private SelectRowsResponse getPlateTemplates(String folderPath) throws IOException, CommandException
{
SelectRowsCommand selectRowsCmd = new SelectRowsCommand("assay.General", "PlateTemplate");
selectRowsCmd.setColumns(List.of("Name", "Lsid"));

return selectRowsCmd.execute(_test.createDefaultConnection(), folderPath);
}

public List<PropertyDescriptor> inferFieldsFromFile(File file, String containerPath) throws IOException, CommandException
{
return new InferDomainCommand(file, "Assay").execute(_test.createDefaultConnection(), containerPath)
Expand Down

0 comments on commit 729ecbd

Please sign in to comment.