Package org.cipres.treebase.domain.study

Examples of org.cipres.treebase.domain.study.Study


    // 1. create a new study:
    String newName = testName + " test " + Math.random();
    StudyStatus inprogress = getStudyStatusHome().findStatusInProgress();

    Study s = new Study();
    s.setName(newName);
    s.setStudyStatus(inprogress);

    getStudyHome().store(s);

    // force commit immeidately, important:
    setComplete();
    endTransaction();

    Long studyID = s.getId();

    logger.info("study created: " + s.getName() + "id = " + studyID);

    // 2. verify
    String sqlStr = "select count(*) from Study where study_id=" + s.getId();
    int count = jdbcTemplate.queryForInt(sqlStr);
    assertTrue(count == 1);

    // assertTrue("need to return Analysis ID.", a1.getId() != null);

    // 3. add nexus
    startNewTransaction();

    String fileName = "test nexus";
    String nexus = "#NEXUS\n"
      + "a       ctgactcctgaggagaagtctgccgttactgccctgtggggcaaggtgaacgtggatgaagttggtggtgag gccctgggcaggctgctggtggtctacccttggacccagaggttctttgagtcctttggggatctgtccact cctgatgctgttatgggcaaccctaaggtgaaggctcatggcaagaaagtgctcggtgcctttagtgatggc ctggctcacctggacaacctcaagggcacctttgccacactgagtgagctgcactgtgacaagctgcacgtg gatcctgagaacttcaggctcctgggcaacgtgctggtctgtgtgctggcccatcactttggcaaagaattc accccaccagtgcaggctgcctatcagaaagtggtggctggtgtggctaatgccctggcccacaagtatcac\n"
      + "b       ctgactgctgaagagaaggccgccgtcactgccctgtggggcaaggtagacgtggaagatgttggtggtgag gccctgggcaggctgctggtcgtctacccatggacccagaggttctttgactcctttggggacctgtccact cctgccgctgttatgagcaatgctaaggtcaaggcccatggcaaaaaggtgctgaacgcctttagtgacggc atggctcatctggacaacctcaagggcacctttgctaagctgagtgagctgcactgtgacaaattgcacgtg gatcctgagaatttcaggctcttgggcaatgtgctggtgtgtgtgctggcccaccactttggcaaagaattc accccgcaggttcaggctgcctatcagaaggtggtggctggtgtggctactgccttggctcacaagtaccac\n"
      + "c       ctgactcctgatgagaagaatgccgtttgtgccctgtggggcaaggtgaatgtggaagaagttggtggtgag gccctgggcaggctgctggttgtctacccatggacccagaggttctttgactcctttggggacctgtcctct ccttctgctgttatgggcaaccctaaagtgaaggcccacggcaagaaggtgctgagtgcctttagcgagggc ctgaatcacctggacaacctcaagggcacctttgctaagctgagtgagctgcattgtgacaagctgcacgtg gaccctgagaacttcaggctcctgggcaacgtgctggtggttgtcctggctcaccactttggcaaggatttc accccacaggtgcaggctgcctatcagaaggtggtggctggtgtggctactgccctggctcacaaataccac\n"
      + "d       ctgtccggtgaggagaagtctgcggtcactgccctgtggggcaaggtgaatgtggaagaagttggtggtgag accctgggcaggctgctggttgtctacccatggacccagaggttcttcgagtcctttggggacctgtccact gcttctgctgttatgggcaaccctaaggtgaaggctcatggcaagaaggtgctggctgccttcagtgagggt ctgagtcacctggacaacctcaaaggcaccttcgctaagctgagtgaactgcattgtgacaagctgcacgtg gatcctgagaacttcaggctcctgggcaacgtgctggttattgtgctgtctcatcactttggcaaagaattc actcctcaggtgcaggctgcctatcagaaggtggtggctggtgtggccaatgccctggctcacaaataccac\n"
      + "e       ctgtccagtgaggagaagtctgcggtcactgccctgtggggcaaggtgaatgtggaagaagttggtggtgag gccctgggcaggctgctggttgtctacccatggacccagaggttcttcgagtcctttggggacctgtcctct gcaaatgctgttatgaacaatcctaaggtgaaggctcatggcaagaaggtgctggctgccttcagtgagggt ctgagtcacctggacaacctcaaaggcacctttgctaagctgagtgaactgcactgtgacaagctgcacgtg gatcctgagaacttcaggctcctgggcaacgtgctggttattgtgctgtctcatcattttggcaaagaattc actcctcaggtgcaggctgcctatcagaaggtggtggctggtgtggccaatgccctggctcacaaataccac\n"
      + "f       ctgactgctgaggagaaggctgccgtcaccgccttttggggcaaggtgaaagtggatgaagttggtggtgag gccctgggcaggctgctggttgtctacccctggactcagaggttctttgagtcctttggggacttgtccact gctgatgctgttatgaacaaccctaaggtgaaggcccatggcaagaaggtgctagattcctttagtaatggc atgaagcatctcgatgacctcaagggcacctttgctgcgctgagtgagctgcactgtgataagctgcatgtg gatcctgagaacttcaagctcctgggcaacgtgctagtggttgtgctggctcgcaattttggcaaggaattc accccggtgctgcaggctgactttcagaaggtggtggctggtgtggccaatgccctggcccacagatatcat\n"
      + "g       ctgtccgatgcggtcaacgctgccgtcaccgccttttggggcaaggtgaaagtggatcaagttggtggtgag gccctgggcaggccgctggttgtctaccgctggactcagaggtgctatgagtcctttggagacttgtccact gctgatgctgttatgaacaaccctaaggtgaaggcccatggcaagaaggtgctagattcctttagtaatggc atgaagcatctcgatgacctcaagggcacctttgctgcgctgagtgagctgcactgtgataagctgcatgtg gatcctgagaacttcaagctcctgggcaacgtgctagtggttgtgctggctcgcaattttggcaaggaattc accccggtgctgcaggctgactttcagaaggtggtggctggtgtggccaatgccctggcccacagatatcat\n";

    //Clob nexusC = Hibernate.createClob(nexus);
    getStudyHome().refresh(s);

    s.addNexusFile(fileName, nexus);

    // force commit immeidately, important:
    setComplete();
    endTransaction();

    // 4. verify nexus
    String sqlNexus = "select count(*) from Study_nexusFile where study_id=" + s.getId();
    int countNexus = jdbcTemplate.queryForInt(sqlNexus);
    assertTrue(countNexus == 1);

    startNewTransaction();
    String nexusString = s.getNexusFiles().values().iterator().next();
    int nexusLength = (int) nexusString.length();
    // String clobStr = nexusClob.getSubString(0, 200);

    //char[] clobchars = new char[clobLength];
    //nexusClob.getCharacterStream().read(clobchars);
