Adds or updates a single nucleotide to the nucleotide store using the URL configured in
{@code MonomerStoreConfiguration}.

@param nucleotide to save
@return response from the webservice
338174
public String saveNucleotideToStore(Nucleotide nucleotide) {
    String res = "";
    CloseableHttpResponse response = null;

    try {
      response = WSAdapterUtils.putResource(nucleotide.toJSON(),
          MonomerStoreConfiguration.getInstance()
              .getWebserviceNucleotidesPutFullURL());
      LOG.debug(response.getStatusLine().toString());

      EntityUtils.consume(response.getEntity());

    } catch (Exception e) {
      LOG.error("Saving nucleotide failed!", e);
      return "";
    } finally {
      try {
        if (response != null) {
          response.close();
        }
      } catch (IOException e) {
        LOG.debug("Closing resources failed.", e);
        return res;
      }
    }

    return res;
  }
992190
def store(self, seq, nsaliases):
        
        if not self._writeable:
            raise RuntimeError("Cannot write -- opened read-only")

        if self._upcase:
            seq = seq.upper()

        try:
            seqhash = bioutils.digests.seq_seqhash(seq)
        except Exception as e:
            import pprint
            _logger.critical("Exception raised for " + pprint.pformat(nsaliases))
            raise
        seq_id = seqhash

        # add sequence if not present
        n_seqs_added = n_aliases_added = 0
        msg = "sh{nsa_sep}{seq_id:.10s}... ({l} residues; {na} aliases {aliases})".format(
            seq_id=seq_id,
            l=len(seq),
            na=len(nsaliases),
            nsa_sep=nsa_sep,
            aliases=", ".join("{nsa[namespace]}:{nsa[alias]}".format(nsa=nsa) for nsa in nsaliases))
        if seq_id not in self.sequences:
            _logger.info("Storing " + msg)
            if len(seq) > ct_n_residues:    # pragma: no cover
                _logger.debug("Precommit for large sequence")
                self.commit()
            self.sequences.store(seq_id, seq)
            n_seqs_added += 1
            self._pending_sequences += 1
            self._pending_sequences_len += len(seq)
            self._pending_aliases += self._update_digest_aliases(seq_id, seq)
        else:
            _logger.debug("Sequence exists: " + msg)

        # add/update external aliases for new and existing sequences
        # updating is optimized to load only new <seq_id,ns,alias> tuples
        existing_aliases = self.aliases.fetch_aliases(seq_id)
        ea_tuples = [(r["seq_id"], r["namespace"], r["alias"]) for r in existing_aliases]
        new_tuples = [(seq_id, r["namespace"], r["alias"]) for r in nsaliases]
        upd_tuples = set(new_tuples) - set(ea_tuples)
        if upd_tuples:
            _logger.info("{} new aliases for {}".format(len(upd_tuples), msg))
            for _, namespace, alias in upd_tuples:
                self.aliases.store_alias(seq_id=seq_id, namespace=namespace, alias=alias)
            self._pending_aliases += len(upd_tuples)
            n_aliases_added += len(upd_tuples)
        if (self._pending_sequences > ct_n_seqs or self._pending_aliases > ct_n_aliases
                or self._pending_sequences_len > ct_n_residues):    # pragma: no cover
            _logger.info("Hit commit thresholds ({self._pending_sequences} sequences, "
                        "{self._pending_aliases} aliases, {self._pending_sequences_len} residues)".format(self=self))
            self.commit()
        return n_seqs_added, n_aliases_added
994430
public static base_responses update(nitro_service client, rnat resources[]) throws Exception {
		base_responses result = null;
		if (resources != null && resources.length > 0) {
			rnat updateresources[] = new rnat[resources.length];
			for (int i=0;i<resources.length;i++){
				updateresources[i] = new rnat();
				updateresources[i].network = resources[i].network;
				updateresources[i].netmask = resources[i].netmask;
				updateresources[i].natip = resources[i].natip;
				updateresources[i].td = resources[i].td;
				updateresources[i].aclname = resources[i].aclname;
				updateresources[i].redirectport = resources[i].redirectport;
				updateresources[i].natip2 = resources[i].natip2;
			}
			result = update_bulk_request(client, updateresources);
		}
		return result;
	}
