TEXT   52
PhyloTreeDAO
Guest on 22nd April 2022 01:10:13 AM


  1.         public Set<PhyloTree> findByTopology3(TaxonVariant a, TaxonVariant b, TaxonVariant c) {
  2.                 Set<PhyloTree> returnVal = new HashSet<PhyloTree>();
  3.                                
  4.                 Set<TaxonVariant> aTV = getTaxonLabelHome().expandTaxonVariant(a);
  5.                 Set<TaxonVariant> bTV = getTaxonLabelHome().expandTaxonVariant(b);
  6.                 Set<TaxonVariant> cTV = getTaxonLabelHome().expandTaxonVariant(c);
  7.                
  8.                 if (aTV.isEmpty() || bTV.isEmpty() || cTV.isEmpty()) {
  9.                         // XXX This avoids a query syntax error later on but maybe isn't
  10.                         // the best behavior.
  11.                         return new HashSet<PhyloTree> ();
  12.                 }
  13.                
  14.                 String query = "select distinct a.tree.rootNode "
  15.                         +
  16.                         // Find the trees with three nodes a, b, and c, such that...
  17.                         "from PhyloTreeNode as a, PhyloTreeNode as b, PhyloTreeNode as c, "
  18.                         +
  19.                         // There's a node "ab" (which will be an ancestor of both a and b)
  20.                         "PhyloTreeNode as ab "
  21.                         +
  22.                         // All four nodes are in the same tree
  23.                         "where a.tree = b.tree " + "and a.tree = c.tree " + "and a.tree = ab.tree "
  24.                         +
  25.                         "and a.taxonLabel.taxonVariant in (:a) " +
  26.                         "and b.taxonLabel.taxonVariant in (:b) " +
  27.                         "and c.taxonLabel.taxonVariant in (:c) " +
  28.                                                 // ab is an ancestor of a
  29.                         "and ab.leftNode < a.leftNode and ab.rightNode > a.rightNode " +
  30.                         // ab is an ancestor of b
  31.                         "and ab.leftNode < b.leftNode and ab.rightNode > b.rightNode " +
  32.                         // ab is NOT an ancestor of c
  33.                         "and (ab.leftNode >= c.leftNode or ab.rightNode <= c.rightNode) ";
  34.                
  35.                 Query q = getSession().createQuery(query);
  36.  
  37.                 q.setParameterList("a", aTV);
  38.                 q.setParameterList("b", bTV);
  39.                 q.setParameterList("c", cTV);
  40.                 List<PhyloTreeNode> rootNodes = q.list();
  41.  
  42.                 if (rootNodes.isEmpty()) {
  43.                         return returnVal;
  44.                 }
  45.  
  46.                 Query t = getSession().createQuery("from PhyloTree where rootNode in (:roots)");
  47.                 t.setParameterList("roots", rootNodes);
  48.  
  49.                 returnVal.addAll(t.list());
  50.                 return returnVal;
  51.         }

Raw Paste

Login or Register to edit or fork this paste. It's free.