コード例 #1
0
 private String addNewInteraction(String fingerprint, BiologicalInteraction interaction)
     throws SQLException {
   String sql =
       String.format(
           "INSERT IGNORE INTO interaction (fingerprint) VALUES (%s)",
           SqlUtil.toSqlVarchar(fingerprint));
   if (1 != DBUtil.update(sql)) {
     System.out.println("SQL update failed? " + sql);
   }
   String interaction_id = DBUtil.querySingle("SELECT LAST_INSERT_ID()");
   Iterator<BiologicalEntity> iter = interaction.getEntityIterator();
   StringBuffer sb =
       new StringBuffer(
           "INSERT IGNORE INTO interaction_pool (interaction_id, gene_id, entity_src_table, role) VALUES ");
   while (iter.hasNext()) {
     BiologicalEntity entity = iter.next();
     sb.append("(")
         .append(interaction_id)
         .append(", ")
         .append(SqlUtil.toSqlVarchar(entity.getId()))
         .append(", '")
         .append(srcTableLookup.get(entity.getId_src()))
         .append("', '")
         .append(entity.getRole())
         .append("')");
     if (iter.hasNext()) sb.append(", ");
   }
   if (DBUtil.update(sb.toString()) != interaction.getEnvolvedEntityCount()) {
     System.out.println("SQL update failed? " + sb);
   }
   return interaction_id;
 }
コード例 #2
0
  public void flush() throws SQLException {
    InteractionFingerprinter fingerprinter = new InteractionFingerprinter();
    for (BiologicalInteraction interaction : interactions) {
      String fingerprint = fingerprinter.getFingerprint(interaction);
      String sql =
          String.format(
              "SELECT interaction_id FROM interaction WHERE fingerprint=%s",
              SqlUtil.toSqlVarchar(fingerprint));
      String id = DBUtil.querySingle(sql);

      if (id == null) {
        id = addNewInteraction(fingerprint, interaction);
      }

      interaction.setInteractionId(Integer.valueOf(id));
    }
    System.out.println("Evidences count: " + evidences.size());
    for (Evidence evidence : evidences) {
      String sql =
          "INSERT INTO evidence SET "
              + "interaction_id="
              + evidence.getInteraction().getInteractionId()
              + ", "
              + "negative=0, "
              + "directed="
              + (evidence.getInteraction().isDirected() ? 1 : 0)
              + ", "
              + "interaction_type='"
              + evidence.getInteraction().getInteractionType()
              + "', "
              + "source='"
              + evidence.getDataSource()
              + "', "
              + "macro_id='"
              + evidence.getMacroId()
              + "', "
              + "micro_id='"
              + evidence.getMicroId()
              + "', "
              + "confidence=100, "
              + "evidence_text="
              + SqlUtil.toSqlVarchar(evidence.getEvidenceText())
              + ", "
              + "curator=0";
      DBUtil.update(sql);
    }
  }