7#ifndef _CPUBCHEMSEARCHWIDGET_H
8#define _CPUBCHEMSEARCHWIDGET_H
11#include <QDesktopServices>
14#include <QNetworkAccessManager>
15#include <QNetworkRequest>
16#include <QNetworkReply>
17#include <QtConcurrent>
18#include <QApplication>
76 void store(ofstream& os);
83 void load(ifstream& is);
89 QTextBrowser* textbrowser;
123 string url =
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/fastformula/";
127 QNetworkAccessManager networkmanager;
128 QNetworkRequest request(QUrl(url.c_str()));
129 QNetworkReply *response = networkmanager.get(request);
132 QObject::connect(response, SIGNAL(finished()), &loop, SLOT(quit()));
135 string cids = response->readAll().toStdString();
137 stringstream errorstream;
139 errorstream <<
"@ERROR" << endl;
140 errorstream <<
"URL: " << url << endl;
141 errorstream <<
"ERROR: " << response->errorString().toStdString() << endl;
145 response->deleteLater();
148 return errorstream.str();
162 if (cids.find(
"Status:") == string::npos) {
163 istringstream inputstream(cids);
165 while (getline(inputstream, line)) {
166 if (!reducedcids.empty()) {
181 if (cids.find(
"Status:") == string::npos) {
182 istringstream inputstream(cids);
184 while (getline(inputstream, line)) {
185 cidsvector.push_back(line);
198 if (cids.find(
"Status:") == string::npos) {
199 istringstream inputstream(cids);
201 while (getline(inputstream, line)) {
206 if (cids.find(
"Status: 404") == string::npos) {
208 cout << cids << endl << endl;
246 string url =
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/";
250 url +=
"synonyms/txt";
254 if (url.size() > 4000) {
255 return "Status: 414";
259 QNetworkAccessManager networkmanager;
260 QNetworkRequest request(QUrl(url.c_str()));
261 QNetworkReply *response;
264 QString body =
"cid=";
266 request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
267 response = networkmanager.post(request, body.toUtf8());
270 response = networkmanager.get(request);
274 QObject::connect(response, SIGNAL(finished()), &loop, SLOT(quit()));
277 string names = response->readAll().toStdString();
279 stringstream errorstream;
281 errorstream <<
"@ERROR" << endl;
282 errorstream <<
"URL: " << url << endl;
283 errorstream <<
"ERROR: " << response->errorString().toStdString() << endl;
287 response->deleteLater();
290 return errorstream.str();
303 if (names.find(
"Status:") == string::npos) {
304 istringstream inputstream(names);
306 while (getline(inputstream, line)) {
307 if (line.find(
"SCHEMBL") == string::npos) {
308 reducednames.insert(line);
311 if (reducednames.empty()) {
312 reducednames.insert(
"This item has only SCHEMBL name(s).");
316 if (names.find(
"Status: 404") == string::npos) {
318 cout << names << endl << endl;
The functor used to get the CIDs of compounds with the same formula.
Definition: cPubChemSearchWidget.h:109
int getNumberOfCIDs(string &cids)
Get the number of compounds with the same formula.
Definition: cPubChemSearchWidget.h:196
void attachVectorOfCIDs(string &cids, vector< string > &cidsvector)
Attach a vector of CIDs.
Definition: cPubChemSearchWidget.h:180
void getCommaSeparatedCIDs(string &cids, string &reducedcids)
Get a list of CIDs separated by comma.
Definition: cPubChemSearchWidget.h:160
string getCIDList(const string &compound)
Get the list of CIDs.
Definition: cPubChemSearchWidget.h:122
string result_type
result_type
Definition: cPubChemSearchWidget.h:114
string operator()(const string &compound)
Overloaded operator ().
Definition: cPubChemSearchWidget.h:221
The functor used to get the names of compounds from CID.
Definition: cPubChemSearchWidget.h:230
string getNameList(const string &cid)
Get the list of names.
Definition: cPubChemSearchWidget.h:243
void getReducedNames(string &names, set< string > &reducednames)
Get the reduded list of names.
Definition: cPubChemSearchWidget.h:302
string result_type
result_type
Definition: cPubChemSearchWidget.h:235
string operator()(const string &cid)
Overloaded operator ().
Definition: cPubChemSearchWidget.h:329
An auxiliary row info structure.
Definition: cPubChemSearchWidget.h:341
double theoreticalmz
Theoretical m/z.
Definition: cPubChemSearchWidget.h:352
double experimentalint
Experimental intensity.
Definition: cPubChemSearchWidget.h:358
int id
Identification ID.
Definition: cPubChemSearchWidget.h:346
string iontype
Ion type.
Definition: cPubChemSearchWidget.h:364
Auxiliary funtions and structures.