Skip to content

Commit

Permalink
delete-set
Browse files Browse the repository at this point in the history
mtholder committed May 30, 2024
1 parent 10d935e commit 0a19c48
Showing 5 changed files with 66 additions and 0 deletions.
26 changes: 26 additions & 0 deletions expected/taxonomy-patcher/delete-set/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
loading taxonomy
loaded
1 amendments to be processed.
1/1 amendments applied.
version.txt
0.0draft0
taxonomy.tsv
uid | parent_uid | name | rank | sourceinfo | uniqname | flags |
1000000 | | Exampleroot | no rank | ncbi:10239,gbif:8 | | |
999999 | 1000000 | Nototuexample | no rank | | | not_otu |
1001 | 1000000 | Amaryllidaceae | no rank | | | |
100 | 1001 | Amaryllis | no rank | | | barren |
200 | 1001 | Bamaryllis | no rank | | | |
11 | 200 | Bamaryllis belladonna | no rank | ncbi:1,gbif:3 | | |
12 | 200 | Bamaryllis major | no rank | ncbi:2,irmng:5 | | |
13 | 200 | Bamarylis minor | no rank | | | |
300 | 1001 | Amaryllis Amaryllis | no rank | | Amaryllis (subgenus Amaryllis) | |
21 | 300 | Amaryllis Amaryllis major | no rank | | | |
22 | 300 | Amaryllis Amaryllis minor | no rank | | | |
23 | 300 | Amaryllis somelodd | no rank | | | |
synonyms.tsv
name | uid | type | uniqname | sourceinfo |
Camaryllis major | 21 | | | |
forwards.tsv
id replacement
2002 1001
5 changes: 5 additions & 0 deletions expected/taxonomy-patcher/taxonomy-patcher.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[
{
"invocation" : ["otc-taxonomy-patcher", "--amend-status-to-stdout", "--write-to-stdout", "--edits", "<INFILELIST>"],
"infile_list": ["delete-set.json", "patch-taxonomy"],
"expected": "delete-set"
},
{
"invocation" : ["otc-taxonomy-patcher", "--amend-status-to-stdout", "--write-to-stdout", "--edits", "<INFILELIST>"],
"infile_list": ["append-set.json", "patch-taxonomy"],
10 changes: 10 additions & 0 deletions otc/taxonomy/patching.cpp
Original file line number Diff line number Diff line change
@@ -293,6 +293,16 @@ bool_str_t PatchableTaxonomy::delete_taxon(OttId ott_id) {
return bool_str_t{true, ""};
}

bool_str_t PatchableTaxonomy::delete_id_set(const OttIdSet & ott_id_set) {
for (auto oid : ott_id_set) {
auto sret = delete_taxon(oid);
if (!sret.first) {
return sret;
}
}
return bool_str_t{true, ""};
}

bool_str_t PatchableTaxonomy::sink_taxon(OttId jr_oid, OttId sr_id) {
auto & tree = this->get_mutable_tax_tree();
auto & rt_data = tree.get_data();
1 change: 1 addition & 0 deletions otc/taxonomy/patching.h
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@ class PatchableTaxonomy: public RichTaxonomy {
const std::string & sourceinfo,
const tax_flags & flags);
bool_str_t delete_taxon(OttId oid) ;
bool_str_t delete_id_set(const OttIdSet & ott_id_set);
bool_str_t add_forward(OttId former_id, OttId redirect_to_id);
bool_str_t delete_forward(OttId former_id, OttId redirect_to_id);
bool_str_t add_synonym(const std::string & name, OttId ott_id, const std::string & sourceinfo);
24 changes: 24 additions & 0 deletions tools/taxonomy-patcher.cpp
Original file line number Diff line number Diff line change
@@ -312,6 +312,24 @@ class TaxaAppendSetAmendment: public TaxonPropAmendment {
OttIdSet ott_ids;
};

class TaxaDeleteSetAmendment: public TaxonomyAmendment {
public:
TaxaDeleteSetAmendment(const json & taxa_obj)
:TaxonomyAmendment() {
this->ott_ids = get_unsigned_set_property(taxa_obj, "ott_ids", true).second;
}

virtual ~TaxaDeleteSetAmendment(){
}

virtual std::pair<bool, std::string> patch(PatchableTaxonomy &t) {
return t.delete_id_set(ott_ids);
}

protected:
OttIdSet ott_ids;
};

class TaxonEditAmendment: public BaseTaxonAmendment {
public:
TaxonEditAmendment(const json & taxon_obj)
@@ -458,6 +476,12 @@ TaxonomyAmendmentPtr parse_taxon_amendment_obj(const json & edit_obj) {
return std::make_shared<TaxaAppendSetAmendment>(*(taxon_j.second));
}
throw OTCError() << "Expecting edit action to contain taxa object.";
} else if (action == "delete-set") {
auto taxon_j = get_object_property(edit_obj, "taxa", false);
if (taxon_j.first) {
return std::make_shared<TaxaDeleteSetAmendment>(*(taxon_j.second));
}
throw OTCError() << "Expecting edit action to contain taxa object.";
} else {
throw OTCError() << "Taxon amendment with action \"" << action << "\" not implemented.";
}

0 comments on commit 0a19c48

Please sign in to comment.