6734 |
09 May 22 |
nicklas |
1 |
package net.sf.basedb.reggie.plugins.cmd; |
6734 |
09 May 22 |
nicklas |
2 |
|
6734 |
09 May 22 |
nicklas |
3 |
import org.json.simple.JSONObject; |
6734 |
09 May 22 |
nicklas |
4 |
|
6734 |
09 May 22 |
nicklas |
5 |
import net.sf.basedb.reggie.dao.DemuxedSequences; |
6734 |
09 May 22 |
nicklas |
6 |
import net.sf.basedb.reggie.dao.Library; |
6734 |
09 May 22 |
nicklas |
7 |
import net.sf.basedb.reggie.dao.Lysate; |
6734 |
09 May 22 |
nicklas |
8 |
import net.sf.basedb.reggie.dao.PooledLibrary; |
6734 |
09 May 22 |
nicklas |
9 |
import net.sf.basedb.reggie.dao.ReggieItem; |
6734 |
09 May 22 |
nicklas |
10 |
import net.sf.basedb.reggie.dao.Rna; |
6734 |
09 May 22 |
nicklas |
11 |
import net.sf.basedb.reggie.dao.SequencingRun; |
6734 |
09 May 22 |
nicklas |
12 |
import net.sf.basedb.reggie.dao.SpecimenTube; |
6734 |
09 May 22 |
nicklas |
13 |
import net.sf.basedb.reggie.plugins.ExternalSpecimenImporter.ImportedItems; |
6734 |
09 May 22 |
nicklas |
14 |
|
6734 |
09 May 22 |
nicklas |
15 |
/** |
6734 |
09 May 22 |
nicklas |
Represents the end-point of items to create |
6734 |
09 May 22 |
nicklas |
when importing from a JSON file. The normal |
6734 |
09 May 22 |
nicklas |
procedure is to import all the way to FASTQ |
6734 |
09 May 22 |
nicklas |
files, but this may not always be possible due |
6734 |
09 May 22 |
nicklas |
to lab procedures failing or a descision to not |
6734 |
09 May 22 |
nicklas |
continue with processing. If this happens we |
6734 |
09 May 22 |
nicklas |
expect that the JSON file contain sections with |
6734 |
09 May 22 |
nicklas |
data for only those steps that has been |
6734 |
09 May 22 |
nicklas |
performed. For example, if a library was created |
6734 |
09 May 22 |
nicklas |
but it was not pooled or sequenced, the "Libary" |
6734 |
09 May 22 |
nicklas |
section should be present but not the other sections |
6734 |
09 May 22 |
nicklas |
downstreams ("Pool", "FlowCell", etc.) |
6734 |
09 May 22 |
nicklas |
28 |
|
6734 |
09 May 22 |
nicklas |
The order of the defined end-points is important |
6734 |
09 May 22 |
nicklas |
since it is implied that all sections before a given |
6734 |
09 May 22 |
nicklas |
end-point are expected to be present in the JSON file. |
6734 |
09 May 22 |
nicklas |
32 |
|
6734 |
09 May 22 |
nicklas |
@author nicklas |
6734 |
09 May 22 |
nicklas |
@since 4.39 |
6734 |
09 May 22 |
nicklas |
35 |
*/ |
6734 |
09 May 22 |
nicklas |
36 |
public enum EndPoint |
6734 |
09 May 22 |
nicklas |
37 |
{ |
6734 |
09 May 22 |
nicklas |
38 |
|
6734 |
09 May 22 |
nicklas |
39 |
SPECIMEN("Specimen", "Specimen") |
6734 |
09 May 22 |
nicklas |
40 |
{ |
6734 |
09 May 22 |
nicklas |
41 |
@Override |
6734 |
09 May 22 |
nicklas |
42 |
public SpecimenTube getEndPointItem(ImportedItems items) |
6734 |
09 May 22 |
nicklas |
43 |
{ |
6734 |
09 May 22 |
nicklas |
44 |
return items.specimen; |
6734 |
09 May 22 |
nicklas |
45 |
} |
6734 |
09 May 22 |
nicklas |
46 |
}, |
6734 |
09 May 22 |
nicklas |
47 |
LYSATE("Lysate", "Lysate") |
6734 |
09 May 22 |
nicklas |
48 |
{ |
6734 |
09 May 22 |
nicklas |
49 |
@Override |
6734 |
09 May 22 |
nicklas |
50 |
public Lysate getEndPointItem(ImportedItems items) |
6734 |
09 May 22 |
nicklas |
51 |
{ |
6734 |
09 May 22 |
nicklas |
52 |
return items.lysate; |
6734 |
09 May 22 |
nicklas |
53 |
} |
6734 |
09 May 22 |
nicklas |
54 |
}, |
6738 |
10 May 22 |
nicklas |
55 |
RNA("RNA/DNA/FlowThrough", "RNA", "DNA", "FlowThrough") |
6734 |
09 May 22 |
nicklas |
56 |
{ |
6734 |
09 May 22 |
nicklas |
57 |
@Override |
6734 |
09 May 22 |
nicklas |
58 |
public Rna getEndPointItem(ImportedItems items) |
6734 |
09 May 22 |
nicklas |
59 |
{ |
6734 |
09 May 22 |
nicklas |
60 |
return items.rna; |
6734 |
09 May 22 |
nicklas |
61 |
} |
6734 |
09 May 22 |
nicklas |
62 |
}, |
6734 |
09 May 22 |
nicklas |
63 |
LIBRARY("Library", "Library") |
6734 |
09 May 22 |
nicklas |
64 |
{ |
6734 |
09 May 22 |
nicklas |
65 |
@Override |
6734 |
09 May 22 |
nicklas |
66 |
public Library getEndPointItem(ImportedItems items) |
6734 |
09 May 22 |
nicklas |
67 |
{ |
6734 |
09 May 22 |
nicklas |
68 |
return items.lib; |
6734 |
09 May 22 |
nicklas |
69 |
} |
6734 |
09 May 22 |
nicklas |
70 |
}, |
6734 |
09 May 22 |
nicklas |
71 |
POOL("Pool", "Pool") |
6734 |
09 May 22 |
nicklas |
72 |
{ |
6734 |
09 May 22 |
nicklas |
73 |
@Override |
6734 |
09 May 22 |
nicklas |
74 |
public PooledLibrary getEndPointItem(ImportedItems items) |
6734 |
09 May 22 |
nicklas |
75 |
{ |
6734 |
09 May 22 |
nicklas |
76 |
return items.pool; |
6734 |
09 May 22 |
nicklas |
77 |
} |
6734 |
09 May 22 |
nicklas |
78 |
}, |
6734 |
09 May 22 |
nicklas |
79 |
SEQUENCING("SequencingRun", "FlowCell", "SequencingRun") |
6734 |
09 May 22 |
nicklas |
80 |
{ |
6734 |
09 May 22 |
nicklas |
81 |
@Override |
6734 |
09 May 22 |
nicklas |
82 |
public SequencingRun getEndPointItem(ImportedItems items) |
6734 |
09 May 22 |
nicklas |
83 |
{ |
6734 |
09 May 22 |
nicklas |
84 |
return items.sequencingRun; |
6734 |
09 May 22 |
nicklas |
85 |
} |
6734 |
09 May 22 |
nicklas |
86 |
}, |
6734 |
09 May 22 |
nicklas |
87 |
DEMUX("DemuxedSequences", "fastq", "DemuxedSequences", "MergedSequences") |
6734 |
09 May 22 |
nicklas |
88 |
{ |
6734 |
09 May 22 |
nicklas |
89 |
@Override |
6734 |
09 May 22 |
nicklas |
90 |
public DemuxedSequences getEndPointItem(ImportedItems items) |
6734 |
09 May 22 |
nicklas |
91 |
{ |
6734 |
09 May 22 |
nicklas |
92 |
return items.demux; |
6734 |
09 May 22 |
nicklas |
93 |
} |
6734 |
09 May 22 |
nicklas |
94 |
}; |
6734 |
09 May 22 |
nicklas |
95 |
|
6734 |
09 May 22 |
nicklas |
96 |
|
6734 |
09 May 22 |
nicklas |
97 |
/** |
6734 |
09 May 22 |
nicklas |
Try to determine the end-point by checking which |
6734 |
09 May 22 |
nicklas |
sections are present in the JSON file. We check |
6734 |
09 May 22 |
nicklas |
end-points from the last to the first and as soon |
6734 |
09 May 22 |
nicklas |
as a section is found we stop. If no section at |
6734 |
09 May 22 |
nicklas |
all is found something is probably very wrong and |
6734 |
09 May 22 |
nicklas |
the DEMUX end-point is returned. |
6734 |
09 May 22 |
nicklas |
104 |
*/ |
6734 |
09 May 22 |
nicklas |
105 |
public static EndPoint determineEndPoint(JSONObject json) |
6734 |
09 May 22 |
nicklas |
106 |
{ |
6734 |
09 May 22 |
nicklas |
107 |
for (int i = EndPoint.values().length-1; i >= 0; i--) |
6734 |
09 May 22 |
nicklas |
108 |
{ |
6734 |
09 May 22 |
nicklas |
109 |
EndPoint ep = EndPoint.values()[i]; |
6734 |
09 May 22 |
nicklas |
110 |
for (String sect : ep.sections) |
6734 |
09 May 22 |
nicklas |
111 |
{ |
6734 |
09 May 22 |
nicklas |
112 |
if (json.containsKey(sect)) |
6734 |
09 May 22 |
nicklas |
113 |
{ |
6734 |
09 May 22 |
nicklas |
114 |
return ep; |
6734 |
09 May 22 |
nicklas |
115 |
} |
6734 |
09 May 22 |
nicklas |
116 |
} |
6734 |
09 May 22 |
nicklas |
117 |
} |
6734 |
09 May 22 |
nicklas |
118 |
return EndPoint.DEMUX; |
6734 |
09 May 22 |
nicklas |
119 |
} |
6734 |
09 May 22 |
nicklas |
120 |
|
6734 |
09 May 22 |
nicklas |
121 |
private final String name; |
6734 |
09 May 22 |
nicklas |
122 |
private final String[] sections; |
6734 |
09 May 22 |
nicklas |
123 |
|
6734 |
09 May 22 |
nicklas |
124 |
private EndPoint(String name, String... sections) |
6734 |
09 May 22 |
nicklas |
125 |
{ |
6734 |
09 May 22 |
nicklas |
126 |
this.name = name; |
6734 |
09 May 22 |
nicklas |
127 |
this.sections = sections; |
6734 |
09 May 22 |
nicklas |
128 |
} |
6734 |
09 May 22 |
nicklas |
129 |
|
6736 |
10 May 22 |
nicklas |
130 |
public JSONObject asJSONObject() |
6736 |
10 May 22 |
nicklas |
131 |
{ |
6736 |
10 May 22 |
nicklas |
132 |
JSONObject json = new JSONObject(); |
6736 |
10 May 22 |
nicklas |
133 |
json.put("name", name); |
6736 |
10 May 22 |
nicklas |
134 |
json.put("id", name()); |
6736 |
10 May 22 |
nicklas |
135 |
json.put("ordinal", ordinal()); |
6736 |
10 May 22 |
nicklas |
136 |
return json; |
6736 |
10 May 22 |
nicklas |
137 |
} |
6736 |
10 May 22 |
nicklas |
138 |
|
6734 |
09 May 22 |
nicklas |
139 |
/** |
6734 |
09 May 22 |
nicklas |
The name of the end-point. |
6734 |
09 May 22 |
nicklas |
141 |
*/ |
6734 |
09 May 22 |
nicklas |
142 |
public String getName() |
6734 |
09 May 22 |
nicklas |
143 |
{ |
6734 |
09 May 22 |
nicklas |
144 |
return name; |
6734 |
09 May 22 |
nicklas |
145 |
} |
6734 |
09 May 22 |
nicklas |
146 |
|
6734 |
09 May 22 |
nicklas |
147 |
/** |
6734 |
09 May 22 |
nicklas |
Check if the given section is required to be present |
6734 |
09 May 22 |
nicklas |
in the JSON file. We check the sections for all end-points |
6734 |
09 May 22 |
nicklas |
before the current end-point. |
6734 |
09 May 22 |
nicklas |
151 |
*/ |
6734 |
09 May 22 |
nicklas |
152 |
public boolean needSection(String section) |
6734 |
09 May 22 |
nicklas |
153 |
{ |
6734 |
09 May 22 |
nicklas |
154 |
for (int i = 0; i <= this.ordinal(); i++) |
6734 |
09 May 22 |
nicklas |
155 |
{ |
6734 |
09 May 22 |
nicklas |
156 |
for (String sect : EndPoint.values()[i].sections) |
6734 |
09 May 22 |
nicklas |
157 |
{ |
6734 |
09 May 22 |
nicklas |
158 |
if (sect.equals(section)) return true; |
6734 |
09 May 22 |
nicklas |
159 |
} |
6734 |
09 May 22 |
nicklas |
160 |
} |
6734 |
09 May 22 |
nicklas |
161 |
return false; |
6734 |
09 May 22 |
nicklas |
162 |
} |
6734 |
09 May 22 |
nicklas |
163 |
|
6734 |
09 May 22 |
nicklas |
164 |
public abstract ReggieItem<?> getEndPointItem(ImportedItems items); |
6734 |
09 May 22 |
nicklas |
165 |
|
6734 |
09 May 22 |
nicklas |
166 |
} |