Skip to content

Commit

Permalink
start of impl
Browse files Browse the repository at this point in the history
  • Loading branch information
mtholder committed May 4, 2024
1 parent 8fc9973 commit 03aec34
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 1 deletion.
1 change: 1 addition & 0 deletions data/patch-taxonomy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pickle
3 changes: 3 additions & 0 deletions data/patch-taxonomy/about.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"inputs": []
}
1 change: 1 addition & 0 deletions data/patch-taxonomy/conflicts.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions data/patch-taxonomy/deprecated.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions data/patch-taxonomy/forwards.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id replacement
2002 1001
2 changes: 2 additions & 0 deletions data/patch-taxonomy/synonyms.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name | uid | type | uniqname | sourceinfo |
Camaryllis major | 21 | synonym | | |
16 changes: 16 additions & 0 deletions data/patch-taxonomy/taxonomy.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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 | | | |
200 | 1001 | Bamaryllis | no rank | | | |
300 | 1001 | Amaryllis Amaryllis | no rank | | Amaryllis (subgenus Amaryllis) | |
1 | 100 | Amaryllis belladonna | no rank | | | |
2 | 100 | Amaryllis minor | no rank | | | hybrid,edited |
3 | 100 | Amaryllis someλodd | 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 | | | |
21 | 300 | Amaryllis Amaryllis major | no rank | | | |
22 | 300 | Amaryllis Amaryllis minor | no rank | | | |
23 | 300 | Amaryllis somelodd | no rank | | | |
2 changes: 2 additions & 0 deletions data/patch-taxonomy/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0.0draft0

9 changes: 9 additions & 0 deletions data/sink.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"action": "sink",
"taxon": {
"ott_id_to_be_jr_syn": 12,
"ott_id_of_sr_syn": 11
}
}
]
31 changes: 31 additions & 0 deletions expected/taxonomy-patcher/sink/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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 | | | |
1 | 100 | Amaryllis belladonna | no rank | | | |
2 | 100 | Amaryllis minor | no rank | | | edited,hybrid |
3 | 100 | Amaryllis someλodd | no rank | | | |
200 | 1001 | Bamaryllis | no rank | | | |
11 | 200 | Bamaryllis belladonna | no rank | ncbi:1,irmng:5,gbif:3 | | |
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 | | | |
Bamaryllis major | 11 | | | |
forwards.tsv
id replacement
6520249 100
2002 1001
12 11
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": ["sink.json", "patch-taxonomy"],
"expected": "sink"
},
{
"invocation" : ["otc-taxonomy-patcher", "--amend-status-to-stdout", "--write-to-stdout", "--edits", "<INFILELIST>"],
"infile_list": ["unmarked-homonym.json", "tnrs-taxonomy"],
Expand Down
29 changes: 28 additions & 1 deletion tools/taxonomy-patcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class BaseTaxonAmendment: public TaxonomyAmendment {
class TaxonAdditionAmendment: public BaseTaxonAmendment {
public:
TaxonAdditionAmendment(const json & taxon_obj)
:BaseTaxonAmendment(taxon_obj,true) {
:BaseTaxonAmendment(taxon_obj, true) {
}

virtual ~TaxonAdditionAmendment(){
Expand All @@ -235,6 +235,27 @@ class TaxonAdditionAmendment: public BaseTaxonAmendment {
}
};

class TaxonSinkAmendment: public TaxonomyAmendment {
public:
TaxonSinkAmendment(const json & taxon_obj)
:TaxonomyAmendment() {
this->ott_id_to_be_jr_syn = get_unsigned_property(taxon_obj, "ott_id_to_be_jr_syn", true).second;
this->ott_id_of_sr_syn = get_unsigned_property(taxon_obj, "ott_id_of_sr_syn", true).second;

}

virtual ~TaxonSinkAmendment(){
}

virtual std::pair<bool, std::string> patch(PatchableTaxonomy &t) {
throw OTCError("Sink action not implemented yet") ;
}

protected:
OttId ott_id_to_be_jr_syn;
OttId ott_id_of_sr_syn;
};

class TaxonEditAmendment: public BaseTaxonAmendment {
public:
TaxonEditAmendment(const json & taxon_obj)
Expand Down Expand Up @@ -369,6 +390,12 @@ TaxonomyAmendmentPtr parse_taxon_amendment_obj(const json & edit_obj) {
return std::make_shared<TaxonEditAmendment>(*(taxon_j.second));
}
throw OTCError() << "Expecting edit action to contain taxon object.";
} else if (action == "sink") {
auto taxon_j = get_object_property(edit_obj, "taxon", false);
if (taxon_j.first) {
return std::make_shared<TaxonSinkAmendment>(*(taxon_j.second));
}
throw OTCError() << "Expecting edit action to contain taxon object.";
} else {
throw OTCError() << "Taxon amendment with action \"" << action << "\" not implemented.";
}
Expand Down

0 comments on commit 03aec34

Please sign in to comment.