Skip to content

Commit af26635

Browse files
committed
Updated keyword argument: function signature change
1 parent c5ac2e9 commit af26635

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

examples/opentree-doi-search/opentree-doi-search.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ def yield_studies(
9595
for study_dict in studies_dict["matched_studies"][study_slice]:
9696
study_id = study_dict["ot:studyId"]
9797
study_dict = pyopentree.get_study_meta(study_id)["nexml"]
98-
citation = study_dict.get('^ot:studyPublicationReference', None)
99-
doi_dict = study_dict.get('^ot:studyPublication', None)
98+
citation = study_dict.get("^ot:studyPublicationReference", None)
99+
doi_dict = study_dict.get("^ot:studyPublication", None)
100100
if doi_dict is not None:
101101
doi = doi_dict["@href"]
102102
else:
@@ -127,6 +127,16 @@ def list_studies(self,
127127
study.doi,
128128
study.citation))
129129

130+
def get_trees(self,
131+
doi,
132+
schema="nexml"):
133+
# verbose
134+
tree_ids = self.studies_find_trees(
135+
study_property="ot:studyPublication",
136+
value=doi,
137+
exact=True)
138+
print(tree_ids)
139+
130140
def main():
131141
"""
132142
Main CLI handler.
@@ -135,31 +145,34 @@ def main():
135145
parser = argparse.ArgumentParser(description=__description__)
136146
subparsers = parser.add_subparsers(help='commands', dest="subparser_name")
137147

138-
# A list command
139-
list_studies_parser = subparsers.add_parser('list-studies', help='List contents')
148+
# list studies
149+
list_studies_parser = subparsers.add_parser("list-studies", help="List contents")
140150
list_studies_parser.add_argument("--filter-for-taxon",
141151
action="append",
142152
default=False,
143-
help="Filter for studies with specific taxa")
153+
help="Filter for studies with specific taxa (multiple filters will be OR'd together).")
144154
list_studies_parser.add_argument("--list-from",
145155
type=int,
146156
default=None,
147157
help="First study to list (default: first)")
148158
list_studies_parser.add_argument("--max-studies",
149159
type=int,
150160
default=None,
151-
help="Maximum number of studies to list")
161+
help="Maximum number of studies to list.")
152162
list_studies_parser.add_argument("--as-table",
153163
action="store_true",
154164
default=False,
155-
help="Format as (tab-delimited) rows")
156-
157-
# A create command
158-
# create_parser = subparsers.add_parser('create', help='Create a directory')
159-
# create_parser.add_argument('dirname', action='store', help='New directory to create')
160-
# create_parser.add_argument('--read-only', default=False, action='store_true',
161-
# help='Set permissions to prevent writing to the directory',
162-
# )
165+
help="Format as (tab-delimited) rows.")
166+
167+
# get trees
168+
get_trees_parser = subparsers.add_parser("get-trees", help="Retrieve trees")
169+
get_trees_parser.add_argument("doi",
170+
help="DOI of the study containing the trees to retrieve")
171+
get_trees_parser.add_argument("-f", "--format",
172+
dest="schema",
173+
choices=["nexus", "newick", "nexml"],
174+
default="nexml",
175+
help="DOI of the study containing the trees to retrieve (default: '%(default)s').")
163176

164177
# # A delete command
165178
# delete_parser = subparsers.add_parser('delete', help='Remove a directory')
@@ -178,6 +191,11 @@ def main():
178191
max_studies=args.max_studies,
179192
as_table=args.as_table,
180193
)
194+
elif args.subparser_name == "get-trees":
195+
# http://dx.doi.org/10.1111/j.1365-294X.2012.05606.x
196+
ots.get_trees(
197+
doi=args.doi,
198+
schema=args.schema)
181199
else:
182200
parser.print_usage(sys.stderr)
183201
sys.exit(1)

pyopentree/opentreeservice.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ def studies_find_studies(
791791

792792
def studies_find_trees(
793793
self,
794-
study_property,
794+
tree_property,
795795
value,
796796
exact=False,
797797
verbose=False):
@@ -807,7 +807,7 @@ def studies_find_trees(
807807
808808
Parameters
809809
----------
810-
study_property : string
810+
tree_property : string
811811
The property to be searched on. A list of searchable properties is
812812
available from the `studies_properties` function.
813813
value : string
@@ -831,7 +831,7 @@ def studies_find_trees(
831831
"""
832832
payload = {
833833
"exact" : exact,
834-
"property": study_property,
834+
"property": tree_property,
835835
"value": value, }
836836
result = self.request(
837837
'/studies/find_trees',

0 commit comments

Comments
 (0)