@@ -157,12 +157,9 @@ def get_phenotypes(
157157 playlist : int = None ,
158158 updated_at : str = None ,
159159 result_types : List [str ] = [],
160- return_type = "list"
161160 ) -> List [Phenotype ]:
162161 """
163- A list of all the phenotypes in the current project.
164- The API paginates results on the `limit` parameter,
165- this method handles the pagination transparently to fetch all results.
162+ Get all phenotypes in the current project as a list of Phenotypes.
166163
167164 :param all_tags: Only fetch phenotypes that have all tags in the given list of tags
168165 :param any_tags: Fetch phenotypes that have any of the tags in the given list of tags
@@ -173,8 +170,139 @@ def get_phenotypes(
173170 :param playlist: Fetch a specific playlist of phenotypes by the playlist id
174171 :param updated_at: Only fetch phenotypes that match the given dates. Example: >=2017-04-01 ┃ <=2012-07-04 ┃ 2016-04-30..2016-07-04
175172 :param result_types: Only fetch phenotypes in the given list of result types
176- :param return_type: list (default) to return a python list of phenotypes, dataframe to return a pandas dataframe of phenotypes
177- :return: List of phenotypes unles return_type is 'dataframe' then return a pandas dataframe
173+ :return: List of Phenotype
174+ :raises: `PhenotypeError` if the project does not exist
175+ :raises: ServerError
176+ """
177+ combined_data = self ._get_phenotypes (
178+ all_tags ,
179+ any_tags ,
180+ categories ,
181+ limit ,
182+ states ,
183+ search ,
184+ playlist ,
185+ updated_at ,
186+ result_types
187+ )
188+ phenotypes = []
189+ for item in combined_data :
190+ phenotypes .append (Phenotype (self .session , item ))
191+ return phenotypes
192+
193+ def get_phenotypes_matrix (
194+ self ,
195+ all_tags : List [str ] = [],
196+ any_tags : List [str ] = [],
197+ categories : List [str ] = [],
198+ limit : int = 100 ,
199+ states : List [str ] = [],
200+ search : str = None ,
201+ playlist : int = None ,
202+ updated_at : str = None ,
203+ result_types : List [str ] = [],
204+ ) -> List [Phenotype ]:
205+ """
206+ Get all phenotypes in the current project as a PhenotypeMatrix.
207+
208+ :param all_tags: Only fetch phenotypes that have all tags in the given list of tags
209+ :param any_tags: Fetch phenotypes that have any of the tags in the given list of tags
210+ :param categories: Only fetch phenotypes in the given list of categories
211+ :param limit: Maximum number of results (default: 100)
212+ :param states: Only fetch phenotypes in the given list of states
213+ :param search: String of keywords to search for in phenotypes, such as name, categories and tags
214+ :param playlist: Fetch a specific playlist of phenotypes by the playlist id
215+ :param updated_at: Only fetch phenotypes that match the given dates. Example: >=2017-04-01 ┃ <=2012-07-04 ┃ 2016-04-30..2016-07-04
216+ :param result_types: Only fetch phenotypes in the given list of result types
217+ :return: Phenotypes as PhenotypeMatrix
218+ :raises: `PhenotypeError` if the project does not exist
219+ :raises: ServerError
220+ """
221+ combined_data = self ._get_phenotypes (
222+ all_tags ,
223+ any_tags ,
224+ categories ,
225+ limit ,
226+ states ,
227+ search ,
228+ playlist ,
229+ updated_at ,
230+ result_types
231+ )
232+ matrix = PhenotypeMatrix (self )
233+ for item in combined_data :
234+ matrix .add_phenotype (Phenotype (self .session , item ))
235+ return matrix
236+
237+ def get_phenotypes_dataframe (
238+ self ,
239+ all_tags : List [str ] = [],
240+ any_tags : List [str ] = [],
241+ categories : List [str ] = [],
242+ limit : int = 100 ,
243+ states : List [str ] = [],
244+ search : str = None ,
245+ playlist : int = None ,
246+ updated_at : str = None ,
247+ result_types : List [str ] = []
248+ ) -> List [Phenotype ]:
249+ """
250+ Get all phenotypes in the current project as a pandas DataFrame.
251+
252+ :param all_tags: Only fetch phenotypes that have all tags in the given list of tags
253+ :param any_tags: Fetch phenotypes that have any of the tags in the given list of tags
254+ :param categories: Only fetch phenotypes in the given list of categories
255+ :param limit: Maximum number of results (default: 100)
256+ :param states: Only fetch phenotypes in the given list of states
257+ :param search: String of keywords to search for in phenotypes, such as name, categories and tags
258+ :param playlist: Fetch a specific playlist of phenotypes by the playlist id
259+ :param updated_at: Only fetch phenotypes that match the given dates. Example: >=2017-04-01 ┃ <=2012-07-04 ┃ 2016-04-30..2016-07-04
260+ :param result_types: Only fetch phenotypes in the given list of result types
261+ :return: Phenotypes as pandas dataframe
262+ :raises: `PhenotypeError` if the project does not exist
263+ :raises: ServerError
264+ """
265+ combined_data = self ._get_phenotypes (
266+ all_tags ,
267+ any_tags ,
268+ categories ,
269+ limit ,
270+ states ,
271+ search ,
272+ playlist ,
273+ updated_at ,
274+ result_types
275+ )
276+ import pandas
277+ dataframe = pandas .DataFrame (combined_data )
278+ return dataframe
279+
280+ def _get_phenotypes (
281+ self ,
282+ all_tags : List [str ] = [],
283+ any_tags : List [str ] = [],
284+ categories : List [str ] = [],
285+ limit : int = 100 ,
286+ states : List [str ] = [],
287+ search : str = None ,
288+ playlist : int = None ,
289+ updated_at : str = None ,
290+ result_types : List [str ] = []
291+ ) -> List [Phenotype ]:
292+ """
293+ Internal method to be called by `get_phenotypes`, `get_phenotypes_matrix` and `get_phenotypes_dataframe`
294+ See documentation of those methods for more details
295+
296+ :param all_tags: Only fetch phenotypes that have all tags in the given list of tags
297+ :param any_tags: Fetch phenotypes that have any of the tags in the given list of tags
298+ :param categories: Only fetch phenotypes in the given list of categories
299+ :param limit: Maximum number of results (default: 100)
300+ :param states: Only fetch phenotypes in the given list of states
301+ :param search: String of keywords to search for in phenotypes, such as name, categories and tags
302+ :param playlist: Fetch a specific playlist of phenotypes by the playlist id
303+ :param updated_at: Only fetch phenotypes that match the given dates. Example: >=2017-04-01 ┃ <=2012-07-04 ┃ 2016-04-30..2016-07-04
304+ :param result_types: Only fetch phenotypes in the given list of result types
305+ :return: List of phenotypes
178306 :raises: `PhenotypeError` if the project does not exist
179307 :raises: ServerError
180308 """
@@ -224,15 +352,7 @@ def do_get(offset=0):
224352 return data
225353
226354 combined_data = _get_paginated_results (do_get , limit )
227-
228- phenotypes = []
229- if return_type == "dataframe" :
230- import pandas
231- phenotypes = pandas .DataFrame (combined_data )
232- else :
233- for item in combined_data :
234- phenotypes .append (Phenotype (self .session , item ))
235- return phenotypes
355+ return combined_data
236356
237357 def get_phenotype (self , name : str ) -> Phenotype :
238358 """
0 commit comments