diff --git a/expected/taxonomy-patcher/delete-set/output b/expected/taxonomy-patcher/delete-set/output new file mode 100644 index 00000000..b18da3ad --- /dev/null +++ b/expected/taxonomy-patcher/delete-set/output @@ -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 diff --git a/expected/taxonomy-patcher/taxonomy-patcher.json b/expected/taxonomy-patcher/taxonomy-patcher.json index fb7bdd31..795506df 100644 --- a/expected/taxonomy-patcher/taxonomy-patcher.json +++ b/expected/taxonomy-patcher/taxonomy-patcher.json @@ -1,4 +1,9 @@ [ + { + "invocation" : ["otc-taxonomy-patcher", "--amend-status-to-stdout", "--write-to-stdout", "--edits", ""], + "infile_list": ["delete-set.json", "patch-taxonomy"], + "expected": "delete-set" + }, { "invocation" : ["otc-taxonomy-patcher", "--amend-status-to-stdout", "--write-to-stdout", "--edits", ""], "infile_list": ["append-set.json", "patch-taxonomy"], diff --git a/otc/taxonomy/patching.cpp b/otc/taxonomy/patching.cpp index 30526766..d95ca09b 100644 --- a/otc/taxonomy/patching.cpp +++ b/otc/taxonomy/patching.cpp @@ -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(); diff --git a/otc/taxonomy/patching.h b/otc/taxonomy/patching.h index 2898cdf4..32a3e635 100644 --- a/otc/taxonomy/patching.h +++ b/otc/taxonomy/patching.h @@ -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); diff --git a/tools/taxonomy-patcher.cpp b/tools/taxonomy-patcher.cpp index 25a7c2a4..504337a5 100644 --- a/tools/taxonomy-patcher.cpp +++ b/tools/taxonomy-patcher.cpp @@ -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 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(*(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(*(taxon_j.second)); + } + throw OTCError() << "Expecting edit action to contain taxa object."; } else { throw OTCError() << "Taxon amendment with action \"" << action << "\" not implemented."; }