Skip to content

Commit aa41171

Browse files
committed
Option to create readsets from SRA
1 parent 689af3e commit aa41171

File tree

3 files changed

+110
-5
lines changed

3 files changed

+110
-5
lines changed
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
/*
2-
* Copyright (c) 2012 LabKey Corporation
3-
*
4-
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
5-
*/
1+
var triggerHelper = new org.labkey.sequenceanalysis.query.SequenceTriggerHelper(LABKEY.Security.currentUser.id, LABKEY.Security.currentContainer.id);
62

73
function beforeDelete(row, errors){
84
if (!this.extraContext.deleteFromServer){
95
errors._form = 'You cannot directly delete readsets. To delete these records, use the delete button above the readset grid.';
106
}
7+
}
8+
9+
function afterInsert(row, errors) {
10+
if (row.sraAccessions) {
11+
triggerHelper.createReaddataForSra(row.rowid, row.sraAccessions);
12+
}
1113
}

SequenceAnalysis/src/org/labkey/sequenceanalysis/query/SequenceTriggerHelper.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
import org.biojava.nbio.core.sequence.transcription.TranscriptionEngine;
1414
import org.junit.Assert;
1515
import org.junit.Test;
16+
import org.labkey.api.assay.AssayFileWriter;
1617
import org.labkey.api.data.Container;
1718
import org.labkey.api.data.ContainerManager;
1819
import org.labkey.api.data.SimpleFilter;
20+
import org.labkey.api.data.Table;
1921
import org.labkey.api.data.TableInfo;
2022
import org.labkey.api.data.TableSelector;
2123
import org.labkey.api.exp.api.DataType;
@@ -28,12 +30,19 @@
2830
import org.labkey.api.security.User;
2931
import org.labkey.api.security.UserManager;
3032
import org.labkey.api.sequenceanalysis.RefNtSequenceModel;
33+
import org.labkey.api.util.FileUtil;
34+
import org.labkey.api.util.Path;
35+
import org.labkey.sequenceanalysis.ReadDataImpl;
3136
import org.labkey.sequenceanalysis.SequenceAnalysisSchema;
37+
import org.labkey.sequenceanalysis.SequenceAnalysisServiceImpl;
38+
import org.labkey.sequenceanalysis.SequenceReadsetImpl;
39+
import org.labkey.vfs.FileLike;
3240

3341
import java.io.File;
3442
import java.io.IOException;
3543
import java.io.StringWriter;
3644
import java.util.Arrays;
45+
import java.util.Date;
3746
import java.util.HashMap;
3847
import java.util.List;
3948
import java.util.Map;
@@ -254,4 +263,64 @@ public int createExpData(String relPath) {
254263

255264
return d.getRowId();
256265
}
266+
267+
public void createReaddataForSra(int readsetId, String sraAccessions)
268+
{
269+
SequenceReadsetImpl rs = SequenceAnalysisServiceImpl.get().getReadset(readsetId, _user);
270+
if (rs == null)
271+
{
272+
throw new IllegalArgumentException("Unable to find readset: " + readsetId);
273+
}
274+
275+
TableInfo rd = SequenceAnalysisSchema.getTable(SequenceAnalysisSchema.TABLE_READ_DATA);
276+
277+
String[] tokens = StringUtils.split(sraAccessions, ",");
278+
for (String token : tokens)
279+
{
280+
if (rs.getReadData() != null && !rs.getReadData().isEmpty())
281+
{
282+
throw new IllegalArgumentException("Did not expect readset to have existing readdata: " + rs.getReadsetId());
283+
}
284+
285+
// Create new:
286+
ReadDataImpl rd1 = new ReadDataImpl();
287+
rd1.setReadset(readsetId);
288+
rd1.setContainer(rs.getContainer());
289+
rd1.setCreated(new Date());
290+
rd1.setModified(new Date());
291+
rd1.setCreatedBy(_user.getUserId());
292+
rd1.setModifiedBy(_user.getUserId());
293+
rd1.setSra_accession(token);
294+
rd1.setArchived(true);
295+
296+
// NOTE: this is a fragile assumption. We might need to eventually query SRA to figure out whether data is paired:
297+
Container c = ContainerManager.getForId(rs.getContainer());
298+
PipeRoot pr = PipelineService.get().findPipelineRoot(c);
299+
if (pr == null)
300+
{
301+
throw new IllegalStateException("Unable to find pipeline root for: " + c.getPath());
302+
}
303+
304+
String folderName = "SequenceImport_" + FileUtil.getTimestamp();
305+
FileLike outDir = AssayFileWriter.findUniqueFileName(folderName, pr.getRootFileLike());
306+
307+
FileLike expectedFile1 = FileUtil.appendPath(outDir, Path.parse(token + "_1.fastq.gz"));
308+
ExpData exp1 = ExperimentService.get().createData(c, new DataType("Data"));
309+
exp1.setDataFileURI(expectedFile1.toURI());
310+
exp1.setContainer(c);
311+
exp1.setName(expectedFile1.getName());
312+
exp1.save(_user);
313+
rd1.setFileId1(exp1.getRowId());
314+
315+
FileLike expectedFile2 = FileUtil.appendPath(outDir, Path.parse(token + "_2.fastq.gz"));
316+
ExpData exp2 = ExperimentService.get().createData(c, new DataType("Data"));
317+
exp2.setDataFileURI(expectedFile2.toURI());
318+
exp2.setContainer(c);
319+
exp2.setName(expectedFile2.getName());
320+
exp2.save(_user);
321+
rd1.setFileId2(exp2.getRowId());
322+
323+
Table.insert(_user, rd, rd1);
324+
}
325+
}
257326
}

