Example #1
0
  public ExptLocatorTree(Genome g) {
    super();
    try {
      java.sql.Connection c = DatabaseFactory.getConnection(ExptLocator.dbRole);
      int species = g.getSpeciesDBID();
      int genome = g.getDBID();

      Statement s = c.createStatement();
      ResultSet rs = null;

      rs =
          s.executeQuery(
              "select e.name, e.version from experiment e, exptToGenome eg where e.active=1 and "
                  + "e.id=eg.experiment and eg.genome="
                  + genome);
      while (rs.next()) {
        String name = rs.getString(1);
        String version = rs.getString(2);
        ChipChipLocator loc = new ChipChipLocator(g, name, version);
        this.addElement(loc.getTreeAddr(), loc);
      }
      rs.close();

      rs =
          s.executeQuery(
              "select ra.name, ra.version from rosettaanalysis ra, rosettaToGenome rg where "
                  + "ra.id = rg.analysis and ra.active=1 and rg.genome="
                  + genome);
      while (rs.next()) {
        String name = rs.getString(1);
        String version = rs.getString(2);
        MSPLocator msp = new MSPLocator(g, name, version);
        this.addElement(msp.getTreeAddr(), msp);
      }
      rs.close();

      rs =
          s.executeQuery(
              "select ra.name, ra.version from bayesanalysis ra, bayesToGenome rg where "
                  + "ra.id = rg.analysis and ra.active=1 and rg.genome="
                  + genome);
      while (rs.next()) {
        String name2 = rs.getString(1);
        String version2 = rs.getString(2);
        ExptLocator loc2 = new BayesLocator(g, name2, version2);
        addElement(loc2.getTreeAddr(), loc2);
      }
      rs.close();
      s.close();

      DatabaseFactory.freeConnection(c);
    } catch (SQLException se) {
      se.printStackTrace(System.err);
      throw new RuntimeException(se);
    } catch (UnknownRoleException e) {
      e.printStackTrace();
    }
  }
  public Collection<Experiment> findExpts(CellLine cells, ExptCondition cond) throws SQLException {

    LinkedList<Integer> dbids = new LinkedList<Integer>();

    String tables = "experiment e";
    if (genome != null) {
      tables += ", probe_platform_to_genome p2g";
    }

    String query = "select e.id from " + tables;

    Vector<String> conds = new Vector<String>();

    if (genome != null) {
      int gid = genome.getDBID();
      conds.add("e.platform=p2g.platform and p2g.genome=" + gid);
    }

    if (cells != null) {
      conds.add("e.cells=" + cells.getDBID());
    }

    if (cond != null) {
      conds.add("e.condition=" + cond.getDBID());
    }

    for (int i = 0; i < conds.size(); i++) {
      if (i == 0) {
        query += " where ";
      } else {
        query += " and ";
      }
      query += conds.get(i);
    }

    System.out.println("Final Query: \"" + query + "\"");

    java.sql.Connection cxn = loader.getConnection();
    Statement s = cxn.createStatement();
    ResultSet rs = s.executeQuery(query);

    while (rs.next()) {
      int dbid = rs.getInt(1);
      dbids.addLast(dbid);
    }

    rs.close();
    s.close();

    Collection<Experiment> expts = loader.loadExperiments(dbids);
    return expts;
  }
  public CellLine getCells(Experiment expt) throws SQLException, UnknownRoleException {

    java.sql.Connection cxn = loader.getConnection();
    PreparedStatement ps = cxn.prepareStatement("select cells from experiment" + " where id=?");
    ps.setInt(1, expt.getDBID());
    ResultSet rs = ps.executeQuery();
    int cellsID = -1;
    if (rs.next()) {
      cellsID = rs.getInt(1);
    }
    rs.close();
    ps.close();

    return chipLoader.loadCellLine(cellsID);
  }