View Full Code Here


//      t2.commit();
    }
   
//    Transaction t = getSession().beginTransaction();

    Study theStudy = aux.study(ContextManager.getStudyService());
    if (theStudy == null) {
      theStudy = new Study();
      ContextManager.getSubmissionService().createSubmission(null, theStudy);
    }
    theStudy.setTB1StudyID(study_id);
    theStudy.setAccessionNumber(study_id);
    theStudy.setStudyStatus(ContextManager.getStudyStatusHome().findStatusPublished());
    ContextManager.getStudyService().save(theStudy);
   
    Submission theSubmission = theStudy.getSubmission();
    ContextManager.getSubmissionService().save(theSubmission);

    Citation theCitation = theStudy.getCitation();
    if (theCitation == null) {
      theCitation = ContextManager.getCitationService().createCitation("TB1");
      theCitation.setStudy(theStudy);
      theStudy.setCitation(theCitation);
      ContextManager.getStudyService().save(theStudy);
    }
   
    { // Truncate extremely long abstracts
      String theAbstract = aux.getString(null, "abstract");
      if (theAbstract.length() > citationMaxLength - 4) {
        theAbstract = theAbstract.substring(0, citationMaxLength - 4) + "...";
      }
      theCitation.setAbstract(theAbstract);
    }
    // this next isn't quite right, because TB1 "citation" contains title, author, publisher, etc.
    // nothing to be done here, I think.  20080229 MJD
    // We can postprocess the citation data with Perl or something
    // to break it up into its component parts. 20080605 MJD
    // Piel says that Rod Page already did this. 20080702 MJD

    // Rutger has a program in util.CitationDataImporter that should do it 20090220 MJD
    {
      String citation = aux.getString(null, "citation");
      if (citation.length() > 250) {
        // It won't all fit into the "title" field of the database
        citation = citation.substring(0, 250); // XXX
      }
      theCitation.setTitle(citation); // XXX
   
    ContextManager.getCitationService().save(theCitation);
 
    // Create or link authors
    for (ValueSection a : aux.getSections("AUTHOR")) {
      Person theAuthor = new Person();
      theAuthor.setFirstName(a.getsval("first_name"));
      theAuthor.setLastName(a.getsval("last_name"));
      theAuthor.setMiddleName("");
//      ContextManager.getPersonService().save(theAuthor);
      // TB1 "author_id" ??
      Person oldAuthor = ContextManager.getPersonService().findByExactMatch(theAuthor);
      if (oldAuthor != null) {
        theAuthor = oldAuthor;
      } else {
        ContextManager.getPersonService().createPerson(theAuthor);
        theAuthor = ContextManager.getPersonService().findByExactMatch(theAuthor);
      }

      String oldEmail = theAuthor.getEmailAddressString();
      if (oldEmail == null || oldEmail.equals("")) {
        theAuthor.setEmailAddressString(a.getsval("email"));
     

      ContextManager.getPersonService().save(theAuthor);
      theCitation.addAuthor(theAuthor);
    }
    ContextManager.getCitationHome().flush();
    ContextManager.getCitationService().save(theCitation);

    // TODO: submission.setSubmitter
    theSubmission.setTest(isForTesting() ? 0 : 1);

    {
      Date creationDate = aux.getCreationDate();
      if (creationDate != null) {
        theSubmission.setCreateDate(creationDate);
      } else {
        warn("  Couldn't find creation date");
      }
    }

    for (ValueAnalysisSection an : aux.getAnalysisSections()) {
      Analysis theAnalysis = new Analysis();
      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);
    }

    warn("  Commiting the study (" + theStudy.getId() + ") to the database");
//    t.commit();
    warn("    Committed");
   
    getAddMetaData().perform(v);
   
View Full Code Here

    // 1. create a new study:
    String newName = testName + " test " + Math.random();
    StudyStatus inprogress = getStudyStatusHome().findStatusInProgress();

    Study s = new Study();
    s.setName(newName);
    s.setStudyStatus(inprogress);

    getStudyHome().store(s);

    // force commit immeidately, important:
    setComplete();
    endTransaction();

    Long studyID = s.getId();

    logger.info("study created: " + s.getName() + "id = " + studyID);

    // 2. verify
    String sqlStr = "select count(*) from Study where study_id=" + s.getId();
    int count = jdbcTemplate.queryForInt(sqlStr);
    assertTrue(count == 1);

    // assertTrue("need to return Analysis ID.", a1.getId() != null);

    // 3. add nexus
    startNewTransaction();
    getFixture().update(s);
    String path = "/49LBR.PDI-branch-length-continue.nex"; // continuous matrix, provided by
    // Peter M.
    File nexusFile = new File(getClass().getResource(path).toURI());
    Collection<File> files = new ArrayList<File>();
    files.add(nexusFile);

    getFixture().addNexusFiles(s, files);

    // force commit immeidately, important:
    setComplete();
    endTransaction();

    // 4. verify nexus
    String sqlNexus = "select count(*) from Study_nexusFile where study_id=" + s.getId();
    int countNexus = jdbcTemplate.queryForInt(sqlNexus);
    logger.info("study_nexusFile: count =" + countNexus);
    assertTrue(countNexus == 1);

    // Print out the clob content
View Full Code Here

    // 1. get a valid nexus file name:
    String fileName = "wtset.nex";   
    long studyId = 100L;
    logger.info("study id: " + studyId);
    assertTrue(studyId > 0);
    Study s = (Study) hibernateTemplate.get(Study.class, studyId);
    Submission sub = s.getSubmission();
    if (fileName == null) {
      fileName = s.getNexusFiles().keySet().iterator().next();
    }
    logger.info("study found: " + s.getName() + "id = " + s.getId() + " fileName=" + fileName);
    logger.info("submission found: " + "id = " + sub.getId());

    // 2. test:
    long t1 = System.currentTimeMillis();
    assertTrue("Failed to refresh submission.", sub != null);
View Full Code Here

    this.out = out;
  }

  public Value perform(Value v) {
    AuxData aux = new AuxData((ValueStudy) v);
    Study s;
    {
      String studyId = aux.getStudyID();
      Collection<Study> studies = ContextManager.getStudyService().findByTBStudyID(studyId);
      if (studies.size() == 0) {
        out.println("Couldn't locate study " + studyId + "; skipping");
        return new ValueNone();
      } else if (studies.size() > 1) {
        out.println("Multiple studies with ID " + studyId + "; skipping");
        return new ValueNone();
      }
     
      Study[] tmp = { null };
      studies.toArray(tmp);
      s = tmp[0];

      out.println("Processing study " + studyId);
    }
   
    Transaction t = session.beginTransaction();
   
    Citation cit = s.getCitation();
    cit.setAuthors(new ArrayList<Person>());
    ContextManager.getCitationHome().flush();
   
    for (ValueSection authorSection : aux.getSections("AUTHOR")) {
      Person theAuthor = new Person();
View Full Code Here

    }
    Map<String,AnalyzedData> analyzedDataForData = new HashMap<String,AnalyzedData>();
    long studyId = 794; // this study seems to have character sets
   
    // this is the full study as it is stored by the database
    Study tbStudy = (Study)loadObject(Study.class, studyId);
   
    // this is an object representation of a NeXML document
    Document nexDoc = DocumentFactory.safeCreateDocument();
   
    // the converter populates the NeXML document with the contents of the treebase study
View Full Code Here

    User submitter = null; // No submitter

    //Study s = bulkUpload.addFileSimple(new File(dirName, fn), submitter, session);
    //Study s = addFilesSimple(undoneFiles, submitter, null);     //VG 2010-02-18 -- see comment at the method
    Study s = addFilesOneByOne(undoneFiles, submitter);
    if (s == null) {
      log("conversion of files failed");
    } else {
      log("conversion of files successful, saved nexus files as study id=" + s.getId() + " submission id="
          + s.getSubmission().getId());
    }
  }
