Esempio n. 1
0
  public MetabolicReaction parseTwoSidedReaction(
      PreparsedReaction preparsed, String[] equationSides) throws UnparsableReactionError {

    Matcher reactionCompartment = REACTION_COMPARTMENT.matcher(equationSides[0]);

    MetabolicReaction rxn = getReaction(preparsed);

    Compartment defaultCompartment = Organelle.CYTOPLASM;

    if (reactionCompartment.find()) {
      defaultCompartment = resolver.getCompartment(reactionCompartment.group(1));
      equationSides[0] = reactionCompartment.replaceAll("");
    }

    for (MetabolicParticipantImplementation p :
        parseParticipants(equationSides[0], defaultCompartment, preparsed)) {
      rxn.addReactant(p);
    }
    for (MetabolicParticipantImplementation p :
        parseParticipants(equationSides[1], defaultCompartment, preparsed)) {
      rxn.addProduct(p);
    }

    return rxn;
  }
Esempio n. 2
0
  /** @inheritDoc */
  public boolean update(Collection<MetabolicReaction> reactions) {

    boolean changed = false;

    for (MetabolicReaction reaction : reactions) {
      if (reactionMap.containsEntry(reaction.getIdentifier(), reaction)) {
        changed = update(reaction) || changed;
      }
    }

    return changed;
  }
Esempio n. 3
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);
   }
 }
Esempio n. 4
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);
  }
Esempio n. 5
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);
  }
Esempio n. 6
0
  /** Only have left side (or some weird reaction operator) */
  public MetabolicReaction parseExchangeReaction(PreparsedReaction reaction, String equationSide)
      throws UnparsableReactionError {
    Matcher reactionCompartment = REACTION_COMPARTMENT.matcher(equationSide);

    MetabolicReaction rxn = getReaction(reaction);

    Compartment defaultCompartment = Organelle.CYTOPLASM;

    if (reactionCompartment.find()) {
      defaultCompartment = resolver.getCompartment(reactionCompartment.group(1));
      equationSide = reactionCompartment.replaceAll("");
    }

    for (MetabolicParticipantImplementation p :
        parseParticipants(equationSide, defaultCompartment, reaction)) {
      rxn.addReactant(p);
    }

    return rxn;
  }
Esempio n. 7
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;
  }
Esempio n. 8
0
  public MetabolicReaction getReaction(PreparsedReaction preparsed) {

    MetabolicReaction rxn =
        factory.ofClass(
            MetabolicReaction.class,
            BasicReactionIdentifier.nextIdentifier(),
            preparsed.hasValue(DESCRIPTION) ? preparsed.getValue(DESCRIPTION) : "",
            preparsed.hasValue(ABBREVIATION) ? preparsed.getValue(ABBREVIATION) : "");

    if (preparsed.hasValue(DIRECTION)) {
      rxn.setDirection(getReactionArrow(preparsed.getValue(DIRECTION)));
    } else {
      rxn.setDirection(getReactionArrow(preparsed.getEquation()));
    }

    // add subsytem annotation
    if (preparsed.hasValue(SUBSYSTEM)) {
      rxn.addAnnotation(new Subsystem(preparsed.getSubsystem()));
    }

    // add classification
    for (String classification : preparsed.getClassifications()) {
      // load EC code
      if (classification.matches("(?:\\d+\\.){3}\\d+") || classification.contains("EC")) {
        rxn.addAnnotation(new EnzymeClassification(new ECNumber(classification)));
      } else if (classification.contains("TC")) {
        rxn.addAnnotation(new Classification(new TransportClassificationNumber(classification)));
      }
    }

    // add loci
    for (String locus : preparsed.getLoci()) {
      rxn.addAnnotation(new Locus(locus));
    }

    // add delta g and delta g error
    if (preparsed.hasValue(FREE_ENERGY)) {
      try {
        if (preparsed.hasValue(FREE_ENERGY_ERROR)) {
          rxn.addAnnotation(
              new GibbsEnergy(
                  Double.parseDouble(preparsed.getValue(FREE_ENERGY)),
                  Double.parseDouble(preparsed.getValue(FREE_ENERGY_ERROR))));
        } else {
          rxn.addAnnotation(
              new GibbsEnergy(Double.parseDouble(preparsed.getValue(FREE_ENERGY)), 0d));
        }
      } catch (NumberFormatException ex) {
        LOGGER.error("Gibbs energy column(s) contained invalid value (not a double)");
      }
    }

    if (preparsed.hasValue(MIN_FLUX)) {
      try {
        rxn.addAnnotation(new FluxLowerBound(Double.parseDouble(preparsed.getValue(MIN_FLUX))));
      } catch (NumberFormatException ex) {
        LOGGER.error(
            "Min flux column contained invalid value (not a double): "
                + preparsed.getValue(MIN_FLUX));
      }
    }

    if (preparsed.hasValue(MAX_FLUX)) {
      try {
        rxn.addAnnotation(new FluxLowerBound(Double.parseDouble(preparsed.getValue(MAX_FLUX))));
      } catch (NumberFormatException ex) {
        LOGGER.error(
            "Max flux column contained invalid value (not a double): "
                + preparsed.getValue(MAX_FLUX));
      }
    }

    return rxn;
  }