1020826
@Override
    public void customize(IAtomContainer molecule, Object nodeToAdd) throws Exception {
        if (!(nodeToAdd instanceof CMLMolecule)) throw new CDKException("NodeToAdd must be of type nu.xom.Element!");

        //The nodeToAdd
        CMLMolecule molToCustomize = (CMLMolecule) nodeToAdd;

        if ((molecule instanceof MDMolecule)) {
            MDMolecule mdmol = (MDMolecule) molecule;
            molToCustomize.setConvention("md:mdMolecule");
            molToCustomize.addNamespaceDeclaration("md", "http://www.bioclipse.net/mdmolecule/");

            //Residues
            if (mdmol.getResidues().size() > 0) {
                Iterator it = mdmol.getResidues().iterator();
                while (it.hasNext()) {
                    Residue residue = (Residue) it.next();
                    int number = residue.getNumber();

                    CMLMolecule resMol = new CMLMolecule();
                    resMol.setDictRef("md:residue");
                    resMol.setTitle(residue.getName());

                    //Append resNo
                    CMLScalar residueNumber = new CMLScalar(number);
                    residueNumber.addAttribute(new Attribute("dictRef", "md:resNumber"));
                    resMol.addScalar(residueNumber);

                    // prefix for residue atom id
                    String rprefix = "r" + number;
                    //Append atoms
                    CMLAtomArray ar = new CMLAtomArray();
                    for (int i = 0; i < residue.getAtomCount(); i++) {
                        CMLAtom cmlAtom = new CMLAtom();
                        //            			System.out.println("atom ID: "+ residue.getAtom(i).getID());
                        //            			cmlAtom.addAttribute(new Attribute("ref", residue.getAtom(i).getID()));
                        // the next thing is better, but throws an exception
                        //
                        // setRef to keep consistent usage
                        // setId to satisfy Jumbo 54. need for all atoms to have id
                        cmlAtom.setRef(residue.getAtom(i).getID());
                        cmlAtom.setId(rprefix + "_" + residue.getAtom(i).getID());
                        ar.addAtom(cmlAtom);
                    }
                    resMol.addAtomArray(ar);

                    molToCustomize.appendChild(resMol);
                }
            }

            //Chargegroups
            if (mdmol.getChargeGroups().size() > 0) {
                Iterator it = mdmol.getChargeGroups().iterator();
                while (it.hasNext()) {
                    ChargeGroup chargeGroup = (ChargeGroup) it.next();
                    int number = chargeGroup.getNumber();

                    //FIXME: persist the ChargeGroup
                    CMLMolecule cgMol = new CMLMolecule();
                    cgMol.setDictRef("md:chargeGroup");
                    // etc: add name, refs to atoms etc

                    //Append chgrpNo
                    CMLScalar cgNo = new CMLScalar(number);
                    cgNo.addAttribute(new Attribute("dictRef", "md:cgNumber"));
                    cgMol.appendChild(cgNo);

                    // prefix for residue atom id
                    String cprefix = "cg" + number;

                    //Append atoms from chargeGroup as it is an AC
                    CMLAtomArray ar = new CMLAtomArray();
                    for (int i = 0; i < chargeGroup.getAtomCount(); i++) {
                        CMLAtom cmlAtom = new CMLAtom();
                        // setRef to keep consistent usage
                        // setId to satisfy Jumbo 5.4 need for all atoms to have id
                        cmlAtom.setRef(chargeGroup.getAtom(i).getID());
                        cmlAtom.setId(cprefix + "_" + chargeGroup.getAtom(i).getID());

                        //Append switching atom?
                        if (chargeGroup.getAtom(i).equals(chargeGroup.getSwitchingAtom())) {
                            CMLScalar scalar = new CMLScalar();
                            scalar.setDictRef("md:switchingAtom");
                            cmlAtom.addScalar(scalar);
                        }
                        ar.addAtom(cmlAtom);
                    }
                    cgMol.addAtomArray(ar);

                    molToCustomize.appendChild(cgMol);
                }
            }
        }
    }