View Full Code Here

  //since then all trees and files are bundled into a huge transaction,
  //where a single failure scraps uploads of all prior trees and files (but not matrices!)
  public Study addFilesSimple(List<File> files, User aUser, Session session) throws IOException {
    //Transaction t = session.beginTransaction();
    Submission sub = getPseudoSubmission();
    Study study = sub.getStudy();
   
    log("submission ID = " + sub.getId() + " study ID " + study.getId());

    UploadFileResult uploadResult = ContextManager.getSubmissionService().addNexusFilesJDBC(sub, files, null);
//    commitTransaction();
    log("added " + uploadResult.getMatrixCount() + " matrices and " + uploadResult.getTreeCount() + " trees.");
View Full Code Here

  }
 
  //VG 2010-02-18 This fixes the deficiency of addFilesSimple by committing each file upload.
  public Study addFilesOneByOne(List<File> files, User aUser) throws IOException {
    Submission sub = getPseudoSubmission();
    Study study = sub.getStudy();   
    log("submission ID = " + sub.getId() + " study ID " + study.getId());

    int countMatrices = 0, countTrees = 0;
    for (File f : files) {
      beginTransaction();
      List<File> theFile = new LinkedList<File> ();
View Full Code Here

    Set<PhyloTree> phyloTreeSet = getResults();
    if ( phyloTreeSet != null ) {

      // for each tree in the result set we need to traverse its associated study
      for ( PhyloTree phyloTree : phyloTreeSet ) {
        Study study = phyloTree.getStudy();
       
        // need to resurrect the study, otherwise we get a LazyInitializationException
        Study resurrectedStudy = getStudyService().resurrect(study);
       
        if ( resurrectedStudy != null ) {
          Collection<AnalysisStep> analysisStepCollection = resurrectedStudy.getAnalysisSteps();
         
          // for the study we need to iterate over all analysis steps
          for ( AnalysisStep analysisStep : analysisStepCollection ) {
            Collection<AnalyzedData> analyzedDataCollection = analysisStep.getDataSetReadOnly();
            boolean treeIsOutput = false;
View Full Code Here

TOP

Related Classes of org.cipres.treebase.domain.study.Study

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.