theAnalysis.setStudy(theStudy);
theAnalysis.setName(an.getString("analysis_name"));
// TODO: TB_ANALYSISID
AnalysisStep theAnalysisStep = new AnalysisStep();
theAnalysisStep.setAnalysis(theAnalysis);
theAnalysis.addAnalysisStep(theAnalysisStep);
ContextManager.getAnalysisService().save(theAnalysis);
ContextManager.getAnalysisStepService().save(theAnalysisStep);
Algorithm theAlgorithm;
String tb1Algorithm = an.getString("algorithm");
if (tb1Algorithm.equalsIgnoreCase("parsimony")) {
theAlgorithm = new ParsimonyAlgorithm();
} else if (tb1Algorithm.equalsIgnoreCase("bayesian")) {
theAlgorithm = new BayesianAlgorithm();
} else if (tb1Algorithm.equalsIgnoreCase("evolution")) {
theAlgorithm = new EvolutionAlgorithm();
} else if (tb1Algorithm.equalsIgnoreCase("joining")) {
theAlgorithm = new JoiningAlgorithm();
} else if (tb1Algorithm.equalsIgnoreCase("UPGMA")) {
theAlgorithm = new UPGMAAlgorithm();
} else if (tb1Algorithm.equalsIgnoreCase("likelihood")) {
theAlgorithm = new LikelihoodAlgorithm();
} else {
theAlgorithm = new OtherAlgorithm();
}
theAlgorithm.setDescription(tb1Algorithm);
ContextManager.getAlgorithmHome().save(theAlgorithm);
theAnalysisStep.setAlgorithmInfo(theAlgorithm);
{ // handle INPUT_MATRIX and OUTPUT_TREE in each ANALYSIS section
TreeBlock theTreeBlock = null;
for (ValueSection ioSection : an.getIOSections()) {
AnalyzedData theData;
if (ioSection.label.equals("INPUT_MATRIX")) {
AnalyzedMatrix theMatrix = new AnalyzedMatrix();
theMatrix.setInput(true);
String matrixID = ioSection.getsval("matrix_id");
Matrix matrixData = matrices.get(matrixID);
if (matrixData == null) {
warn("Matrix " + matrixID + "is used in analysis " + an.getString("analysis_id") + " but is not listed in any MATRIX section for its study");
return new ValueNone();
}
matrixData.setStudy(theStudy);
ContextManager.getTaxonLabelService().updateStudyForAllLabels(matrixData, theStudy);
matrixData.setTB1MatrixID(matrixID);
ContextManager.getMatrixService().save(matrixData);
theSubmission.addMatrixIfNecessary(matrixData);
ContextManager.getSubmissionService().save(theSubmission);
theMatrix.setMatrix(matrixData);
theData = theMatrix;
} else if (ioSection.label.equals("OUTPUT_TREE")) {
if (theTreeBlock == null) {
theTreeBlock = new TreeBlock();
ContextManager.getStudyService().save(theTreeBlock); // XXX should be some treeblock-specific service
theSubmission.addPhyloTreeBlock(theTreeBlock);
ContextManager.getSubmissionService().save(theSubmission);
}
AnalyzedTree theTree = new AnalyzedTree();
theTree.setInput(false);
String treeID = ioSection.getsval("tree_id");
PhyloTree treeData = trees.get(treeID);
treeData.setStudy(theStudy);
ContextManager.getTaxonLabelService().updateStudyForAllLabels(treeData, theStudy);
treeData.setTB1TreeID(treeID);
ContextManager.getPhyloTreeService().save(treeData);
theTreeBlock.addPhyloTree(treeData);
theSubmission.addPhyloTreeBlockIfNecessary(theTreeBlock);
ContextManager.getSubmissionService().save(theSubmission);
theTree.setTree(treeData);
theData = theTree;
} else {
throw new Error("Unknown IO section '" + ioSection.label + "' in study " + aux.getString(null, "study_id"));
}
theData.setAnalysisStep(theAnalysisStep);
ContextManager.getAnalyzedDataService().save(theData);
theAnalysisStep.addAnalyzedData(theData);
ContextManager.getAnalysisStepService().save(theAnalysisStep);
}
}
// TODO: fix submission taxa list
Software theSoftware = new Software();
theSoftware.setName(an.getString("software"));
ContextManager.getStudyService().save(theSoftware); // XXX should be SoftwareService
theAnalysisStep.setSoftwareInfo(theSoftware);
theAnalysisStep.setNotes("Imported from TB1");
ContextManager.getAnalysisStepService().save(theAnalysisStep);
theStudy.addAnalysis(theAnalysis);
ContextManager.getStudyService().save(theStudy);
}