SequenceAnalysis/test/src/org/labkey/test/tests/external/labModules/SequenceTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,28 @@ private void importReadsetMetadata()
195195
log("verifying readset count correct");
196196
waitForText("Sequence Readsets");
197197
waitForElement(LabModuleHelper.getNavPanelItem("Sequence Readsets:", _readsetCt.toString()));
198+
199+
// Repeat, adding SRA accessions:
200+
goToProjectHome();
201+
waitAndClick(Locator.linkWithText("Plan Sequence Run (Create Readsets)"));
202+
new Window.WindowFinder(getDriver()).withTitle("Create Readsets").waitFor();
203+
waitAndClickAndWait(Ext4Helper.Locators.ext4Button("Submit"));
204+
205+
_helper.waitForField("Sample Id", WAIT_FOR_PAGE);
206+
_ext4Helper.clickTabContainingText("Import Spreadsheet");
207+
waitForText("Copy/Paste Data");
208+
209+
setFormElementJS(Locator.name("text"), getIlluminaSRANames());
210+
211+
waitAndClick(Ext4Helper.Locators.ext4Button("Upload"));
212+
new Window.WindowFinder(getDriver()).withTitle("Success").waitFor();
213+
_readsetCt += 3;
214+
assertTextPresent("Success!");
215+
waitAndClickAndWait(Ext4Helper.Locators.ext4Button("OK"));
216+
217+
log("verifying readset count correct");
218+
waitForText("Sequence Readsets");
219+
waitForElement(LabModuleHelper.getNavPanelItem("Sequence Readsets:", _readsetCt.toString()));
198220
}
199221

200222
/**
@@ -320,6 +342,18 @@ private String getIlluminaNames()
320342
return sb.toString();
321343
}
322344

345+
private String getIlluminaSRANames()
346+
{
347+
StringBuilder sb = new StringBuilder("Name\tPlatform\tsraAccessions\n");
348+
int i = 0;
349+
while (i < 3)
350+
{
351+
sb.append("IlluminaSRA" + (i + 1) + "\tILLUMINA\tSRA" + idx + "\n");
352+
i++;
353+
}
354+
return sb.toString();
355+
}
356+
323357
/**
324358
* This test will kick off a pipeline import using the illumina pipeline. Verification of the result
325359
* is performed by readsetFeaturesTest()

0 commit comments

Comments
 (0)