//private static Map<String, Pool<Plate<LinkedList<Library>, Library>>> process384PlateInputODS(OdfSpreadsheetDocument oDoc, User u, RequestManager manager, MisoNamingScheme<Library> libraryNamingScheme) throws Exception {
private static Map<String, PlatePool> process384PlateInputODS(OdfSpreadsheetDocument oDoc, User u, RequestManager manager, MisoNamingScheme<Library> libraryNamingScheme) throws Exception {
((RequestManagerAwareNamingScheme) libraryNamingScheme).setRequestManager(manager);
List<Sample> samples = new ArrayList<Sample>();
OdfTable oTable = oDoc.getTableList().get(0);
//process global headers
OdfTableCell pairedCell = oTable.getCellByPosition("A2");
boolean paired = false;
if (pairedCell.getBooleanValue() != null) {
paired = pairedCell.getBooleanValue();
log.info("Got paired: " + paired);
}
OdfTableCell platformCell = oTable.getCellByPosition("B2");
PlatformType pt = null;
if (!"".equals(platformCell.getStringValue())) {
pt = PlatformType.get(platformCell.getStringValue());
}
if (pt == null) {
throw new InputFormException("Cannot resolve Platform type from: '" + platformCell.getStringValue() + "'");
}
else {
log.info("Got platform type: " + pt.getKey());
}
OdfTableCell typeCell = oTable.getCellByPosition("C2");
LibraryType lt = null;
if (!"".equals(typeCell.getStringValue())) {
String[] split = typeCell.getStringValue().split("-");
String plat = split[0];
String type = split[1];
if (platformCell.getStringValue().equals(plat)) {
lt = manager.getLibraryTypeByDescriptionAndPlatform(type, pt);
}
else {
throw new InputFormException("Selected library type '" + typeCell.getStringValue() + "' doesn't match platform type: '" + platformCell.getStringValue() + "'");
}
}
if (lt == null) {
throw new InputFormException("Cannot resolve Library type from: '" + typeCell.getStringValue() + "'");
}
else {
log.info("Got library type: " + lt.getDescription());
}
OdfTableCell selectionCell = oTable.getCellByPosition("D2");
LibrarySelectionType ls = null;
if (!"".equals(selectionCell.getStringValue())) {
ls = manager.getLibrarySelectionTypeByName(selectionCell.getStringValue());
}
if (ls == null) {
throw new InputFormException("Cannot resolve Library Selection type from: '" + selectionCell.getStringValue() + "'");
}
else {
log.info("Got library selection type: " + ls.getName());
}
OdfTableCell strategyCell = oTable.getCellByPosition("E2");
LibraryStrategyType lst = null;
if (!"".equals(strategyCell.getStringValue())) {
lst = manager.getLibraryStrategyTypeByName(strategyCell.getStringValue());
}
if (lst == null) {
throw new InputFormException("Cannot resolve Library Strategy type from: '" + strategyCell.getStringValue() + "'");
}
else {
log.info("Got library strategy type: " + lst.getName());
}
OdfTableCell plateBarcodeCell = oTable.getCellByPosition("F2");
String plateBarcode = null;
if (!"".equals(plateBarcodeCell.getStringValue())) {
plateBarcode = plateBarcodeCell.getStringValue();
}
if (plateBarcode == null) {
throw new InputFormException("Cannot resolve plate barcode from: '" + plateBarcodeCell.getStringValue() + "'");
}
else {
log.info("Got plate parcode: " + plateBarcode);
}
//process entries
Simple384WellPlate libraryPlate = null;
//Map<String, Pool<Plate<LinkedList<Library>, Library>>> pools = new HashMap<String, Pool<Plate<LinkedList<Library>, Library>>>();
Map<String, PlatePool> pools = new HashMap<String, PlatePool>();
for (OdfTableRow row : oTable.getRowList()) {
int ri = row.getRowIndex();
if (ri > 3) {
// Ax - plate position
OdfTableCell platePosCell = oTable.getCellByPosition(0, ri);
if (!"".equals(platePosCell.getStringValue()) && libraryPlate == null) {
//plated libraries - process as plate
libraryPlate = new Simple384WellPlate();
libraryPlate.setIdentificationBarcode(plateBarcode);
libraryPlate.setCreationDate(new Date());
}
//cell defs
OdfTableCell sampleAliasCell = oTable.getCellByPosition(1, ri);
Sample s = null;
if (!"".equals(sampleAliasCell.getStringValue())) {
Collection<Sample> ss = manager.listSamplesByAlias(sampleAliasCell.getStringValue());
if (!ss.isEmpty()) {
if (ss.size() == 1) {
s = ss.iterator().next();
log.info("Got sample: " + s.getAlias());
}
else {
throw new InputFormException("Multiple samples retrieved with this alias: '" + sampleAliasCell.getStringValue() + "'. Cannot process.");
}
}
else {
throw new InputFormException("No such sample '" + sampleAliasCell.getStringValue() + "'in database. Samples need to be created before using the form input functionality");
}
}
else {
log.info("Blank sample row found. Ending import.");
break;
}
//sample OK - good to go
if (s != null) {
OdfTableCell entityIDCell = oTable.getCellByPosition(2, ri);
OdfTableCell poolNumberCell = oTable.getCellByPosition(3, ri);
OdfTableCell sampleQcCell = oTable.getCellByPosition(4, ri);
//OdfTableCell sampleAmountCell = oTable.getCellByPosition(5, ri);
//OdfTableCell sampleWaterAmountCell = oTable.getCellByPosition(6, ri);
OdfTableCell barcodeKitCell = oTable.getCellByPosition(7, ri);
OdfTableCell barcodeTagsCell = oTable.getCellByPosition(8, ri);
OdfTableCell libraryQcCell = oTable.getCellByPosition(9, ri);
OdfTableCell libraryQcInsertSizeCell = oTable.getCellByPosition(10, ri);
OdfTableCell libraryQcMolarityCell = oTable.getCellByPosition(11, ri);
OdfTableCell libraryQcPassFailCell = oTable.getCellByPosition(12, ri);
//OdfTableCell libraryAmountCell = oTable.getCellByPosition(13, ri);
//OdfTableCell libraryWaterAmountCell = oTable.getCellByPosition(14, ri);
//OdfTableCell dilutionQcCell = oTable.getCellByPosition(15, ri);
OdfTableCell dilutionMolarityCell = oTable.getCellByPosition(16, ri);
//OdfTableCell dilutionAmountCell = oTable.getCellByPosition(17, ri);
//OdfTableCell dilutionWaterAmountCell = oTable.getCellByPosition(18, ri);
OdfTableCell poolQcCell = oTable.getCellByPosition(19, ri);
//OdfTableCell poolAverageInsertSizeCell = oTable.getCellByPosition(20, ri);
OdfTableCell poolConvertedMolarityCell = oTable.getCellByPosition(21, ri);
//add pool, if any
if (!"".equals(poolNumberCell.getStringValue())) {
if (!pools.containsKey(poolNumberCell.getStringValue())) {
PlatePool pool = new PlatePool();