117099
public XcapResponse put(URI uri, String mimetype, String content,
			Header[] additionalRequestHeaders, Credentials credentials)
			throws IOException {

		if (log.isDebugEnabled()) {
			log.debug("put(uri=" + uri + ", mimetype=" + mimetype
					+ ", content=" + content
					+ " , additionalRequestHeaders = ( "
					+ Arrays.toString(additionalRequestHeaders) + " ) )");
		}

		final HttpPut request = new HttpPut(uri);
		setRequestEntity(request, content, mimetype);
		return execute(request, additionalRequestHeaders, credentials);

	}
84805
public static Element getMonomerElement(Monomer monomer)
      throws MonomerException {
    Element element = new Element(MONOMER_ELEMENT);

    if (null != monomer.getAlternateId()) {
      Element e = new Element(MONOMER_ID_ELEMENT);
      e.setText(monomer.getAlternateId());
      element.getChildren().add(e);
    }

    if (null != monomer.getCanSMILES()) {
      Element e = new Element(MONOMER_SMILES_ELEMENT);
      e.setText(monomer.getCanSMILES());
      element.getChildren().add(e);
    }

    if (null != monomer.getMolfile()) {
      Element e = new Element(MONOMER_MOL_FILE_ELEMENT);
      String encodedMolfile = null;
      try {
        encodedMolfile = MolfileEncoder.encode(monomer.getMolfile());
      } catch (EncoderException ex) {
        throw new MonomerException("Invalid monomer molfile");
      }
      // CDATA cdata = new CDATA(monomer.getMolfile());
      // e.setContent(cdata);
      e.setText(encodedMolfile);
      element.getChildren().add(e);
    }

    if (null != monomer.getMonomerType()) {
      Element e = new Element(MONOMER_TYPE_ELEMENT);
      e.setText(monomer.getMonomerType());
      element.getChildren().add(e);
    }

    if (null != monomer.getPolymerType()) {
      Element e = new Element(POLYMER_TYPE_ELEMENT);
      e.setText(monomer.getPolymerType());
      element.getChildren().add(e);
    }

    if (null != monomer.getNaturalAnalog()) {
      Element e = new Element(NATURAL_ANALOG_ELEMENT);
      e.setText(monomer.getNaturalAnalog());
      element.getChildren().add(e);
    }

    if (null != monomer.getName()) {
      Element e = new Element(MONOMER_NAME_ELEMENT);
      e.setText(monomer.getName());
      element.getChildren().add(e);
    }

    List<Attachment> l = monomer.getAttachmentList();
    if (null != l && l.size() > 0) {
      Element attachments = new Element(ATTACHEMENTS_ELEMENT);

      for (int i = 0; i < l.size(); i++) {
        Attachment att = l.get(i);
        Element attachment = getAttachementElement(att);
        attachments.getChildren().add(attachment);
      }
      element.getChildren().add(attachments);
    }

    return element;
  }
1304572
public void addResponse(RecordResponse response) {
        if (records == null) {
            records = new RecordResponse[1];
        }
        else {
            RecordResponse old[] = records;
            records = new RecordResponse[old.length + 1];

            System.arraycopy(old, 0, records, 0, old.length);
        }
        records[records.length - 1] = response;
    }
874608
private static void initMapNucleotidesNaturalAnalog() throws FastaFormatException, ChemistryException {
		try {
			nucleotidesNaturalAnalog = MonomerFactory.getInstance().getMonomerDB().get("RNA");
		} catch (IOException e) {
			e.printStackTrace();
			LOG.error("Nucleotides can not be initialized");
			throw new FastaFormatException(e.getMessage());
		}
	}
1309785
public Mono<Void> send(GatewayMessage response) {
    return Mono.defer(
        () ->
            outbound
                .sendObject(Mono.just(response).map(codec::encode).map(TextWebSocketFrame::new))
                .then()
                .doOnSuccessOrError((avoid, th) -> logSend(response, th)));
  }
