Skip to content

Commit

Permalink
Merge pull request #8 from RNABioInfo/ID-type-update
Browse files Browse the repository at this point in the history
ID type
  • Loading branch information
Richard A. Schäfer authored May 16, 2023
2 parents e1e0683 + cc3514c commit a8ef923
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
5 changes: 0 additions & 5 deletions impl/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ int main(int argc, char** argv) {
rapidjson::Document s;
s.Parse(sch.c_str());
schema_validator(&d, &s);
rapidjson::Document f=get_interaction(&d,"partner=Hfq,Bbh,micF; type=basepairing");
cout << f.Size() << endl;
f[0]["ID"]=12;
schema_validator(&f, &s);
write_json(&f,"/homes/brauerei2/guillaume/Documents/RNA/json/rna-interaction-specification/examples/" , "test");
}
cout << endl << "The End !" << endl;
return 0;
Expand Down
14 changes: 7 additions & 7 deletions impl/cpp/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ std::vector<std::vector<std::string>> read_query(std::string q)
//to use one of the methods below, better make sure first that the json document given as input is valid with regard to the schema (with schema_validator()). Things will probably not work otherwise.


int find_interaction(rapidjson::Document *doc, int ref)
int find_interaction(rapidjson::Document *doc, std::string ref)
//searches an interaction from its ID, returns its position in the list of partners (or -1 if the partner is not found).
{
int s=(*doc).Size();
int i=0;
int c=0;
while(c==0 && i<s)
{
if(((*doc)[i]["ID"]).GetInt()==ref)
if(((*doc)[i]["ID"]).GetString()==ref)
{
c=1;
}
Expand All @@ -95,7 +95,7 @@ std::vector<int> subset_interaction(rapidjson::Document *doc, std::string q)
for(int j=0; j<qr.size(); j++)
{
nm=qr[j][0];
if (std::string(nm)=="ID")
/*if (std::string(nm)=="ID")
{
for(int k=1; k<(qr[j]).size(); k++)
{
Expand All @@ -108,8 +108,8 @@ std::vector<int> subset_interaction(rapidjson::Document *doc, std::string q)
}
}
}
}
else if (std::string(nm)=="class" || std::string(nm)=="type")
}*/
if (std::string(nm)=="ID" || std::string(nm)=="class" || std::string(nm)=="type")
{
for(int k=1; k<(qr[j]).size(); k++)
{
Expand Down Expand Up @@ -193,7 +193,7 @@ rapidjson::Document get_interaction(rapidjson::Document *doc, std::string q)
void add_interaction(rapidjson::Document *doc, rapidjson::Value v)
//adds a new interaction, but first checks that there is not already an interaction with same ID. Does not add the new interaction if this is the case. And does not check that the updated document remains valid with regards to the schema
{
int ref=(v["ID"]).GetInt();
std::string ref=(v["ID"]).GetString();
int i=find_interaction(doc, ref);
if(i==-1)
{
Expand All @@ -206,7 +206,7 @@ void add_interaction(rapidjson::Document *doc, rapidjson::Value v)
}
}

void remove_interaction(rapidjson::Document *doc, int ref)
void remove_interaction(rapidjson::Document *doc, std::string ref)
//as name says
{
int i=find_interaction(doc, ref);
Expand Down
4 changes: 2 additions & 2 deletions impl/cpp/update.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#include "include/rapidjson/stringbuffer.h"
#include "include/rapidjson/prettywriter.h"

int find_interaction(rapidjson::Document *doc, int ref);
int find_interaction(rapidjson::Document *doc, std::string ref);

std::vector<int> subset_interaction(rapidjson::Document *doc, std::string q);

rapidjson::Document get_interaction(rapidjson::Document *doc, std::string q);

void add_interaction(rapidjson::Document *doc, rapidjson::Value v);

void remove_interaction(rapidjson::Document *doc, int ref);
void remove_interaction(rapidjson::Document *doc, std::string ref);

#endif /* UPDATE_H_ */

0 comments on commit a8ef923

Please sign in to comment.