6202 |
09 Apr 21 |
nicklas |
1 |
package net.sf.basedb.reggie.plugins.cmd; |
6202 |
09 Apr 21 |
nicklas |
2 |
|
6205 |
12 Apr 21 |
nicklas |
3 |
import java.util.List; |
6202 |
09 Apr 21 |
nicklas |
4 |
|
6205 |
12 Apr 21 |
nicklas |
5 |
import net.sf.basedb.core.DbControl; |
6205 |
12 Apr 21 |
nicklas |
6 |
import net.sf.basedb.core.ItemQuery; |
6205 |
12 Apr 21 |
nicklas |
7 |
import net.sf.basedb.core.PhysicalBioAssay; |
6205 |
12 Apr 21 |
nicklas |
8 |
import net.sf.basedb.core.query.Annotations; |
6205 |
12 Apr 21 |
nicklas |
9 |
import net.sf.basedb.core.query.Expressions; |
6205 |
12 Apr 21 |
nicklas |
10 |
import net.sf.basedb.core.query.Hql; |
6205 |
12 Apr 21 |
nicklas |
11 |
import net.sf.basedb.core.query.Restrictions; |
6205 |
12 Apr 21 |
nicklas |
12 |
import net.sf.basedb.reggie.Reggie; |
6205 |
12 Apr 21 |
nicklas |
13 |
import net.sf.basedb.reggie.dao.Annotationtype; |
6205 |
12 Apr 21 |
nicklas |
14 |
import net.sf.basedb.reggie.dao.FlowCell; |
6205 |
12 Apr 21 |
nicklas |
15 |
import net.sf.basedb.reggie.dao.PooledLibrary; |
6205 |
12 Apr 21 |
nicklas |
16 |
import net.sf.basedb.reggie.dao.Subtype; |
6960 |
13 Dec 22 |
nicklas |
17 |
import net.sf.basedb.util.Values; |
6205 |
12 Apr 21 |
nicklas |
18 |
|
6202 |
09 Apr 21 |
nicklas |
19 |
/** |
6202 |
09 Apr 21 |
nicklas |
Holds all information about a flow cell. Validation will |
6202 |
09 Apr 21 |
nicklas |
be done at construction and errors are reported to |
6202 |
09 Apr 21 |
nicklas |
the JsonSection. Check the 'valid' flag before using |
6202 |
09 Apr 21 |
nicklas |
the information. |
6202 |
09 Apr 21 |
nicklas |
24 |
|
6202 |
09 Apr 21 |
nicklas |
NOTE! We do not read the "FlowCellType" entry from this |
6202 |
09 Apr 21 |
nicklas |
section. Instead we use the "SequencingRun/SerialNumber" |
6202 |
09 Apr 21 |
nicklas |
entry to locate a Hardware item (Sequencer) in our database |
6202 |
09 Apr 21 |
nicklas |
and take the "FlowCellType" annotation from that item. This |
6202 |
09 Apr 21 |
nicklas |
is done in the {@link SequencingRunInfo} class. |
6202 |
09 Apr 21 |
nicklas |
30 |
|
6202 |
09 Apr 21 |
nicklas |
@since 4.32 |
6202 |
09 Apr 21 |
nicklas |
32 |
*/ |
6202 |
09 Apr 21 |
nicklas |
33 |
public class FlowCellInfo |
6202 |
09 Apr 21 |
nicklas |
34 |
{ |
6202 |
09 Apr 21 |
nicklas |
35 |
|
6202 |
09 Apr 21 |
nicklas |
36 |
public String flowCellId; |
6205 |
12 Apr 21 |
nicklas |
37 |
public PhysicalBioAssay flowCell; |
6202 |
09 Apr 21 |
nicklas |
38 |
public Integer size; |
6202 |
09 Apr 21 |
nicklas |
39 |
public String sequencingCycles; |
6202 |
09 Apr 21 |
nicklas |
40 |
public String operator; |
6202 |
09 Apr 21 |
nicklas |
41 |
|
6202 |
09 Apr 21 |
nicklas |
42 |
public boolean valid; |
6202 |
09 Apr 21 |
nicklas |
43 |
|
6960 |
13 Dec 22 |
nicklas |
44 |
public FlowCellInfo(JsonSection section, FastqInfo fastqInfo, PoolInfo poolInfo, LibraryInfo libInfo, MainInfo main) |
6202 |
09 Apr 21 |
nicklas |
45 |
{ |
6205 |
12 Apr 21 |
nicklas |
46 |
if (section != null) |
6202 |
09 Apr 21 |
nicklas |
47 |
{ |
6205 |
12 Apr 21 |
nicklas |
48 |
flowCellId = section.getRequiredEntry("FlowCellID", PatternValidator.FLOWCELL_ID); |
6955 |
12 Dec 22 |
nicklas |
49 |
if (flowCellId != null && fastqInfo != null && fastqInfo.flowCellId != null) |
6955 |
12 Dec 22 |
nicklas |
50 |
{ |
6955 |
12 Dec 22 |
nicklas |
51 |
if (!flowCellId.equals(fastqInfo.flowCellId)) |
6955 |
12 Dec 22 |
nicklas |
52 |
{ |
6955 |
12 Dec 22 |
nicklas |
53 |
section.addErrorMessage("FlowCell.FlowCellID mismatch: JSON="+flowCellId+"; FASTQ="+fastqInfo.flowCellId); |
6955 |
12 Dec 22 |
nicklas |
54 |
} |
6955 |
12 Dec 22 |
nicklas |
55 |
} |
6205 |
12 Apr 21 |
nicklas |
56 |
if (flowCellId != null) flowCell = findExistingFlowCell(flowCellId, section); |
6955 |
12 Dec 22 |
nicklas |
57 |
|
6739 |
10 May 22 |
nicklas |
58 |
if (flowCell != null && poolInfo != null && poolInfo.poolId != null) |
6205 |
12 Apr 21 |
nicklas |
59 |
{ |
6205 |
12 Apr 21 |
nicklas |
60 |
verifyPoolIsSequencedOnFlowCell(flowCell, poolInfo, section); |
6205 |
12 Apr 21 |
nicklas |
61 |
} |
6205 |
12 Apr 21 |
nicklas |
62 |
size = section.getRequiredEntry("Size", IntValidator.FLOWCELL_SIZE_2_OR_4); |
6209 |
13 Apr 21 |
nicklas |
63 |
sequencingCycles = section.getRequiredEntry("SequencingCycles", PatternValidator.SEQUENCING_CYCLES); |
6960 |
13 Dec 22 |
nicklas |
64 |
if (sequencingCycles != null && libInfo != null && libInfo.barcodeInfo != null) |
6960 |
13 Dec 22 |
nicklas |
65 |
{ |
6960 |
13 Dec 22 |
nicklas |
66 |
Integer[] cycles = Values.getInt(sequencingCycles.split("-")); |
6960 |
13 Dec 22 |
nicklas |
67 |
if (cycles.length == 4) |
6960 |
13 Dec 22 |
nicklas |
68 |
{ |
6960 |
13 Dec 22 |
nicklas |
// Check barcode sizes |
6960 |
13 Dec 22 |
nicklas |
70 |
if (libInfo.barcodeInfo.seq1 != null && cycles[1] != libInfo.barcodeInfo.seq1.length()) |
6960 |
13 Dec 22 |
nicklas |
71 |
{ |
6960 |
13 Dec 22 |
nicklas |
72 |
section.addErrorMessage("FlowCell.SequencingCycles ("+sequencingCycles+") doesn't match Library.Barcode length: " + libInfo.barcodeInfo.seq1.length() + " ("+libInfo.barcodeInfo.seq1+")"); |
6960 |
13 Dec 22 |
nicklas |
73 |
} |
6960 |
13 Dec 22 |
nicklas |
74 |
else if (libInfo.barcodeInfo.seq2 != null && cycles[2] != libInfo.barcodeInfo.seq2.length()) |
6960 |
13 Dec 22 |
nicklas |
75 |
{ |
6960 |
13 Dec 22 |
nicklas |
76 |
section.addErrorMessage("FlowCell.SequencingCycles ("+sequencingCycles+") doesn't match Library.Barcode length: " + libInfo.barcodeInfo.seq2.length() + " ("+libInfo.barcodeInfo.seq2+")"); |
6960 |
13 Dec 22 |
nicklas |
77 |
} |
6960 |
13 Dec 22 |
nicklas |
78 |
} |
6960 |
13 Dec 22 |
nicklas |
79 |
} |
6960 |
13 Dec 22 |
nicklas |
80 |
|
6212 |
14 Apr 21 |
nicklas |
81 |
operator = section.getOptionalEntry("Operator", null); |
6202 |
09 Apr 21 |
nicklas |
82 |
} |
6205 |
12 Apr 21 |
nicklas |
83 |
valid = section != null && !section.hasError(); |
6202 |
09 Apr 21 |
nicklas |
84 |
} |
6202 |
09 Apr 21 |
nicklas |
85 |
|
6205 |
12 Apr 21 |
nicklas |
86 |
private PhysicalBioAssay findExistingFlowCell(String flowCellId, JsonSection section) |
6205 |
12 Apr 21 |
nicklas |
87 |
{ |
6205 |
12 Apr 21 |
nicklas |
88 |
PhysicalBioAssay flowCell = null; |
6205 |
12 Apr 21 |
nicklas |
89 |
DbControl dc = section.getFile().dc(); |
6205 |
12 Apr 21 |
nicklas |
90 |
ItemQuery<PhysicalBioAssay> query = PhysicalBioAssay.getQuery(); |
6205 |
12 Apr 21 |
nicklas |
91 |
query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
6205 |
12 Apr 21 |
nicklas |
92 |
Subtype.FLOW_CELL.addFilter(dc, query); |
6205 |
12 Apr 21 |
nicklas |
93 |
query.join(Annotations.innerJoin(null, Annotationtype.FLOWCELL_ID.load(dc), "ref")); |
6205 |
12 Apr 21 |
nicklas |
94 |
query.restrict(Restrictions.eq(Hql.alias("ref"), Expressions.string(flowCellId))); |
6205 |
12 Apr 21 |
nicklas |
95 |
List<PhysicalBioAssay> list = query.list(dc); |
6205 |
12 Apr 21 |
nicklas |
96 |
if (list.size() > 1) |
6205 |
12 Apr 21 |
nicklas |
97 |
{ |
6205 |
12 Apr 21 |
nicklas |
98 |
section.addErrorMessage("Found "+list.size()+" flow cells with FlowCellID="+flowCellId); |
6205 |
12 Apr 21 |
nicklas |
99 |
} |
6205 |
12 Apr 21 |
nicklas |
100 |
else if (list.size() == 1) |
6205 |
12 Apr 21 |
nicklas |
101 |
{ |
6205 |
12 Apr 21 |
nicklas |
102 |
flowCell = list.get(0); |
6205 |
12 Apr 21 |
nicklas |
103 |
} |
6205 |
12 Apr 21 |
nicklas |
104 |
return flowCell; |
6205 |
12 Apr 21 |
nicklas |
105 |
} |
6205 |
12 Apr 21 |
nicklas |
106 |
|
6205 |
12 Apr 21 |
nicklas |
107 |
/** |
6205 |
12 Apr 21 |
nicklas |
Verify that an existing flow cell is linked to an existing pool. Note |
6205 |
12 Apr 21 |
nicklas |
that is it not possible to add a new pool to an existing flow cell. |
6205 |
12 Apr 21 |
nicklas |
110 |
*/ |
6205 |
12 Apr 21 |
nicklas |
111 |
private void verifyPoolIsSequencedOnFlowCell(PhysicalBioAssay flowCell, PoolInfo poolInfo, JsonSection section) |
6205 |
12 Apr 21 |
nicklas |
112 |
{ |
6205 |
12 Apr 21 |
nicklas |
113 |
if (poolInfo.pool != null) |
6205 |
12 Apr 21 |
nicklas |
114 |
{ |
6205 |
12 Apr 21 |
nicklas |
115 |
DbControl dc = section.getFile().dc(); |
6205 |
12 Apr 21 |
nicklas |
// Verify that the flow cell is linked to the pool |
6205 |
12 Apr 21 |
nicklas |
117 |
List<PooledLibrary> pools = PooledLibrary.getByFlowCell(dc, FlowCell.get(flowCell)); |
6205 |
12 Apr 21 |
nicklas |
118 |
boolean isLinked = false; |
6205 |
12 Apr 21 |
nicklas |
119 |
for (PooledLibrary p : pools) |
6205 |
12 Apr 21 |
nicklas |
120 |
{ |
6205 |
12 Apr 21 |
nicklas |
121 |
if (p.getId() == poolInfo.pool.getId()) isLinked = true; |
6205 |
12 Apr 21 |
nicklas |
122 |
} |
6205 |
12 Apr 21 |
nicklas |
123 |
if (!isLinked) |
6205 |
12 Apr 21 |
nicklas |
124 |
{ |
6205 |
12 Apr 21 |
nicklas |
125 |
section.addErrorMessage(poolInfo.pool.getName()+" is not sequenced on "+flowCell.getName()); |
6205 |
12 Apr 21 |
nicklas |
126 |
} |
6205 |
12 Apr 21 |
nicklas |
127 |
} |
6205 |
12 Apr 21 |
nicklas |
128 |
else |
6205 |
12 Apr 21 |
nicklas |
129 |
{ |
6205 |
12 Apr 21 |
nicklas |
// This is a new pool that can't be added to the existing flow cell |
6205 |
12 Apr 21 |
nicklas |
131 |
section.addErrorMessage("Pool[ExternalRef="+poolInfo.poolId+"] is not sequenced on "+flowCell.getName()); |
6205 |
12 Apr 21 |
nicklas |
132 |
} |
6205 |
12 Apr 21 |
nicklas |
133 |
} |
6205 |
12 Apr 21 |
nicklas |
134 |
|
6202 |
09 Apr 21 |
nicklas |
135 |
} |