1103231
public void addMonomer(Monomer monomer, boolean dbChanged)
      throws IOException, MonomerException {
    Map<String, Monomer> monomerMap = monomerDB.get(monomer.getPolymerType());
    String polymerType = monomer.getPolymerType();
    String alternateId = monomer.getAlternateId();
    String smilesString = monomer.getCanSMILES();

    try {
      smilesString = SMILES.getUniqueExtendedSMILES(smilesString);
    } catch (Exception e) {
      smilesString = monomer.getCanSMILES();
    }

    boolean hasSmilesString = (smilesString != null && smilesString.length() > 0);

    if (null == monomerMap) {
      monomerMap = new TreeMap<String, Monomer>(String.CASE_INSENSITIVE_ORDER);
      monomerDB.put(polymerType, monomerMap);
    }

    Monomer copyMonomer = DeepCopy.copy(monomer);

    // ensure the canonical SMILES is indexed in the monomer store
    if (hasSmilesString) {
      copyMonomer.setCanSMILES(smilesString);
    }

    boolean alreadyAdded = false;
    alreadyAdded = monomerMap.containsKey(alternateId);

    if (!alreadyAdded) {
      monomerMap.put(alternateId, copyMonomer);

      boolean alreadyInSMILESMap = hasSmilesString
          && (smilesMonomerDB.containsKey(smilesString));

      if (!alreadyInSMILESMap) {
        smilesMonomerDB.put(smilesString, copyMonomer);
      }
    }

    if (dbChanged) {
      MonomerFactory.setDBChanged(true);
    }
  }
497359
public Monomer getBaseMonomer(MonomerStore monomerStore) {

    String baseSymbol = getBaseSymbol();
    if (baseSymbol != null && !baseSymbol.equalsIgnoreCase("")) {
      try {
        Map<String, Monomer> monomers = monomerStore.getMonomers(Monomer.NUCLIEC_ACID_POLYMER_TYPE);
        Monomer m = monomers.get(baseSymbol);
        return m;
      } catch (Exception ex) {
        LOG.info("Unable to get base monomer for "
            + baseSymbol);
        return null;
      }
    } else {
      return null;
    }

  }
1004714
@Override
    public void addAtomContainer(IAtomContainer atomContainer, double multiplier) {
        if (atomContainerCount + 1 >= atomContainers.length) {
            growAtomContainerArray();
        }
        atomContainer.addListener(this);
        atomContainers[atomContainerCount] = atomContainer;
        multipliers[atomContainerCount] = multiplier;
        atomContainerCount++;
        notifyChanged();
    }
83393
public static Response put(URI uri) throws URISyntaxException, HttpException {
        return putBody(new HttpPut(uri), null, null, null, null);
    }
124867
protected Document responseToDoc(String response){
        Document doc = null;
        try {
            DocumentBuilderFactory factory = new DocumentBuilderFactoryImpl();
            DocumentBuilderFactory.newInstance();
            DocumentBuilder builder =  factory.newDocumentBuilder();
            ByteArrayInputStream input =  new ByteArrayInputStream(response.getBytes("UTF-8"));
            doc = builder.parse(input);
        } catch (ParserConfigurationException e) {
            LOG.error("ParserConfigurationException", e);
        } catch (UnsupportedEncodingException e) {
            LOG.error("UnsupportedEncodingException", e);
        } catch (IOException e) {
            LOG.error("IOException", e);
        } catch (SAXException e) {
            LOG.error("SAXException", e);
        }

        return doc;
    }
71325
public static void writeNucleotideSequence(OutputStream outputStream,
			Collection<DNASequence> dnaSequences, String seqType)
			throws Exception {
		GenericGenbankHeaderFormat<DNASequence, NucleotideCompound> genericGenbankHeaderFormat = new GenericGenbankHeaderFormat<DNASequence, NucleotideCompound>(
				seqType);
		// genericGenbankHeaderFormat.setLineSeparator(lineSep);
		GenbankWriter<DNASequence, NucleotideCompound> genbankWriter = new GenbankWriter<DNASequence, NucleotideCompound>(
				outputStream, dnaSequences, genericGenbankHeaderFormat);
		// genbankWriter.setLineSeparator(lineSep);
		genbankWriter.process();
	}
408699
public Monomer getPhosphateMonomer() {
    MonomerFactory factory = null;
    try {
      factory = MonomerFactory.getInstance();
    } catch (Exception ex) {
      Logger.getLogger(Nucleotide.class.getName()).log(Level.SEVERE, "Unable to initialize monomer factory", ex);
    }
    return getPhosphateMonomer(factory.getMonomerStore());
  }
967716
public Sequence<AminoAcidCompound> translate(
			Sequence<NucleotideCompound> dna) {
		Map<Frame, Sequence<AminoAcidCompound>> trans = multipleFrameTranslation(
				dna, Frame.ONE);
		return trans.get(Frame.ONE);
	}