Beispiel #1
0
 public void rebuildMaps() {
   participantMap.clear();
   reactionMap.clear();
   for (MetabolicReaction rxn : this) {
     for (MetabolicParticipant m : rxn.getReactants()) {
       participantMap.get(m.getMolecule().getIdentifier()).add(rxn);
     }
     for (MetabolicParticipant m : rxn.getProducts()) {
       participantMap.get(m.getMolecule().getIdentifier()).add(rxn);
     }
     reactionMap.put(rxn.getIdentifier(), rxn);
   }
 }
Beispiel #2
0
  @Override
  public boolean remove(MetabolicReaction rxn) {

    // remove links to metabolites
    for (MetabolicParticipant p : rxn.getParticipants()) {
      Metabolite m = p.getMolecule();
      participantMap.get(m.getIdentifier()).remove(rxn);
      if (participantMap.get(m.getIdentifier()).isEmpty()) {
        participantMap.removeAll(m.getIdentifier());
      }
    }
    reactionMap.remove(rxn.getIdentifier(), rxn);
    return super.remove(rxn);
  }
Beispiel #3
0
  @Override
  public boolean add(MetabolicReaction rxn) {

    if (rxn == null) return false;

    if (reactionMap.containsKey(rxn.getIdentifier())) return false;

    for (MetabolicParticipant m : rxn.getParticipants()) {
      participantMap.get(m.getMolecule().getIdentifier()).add(rxn);
    }

    reactionMap.put(rxn.getIdentifier(), rxn);

    return super.add(rxn);
  }
Beispiel #4
0
  /** @inheritDoc */
  public boolean update(MetabolicReaction reaction) {

    Identifier identifier = reaction.getIdentifier();

    if (reactionMap.containsKey(identifier)) {

      PARTICIPANTS:
      for (MetabolicParticipant p : reaction.getParticipants()) {

        Identifier id = p.getMolecule().getIdentifier();

        boolean found = false;
        for (MetabolicReaction rxn : participantMap.get(id)) {
          if (rxn == reaction) continue PARTICIPANTS; // continue to next participant
        }

        participantMap.put(id, reaction);
      }
      return true;
    }

    return false;
  }