Skip to content

Commit 31f25d5

Browse files
author
Nils Fo
committed
Updated Konstanz inserter and implemented Assay-Distribution Exporter
1 parent f7d084d commit 31f25d5

7 files changed

Lines changed: 207 additions & 55 deletions

File tree

src/main/java/de/rub/bph/omnineuro/client/core/db/in/KonstanzInserter.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ public void run() {
128128
String sampleID = reader.getValueAt("A" + i);
129129
String plateID = reader.getValueAt("B" + i);
130130

131+
for (int j = 0; j < 99; j++) {
132+
// Extrawurst for UKN 4.
133+
// Sometimes UKN4 plateID contains the plate number. That has to be removed.
134+
// Example of undesireable plate: UKN4_PreProject_Acet_plate 1_N1
135+
String plate = "_plate " + j;
136+
if (plateID.contains(plate)) {
137+
addError("Warning! '" + plateID + "' contained plate ID in the experiment. Deleting '" + plate + "'!");
138+
plateID = plateID.replace(plate, "");
139+
}
140+
}
141+
131142
boolean hasWell = true;
132143
String wellName;
133144
try {
@@ -157,6 +168,17 @@ public void run() {
157168
}
158169
boolean CASMode = CAS != null;
159170

171+
if (CASMode) {
172+
// Extrawurst for 'Paraquat dichloride hydrate'.
173+
// Konstanz used CAS: 1910-42-5
174+
// IUF CAS: 75365-73-0
175+
// TODO this is technical debt
176+
if (CAS.equals("1910-42-5") || sampleID.toLowerCase().trim().equals("paraquat dichloride hydrate")) {
177+
CAS = "75365-73-0";
178+
addError("Technical debt. Replaced PARAQ CAS to match DB.");
179+
}
180+
}
181+
160182
long outlierID = confirmedOutlierID;
161183
try {
162184
int wellQualityNumeric = (int) Double.parseDouble(wellQuality);
@@ -267,6 +289,7 @@ public void run() {
267289
}
268290

269291
//So our CAS was not in the DB and not in the unblinded mapping. Let's insert it as a new compound then.
292+
addError("This compound was not found in the DB! Name: '" + sampleID + "'. CAS: " + CAS);
270293
executor.insertCompound(sampleID, CAS, sampleID, true);
271294
foundCas = false;
272295
compoundID = executor.getIDViaName("compound", sampleID);
@@ -328,7 +351,11 @@ public void run() {
328351

329352
ArrayList<Long> experimentIDList = new ArrayList<>();
330353
if (isControl) {
331-
executor.deleteRow("experiment", experimentID);
354+
if (!experimentName.startsWith("Narciclasine#UKN4_PreProject_Narci_plate")) {
355+
// Hier eine Extrawurst, weil auf der selben plate als compound und auch als kontrolle verwendet wurde
356+
//TODO this should be discussed and deleted! Technical debt gedetected!!
357+
executor.deleteRow("experiment", experimentID);
358+
}
332359
ArrayList<String> experimentList = lookupMapDMSO.get(plateID);
333360
for (String s : experimentList) {
334361
long id = executor.getIDViaName("experiment", s + "#" + plateID);

src/main/java/de/rub/bph/omnineuro/client/core/db/out/ResponseSheetExporterCompatManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@ public void export() {
107107
if (includeBlinded) {
108108
try {
109109
exportEFSASheet();
110-
} catch (SQLException e) {
110+
} catch (Exception e) {
111111
Log.e(e);
112112
Client.showErrorMessage("Failed to export experiment data!\nA more detailed message will be displayed in the future.", null, e);
113+
return;
113114
}
114115
}
115116

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package de.rub.bph.omnineuro.client.core.db.out.assay_distribution;
2+
3+
import de.rub.bph.omnineuro.client.core.db.DBConnection;
4+
import de.rub.bph.omnineuro.client.core.db.OmniNeuroQueryExecutor;
5+
import de.rub.bph.omnineuro.client.core.db.out.SheetExporterCompatManager;
6+
import de.rub.bph.omnineuro.client.imported.filemanager.FileManager;
7+
import de.rub.bph.omnineuro.client.imported.log.Log;
8+
9+
import java.io.File;
10+
import java.sql.ResultSet;
11+
import java.sql.SQLException;
12+
import java.util.ArrayList;
13+
import java.util.concurrent.ExecutorService;
14+
15+
public class AssayDistributionSheetExporter extends SheetExporterCompatManager {
16+
17+
private ArrayList<String> errorList;
18+
private OmniNeuroQueryExecutor queryExecutor;
19+
private File outFile;
20+
private ExecutorService service;
21+
private ArrayList<Long> compoundIDs;
22+
private ArrayList<String> assayNames;
23+
24+
public AssayDistributionSheetExporter(int threads, File sourceDir) throws SQLException {
25+
super(threads, sourceDir);
26+
27+
errorList = new ArrayList<>();
28+
DBConnection connection = DBConnection.getDBConnection();
29+
queryExecutor = new OmniNeuroQueryExecutor(connection.getConnection());
30+
queryExecutor.setLogEnabled(false);
31+
32+
String compoundQuery = "SELECT id from compound ORDER BY name";
33+
compoundIDs = queryExecutor.extractLongFeature(queryExecutor.executeQuery(compoundQuery), "id");
34+
assayNames = queryExecutor.getColumn("assay", "name", true);
35+
36+
outFile = new File(sourceDir, "assay_distribution.csv");
37+
}
38+
39+
private String getRowText(long compoundID, int index) throws SQLException {
40+
StringBuilder row = new StringBuilder();
41+
row.append(index + 1 + ";");
42+
43+
String cas = queryExecutor.getFeatureViaID("compound", "cas_no", compoundID);
44+
String compoundName = queryExecutor.getNameViaID("compound", compoundID);
45+
46+
row.append(compoundName + ";");
47+
row.append(cas + ";");
48+
49+
int sum = 0;
50+
for (String assay : assayNames) {
51+
String query = "SELECT count(experiment.id)\n" +
52+
"FROM compound,\n" +
53+
" experiment,\n" +
54+
" assay\n" +
55+
"WHERE compound.id = " + compoundID + "\n" +
56+
" AND experiment.compound_id = compound.id\n" +
57+
" AND experiment.assay_id = assay.id\n" +
58+
" AND assay.name = '" + assay + "';";
59+
ResultSet set = queryExecutor.executeQuery(query);
60+
set.next();
61+
int count = set.getInt("count");
62+
sum += count;
63+
row.append(count + ";");
64+
}
65+
row.append(sum);
66+
67+
return row.toString();
68+
}
69+
70+
@Override
71+
public void export() {
72+
try {
73+
StringBuilder headerLine = new StringBuilder();
74+
headerLine.append("Index;Compound;CAS;");
75+
for (String assay : assayNames) {
76+
headerLine.append("n (" + assay + ");");
77+
}
78+
headerLine.append("Sum");
79+
80+
ArrayList<String> outLines = new ArrayList<>();
81+
outLines.add(headerLine.toString());
82+
83+
for (int i = 0; i < compoundIDs.size(); i++) {
84+
long currentID = compoundIDs.get(i);
85+
String row = getRowText(currentID, i);
86+
outLines.add(row);
87+
Log.i("Assay Distribution sheet Progress: " + i + "/" + compoundIDs.size());
88+
}
89+
90+
FileManager manager = new FileManager();
91+
manager.saveListFile(outLines, outFile);
92+
} catch (Exception e) {
93+
Log.e(e);
94+
errorList.add("Fatal error!! " + e.getMessage());
95+
}
96+
}
97+
98+
@Override
99+
public ArrayList<String> getErrors() {
100+
return new ArrayList<>(errorList);
101+
}
102+
103+
@Override
104+
public int getTaskCount() {
105+
return compoundIDs.size();
106+
}
107+
}

src/main/java/de/rub/bph/omnineuro/client/core/db/out/compact_experiment/CompactExperimentSheetExporter.java

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -111,61 +111,36 @@ public void export() {
111111
Collections.sort(timestamps);
112112
Log.i("Experiments found in the DB: " + Arrays.toString(experimentNames.toArray()));
113113

114-
/*
115-
endpointNames.remove("Viability UKN2");
116-
endpointNames.remove("Migration UKN2");
117-
endpointNames.remove("Neurite Area UKN5");
118-
endpointNames.remove("Valid Objects UKN4");
119-
endpointNames.remove("Selected Objects UKN5");
120-
endpointNames.remove("Selected Objects UKN4");
121-
endpointNames.remove("Valid Objects UKN5");
122-
endpointNames.remove("Neurite Area UKN4");
123-
endpointNames.remove("Neuronal Density Ring 1");
124-
endpointNames.remove("Neuronal Density Ring 2");
125-
endpointNames.remove("Neuronal Density Ring 3");
126-
endpointNames.remove("Neuronal Density Ring 4");
127-
endpointNames.remove("Neuronal Density Ring 5");
128-
endpointNames.remove("Neuronal Density Ring 6");
129-
endpointNames.remove("Neuronal Density Ring 7");
130-
endpointNames.remove("Neuronal Density Ring 8");
131-
endpointNames.remove("Neuronal Density Ring 9");
132-
endpointNames.remove("Neuronal Density Ring 10");
133-
endpointNames.remove("Mean Subneurite Count limited");
134-
endpointNames.remove("Skeleton Oligos");
135-
endpointNames.remove("Mean Migration Distance all neurons");
136-
endpointNames.remove("Average Subneuritelength per Nucleus limited");
137-
*/
138-
139114
endpointNames = new ArrayList<>();
140115

141116
//IUF Endpoints
142-
//endpointNames.add("Proliferation (BrdU)");
143-
//endpointNames.add("Proliferation Area");
144-
//endpointNames.add("Viabillity");
145-
//endpointNames.add("Viabillity of Proliferation");
146-
//endpointNames.add("Mean Migration Distance all Oligodendrocytes");
147-
//endpointNames.add("Skeleton Neurons");
148-
//endpointNames.add("Migration");
149-
//endpointNames.add("Number Nuclei");
150-
//endpointNames.add("Migration Distance");
151-
//endpointNames.add("Skeleton Oligos");
152-
//endpointNames.add("Mean Migration Distance all neurons");
153-
//endpointNames.add("Cytotoxicity (NPC1ab)");
154-
//endpointNames.add("Cytotoxicity (NPC2-5)");
117+
endpointNames.add("Proliferation (BrdU)");
118+
endpointNames.add("Proliferation Area");
119+
endpointNames.add("Viabillity");
120+
endpointNames.add("Viabillity of Proliferation");
121+
endpointNames.add("Mean Migration Distance all Oligodendrocytes");
122+
endpointNames.add("Skeleton Neurons");
123+
endpointNames.add("Migration");
124+
endpointNames.add("Number Nuclei");
125+
endpointNames.add("Migration Distance");
126+
endpointNames.add("Skeleton Oligos");
127+
endpointNames.add("Mean Migration Distance all neurons");
128+
endpointNames.add("Cytotoxicity (NPC1ab)");
129+
endpointNames.add("Cytotoxicity (NPC2-5)");
155130

156131
//Konstanz Endpoints
157-
endpointNames.add("Viability UKN2");
158-
endpointNames.add("Migration UKN2");
159-
endpointNames.add("Neurite Area UKN5");
160-
endpointNames.add("Valid Objects UKN4");
161-
endpointNames.add("Selected Objects UKN5");
162-
endpointNames.add("Selected Objects UKN4");
163-
endpointNames.add("Neurite Area");
164-
endpointNames.add("Selected Objects");
165-
endpointNames.add("Valid Objects");
166-
endpointNames.add("Valid Objects UKN5");
167-
endpointNames.add("Neurite Area UKN4");
168-
endpointNames.add("Viabilty UKN2");
132+
// endpointNames.add("Viability UKN2");
133+
// endpointNames.add("Migration UKN2");
134+
// endpointNames.add("Neurite Area UKN5");
135+
// endpointNames.add("Valid Objects UKN4");
136+
// endpointNames.add("Selected Objects UKN5");
137+
// endpointNames.add("Selected Objects UKN4");
138+
// endpointNames.add("Neurite Area");
139+
// endpointNames.add("Selected Objects");
140+
// endpointNames.add("Valid Objects");
141+
// endpointNames.add("Valid Objects UKN5");
142+
// endpointNames.add("Neurite Area UKN4");
143+
// endpointNames.add("Viabilty UKN2");
169144

170145
StringBuilder headerBuilder = new StringBuilder();
171146
headerBuilder.append("ExperimentID;Plating date (ddMONjj);Assay;Species;Cell type;Individual;Date (ddMONjj)/passage 0;P;Date (ddMONjj)/passage 1;P;control Plate ID;" +

src/main/java/de/rub/bph/omnineuro/client/core/db/out/efsa/BlindedCompoundsExporter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ private String getRow(String name, String well) throws SQLException {
5858
" response.concentration_id = concentration.id\n" +
5959
" AND (endpoint.id = 17 OR endpoint.id = 20 OR endpoint.id = 23 OR endpoint.id = 49 OR endpoint.id = 19 OR\n" +
6060
" endpoint.id = 16 OR endpoint.id = 15 OR endpoint.id = 54 OR endpoint.id = 22 OR endpoint.id = 51 OR\n" +
61-
" endpoint.id = 4 OR endpoint.id = 1 OR endpoint.id = 2) AND (response.timestamp = 72 OR response.timestamp = 120) AND experiment.name = '" + name + "' AND well.name = '" + well + "' ORDER BY endpoint_id;";
61+
" endpoint.id = 4 OR endpoint.id = 1 OR endpoint.id = 2 OR endpoint.id = 8) " +
62+
" AND (response.timestamp = 72 OR response.timestamp = 120) AND experiment.name = '" + name + "' AND well.name = '" + well + "' ORDER BY endpoint_id;";
6263
ResultSet set = queryExecutor.executeQuery(query);
6364

6465
if (!set.next()) {
@@ -121,7 +122,7 @@ private String getRow(String name, String well) throws SQLException {
121122
migrationDistance120 = responseValue + ";";
122123
} else if (endpointID == 23) {
123124
meanMigrationDistanceAllNeurons120 = responseValue + ";";
124-
} else if (endpointID == 49) {
125+
} else if (endpointID == 8) {
125126
meanMigrationDistanceAllOligodendrocytes120 = responseValue + ";";
126127
} else if (endpointID == 19) {
127128
numberNuclei120 = responseValue + ";";

src/main/java/de/rub/bph/omnineuro/client/ui/OmniFrame.form

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>
6-
<xy x="20" y="20" width="571" height="1037"/>
6+
<xy x="20" y="20" width="571" height="1066"/>
77
</constraints>
88
<properties/>
99
<border type="none"/>
@@ -291,6 +291,34 @@
291291
</vspacer>
292292
</children>
293293
</grid>
294+
<grid id="2ce9c" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
295+
<margin top="0" left="0" bottom="0" right="0"/>
296+
<constraints>
297+
<tabbedpane title="Assay Distribution"/>
298+
</constraints>
299+
<properties/>
300+
<border type="none"/>
301+
<children>
302+
<component id="c7b6f" class="javax.swing.JLabel">
303+
<constraints>
304+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
305+
</constraints>
306+
<properties>
307+
<text value="Lists ever compound and counts its appeance in every registered Assay."/>
308+
</properties>
309+
</component>
310+
<hspacer id="279a">
311+
<constraints>
312+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
313+
</constraints>
314+
</hspacer>
315+
<vspacer id="f68ff">
316+
<constraints>
317+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
318+
</constraints>
319+
</vspacer>
320+
</children>
321+
</grid>
294322
</children>
295323
</tabbedpane>
296324
</children>

src/main/java/de/rub/bph/omnineuro/client/ui/OmniFrame.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import de.rub.bph.omnineuro.client.core.db.out.ResponseIDLimiter;
99
import de.rub.bph.omnineuro.client.core.db.out.ResponseSheetExporterCompatManager;
1010
import de.rub.bph.omnineuro.client.core.db.out.SheetExporterCompatManager;
11+
import de.rub.bph.omnineuro.client.core.db.out.assay_distribution.AssayDistributionSheetExporter;
1112
import de.rub.bph.omnineuro.client.core.db.out.compact_experiment.CompactExperimentSheetExporter;
1213
import de.rub.bph.omnineuro.client.core.db.out.holder.ResponseHolder;
1314
import de.rub.bph.omnineuro.client.core.db.out.r.CompoundExperimentSheetExporter;
@@ -305,6 +306,9 @@ public void requestExport() {
305306
case 2:
306307
useLimiterConfig = false;
307308
break;
309+
case 3:
310+
useLimiterConfig = false;
311+
break;
308312
default:
309313
throw new IllegalStateException("Invalid method selection index: " + exportMethod);
310314
}
@@ -354,6 +358,15 @@ public void requestExport() {
354358
Client.showErrorMessage("Failed to initiate the export.", this, e);
355359
}
356360
break;
361+
case 3:
362+
try {
363+
compatManager = new AssayDistributionSheetExporter(threads, dir);
364+
} catch (SQLException e) {
365+
e.printStackTrace();
366+
Log.e(e);
367+
Client.showErrorMessage("Failed to initiate the export.", this, e);
368+
}
369+
break;
357370
default:
358371
throw new IllegalStateException("Invalid method selection index: " + exportMethod);
359372
}

0 commit comments

Comments
 (0)