seer-pas-sdk 0.3.2__py3-none-any.whl → 0.3.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
seer_pas_sdk/core/sdk.py CHANGED
@@ -515,6 +515,8 @@ class SeerSDK:
515
515
  f"Failed to fetch sample data for plate ID: {plate_id}."
516
516
  )
517
517
  res = samples.json()["data"]
518
+ if not res:
519
+ return [] if not as_df else dict_to_df(res)
518
520
  res_df = dict_to_df(res)
519
521
 
520
522
  # API returns empty strings if not a control, replace with None for filtering purposes
@@ -1195,7 +1197,9 @@ class SeerSDK:
1195
1197
 
1196
1198
  return peptide_data
1197
1199
 
1198
- def list_search_result_files(self, analysis_id: str):
1200
+ def list_search_result_files(
1201
+ self, analysis_id: str, folder: str = None, recursive: bool = False
1202
+ ):
1199
1203
  """
1200
1204
  Given an analysis id, this function returns a list of files associated with the analysis.
1201
1205
 
@@ -1204,6 +1208,12 @@ class SeerSDK:
1204
1208
  analysis_id : str
1205
1209
  ID of the analysis for which the data is to be fetched.
1206
1210
 
1211
+ folder : str, optional
1212
+ Root folder key to list search result files from, defaulted to None.
1213
+
1214
+ recursive : bool, optional
1215
+ Whether to list files recursively from subfolders, defaulted to False.
1216
+
1207
1217
  Returns
1208
1218
  -------
1209
1219
  files: list[str]
@@ -1218,9 +1228,15 @@ class SeerSDK:
1218
1228
 
1219
1229
  if analysis_metadata.get("status") in ["Failed", None]:
1220
1230
  raise ValueError("Cannot find files for a failed analysis.")
1231
+
1232
+ params = {"all": "true"}
1233
+ if folder:
1234
+ params["folderKey"] = folder
1235
+
1221
1236
  with self._get_auth_session() as s:
1222
1237
  response = s.get(
1223
- f"{self._auth.url}api/v2/analysisResultFiles/{analysis_id}"
1238
+ f"{self._auth.url}api/v2/analysisResultFiles/{analysis_id}",
1239
+ params=params,
1224
1240
  )
1225
1241
  if response.status_code != 200:
1226
1242
  raise ServerError(
@@ -1228,8 +1244,25 @@ class SeerSDK:
1228
1244
  )
1229
1245
  response = response.json()
1230
1246
  files = []
1247
+ folders = []
1231
1248
  for row in response["data"]:
1232
- files.append(row["filename"])
1249
+ if folder:
1250
+ row["filename"] = f"{folder}/{row['filename']}"
1251
+ if row["isFolder"]:
1252
+ if recursive:
1253
+ folders.append(row["filename"])
1254
+ else:
1255
+ row["filename"] += "/"
1256
+ files.append(row["filename"])
1257
+ else:
1258
+ files.append(row["filename"])
1259
+
1260
+ if recursive:
1261
+ for subfolder in folders:
1262
+ files += self.list_search_result_files(
1263
+ analysis_id, folder=subfolder, recursive=recursive
1264
+ )
1265
+
1233
1266
  return files
1234
1267
 
1235
1268
  def get_search_result(
@@ -1737,7 +1770,32 @@ class SeerSDK:
1737
1770
  raise ServerError(
1738
1771
  "Could not fetch protein results table. Please verify that your analysis completed."
1739
1772
  )
1740
- return dict_to_df(res.json()) if as_df else res.json()
1773
+ res = dict_to_df(res.json())
1774
+ res.rename(
1775
+ columns={
1776
+ "proteinId": "uniprot_id",
1777
+ "n": "n_samples",
1778
+ "bp": "biological_process",
1779
+ "mf": "molecular_function",
1780
+ "cc": "cellular_component",
1781
+ "nFrac": "fraction_samples",
1782
+ "proteinNames": "protein_name",
1783
+ "geneName": "gene_name",
1784
+ },
1785
+ inplace=True,
1786
+ )
1787
+
1788
+ res.drop(
1789
+ columns=[
1790
+ "median_undefined",
1791
+ "n_undefined",
1792
+ "n_null",
1793
+ "median_null",
1794
+ ],
1795
+ inplace=True,
1796
+ errors="ignore",
1797
+ )
1798
+ return res if as_df else res.to_dict(orient="records")
1741
1799
 
1742
1800
  def get_peptide_results_table(
1743
1801
  self,
@@ -1779,9 +1837,28 @@ class SeerSDK:
1779
1837
  )
1780
1838
  if res.status_code != 200:
1781
1839
  raise ServerError(
1782
- "Could not fetch protein results table. Please verify that your analysis completed."
1840
+ "Could not fetch peptide results table. Please verify that your analysis completed."
1783
1841
  )
1784
- return dict_to_df(res.json()) if as_df else res.json()
1842
+ res = dict_to_df(res.json())
1843
+ res.rename(
1844
+ columns={
1845
+ "proteinId": "uniprot_id",
1846
+ "n": "n_samples",
1847
+ "bp": "biological_process",
1848
+ "mf": "molecular_function",
1849
+ "cc": "cellular_component",
1850
+ "nFrac": "fraction_samples",
1851
+ "proteinNames": "protein_name",
1852
+ "geneName": "gene_name",
1853
+ },
1854
+ inplace=True,
1855
+ )
1856
+
1857
+ res.drop(columns=["n_undefined"], inplace=True, errors="ignore")
1858
+ res.drop(
1859
+ columns=["median_undefined"], inplace=True, errors="ignore"
1860
+ )
1861
+ return res if as_df else res.to_dict(orient="records")
1785
1862
 
1786
1863
  def list_ms_data_files(self, folder="", space=None):
1787
1864
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: seer-pas-sdk
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: SDK for Seer Proteograph Analysis Suite (PAS)
5
5
  Author-email: Ryan Sun <rsun@seer.bio>
6
6
  License:
@@ -5,14 +5,14 @@ seer_pas_sdk/common/__init__.py,sha256=jA5qm-t9x3qXMp5Q6v7vV2kZdLw32-lnbtf0fPY4l
5
5
  seer_pas_sdk/common/errors.py,sha256=4HFORWnaQQCMXRE8kwdsJWvQRB_3KFEZ7yMb391e4gA,142
6
6
  seer_pas_sdk/common/groupanalysis.py,sha256=DxB-gbQfYzl7p9MTYWDIqghcH-IeakzdYdrRZrlIHek,1730
7
7
  seer_pas_sdk/core/__init__.py,sha256=rxbKgg-Qe24OaxX2zyHHYPYgDCTEKE_-41bB2wvpvL4,25
8
- seer_pas_sdk/core/sdk.py,sha256=P8t_QNS8YmwBhdTtkbW02RhzN0Mb2u9F92JAOqvvmUg,105847
8
+ seer_pas_sdk/core/sdk.py,sha256=NHhUCxuhea_KhCd3FLpojCwkOZDIZuvjU7K52h695KY,108508
9
9
  seer_pas_sdk/core/unsupported.py,sha256=XAPZ3tidqjnsgftf3NUdTGIzvnsjHy0e_eGRCAo6GPo,59890
10
10
  seer_pas_sdk/objects/__init__.py,sha256=HJLS6sOr7DfzdI14fv5dWcITEj5QQsKcdfED3YNvUrY,107
11
11
  seer_pas_sdk/objects/groupanalysis.py,sha256=x3D_5NmYBoPDilNCQqUoCFARIfIeUq4FBY3_N6u8tfM,994
12
12
  seer_pas_sdk/objects/platemap.py,sha256=8IvJPAecs_e_FyqibzhCw-O4zjCFnf-zMUp_5krTEsg,5864
13
13
  seer_pas_sdk/objects/volcanoplot.py,sha256=tKuCWDIdoO8FLJlhpXhuwHn0aMYnvudTugxAslDXyGs,9357
14
- seer_pas_sdk-0.3.2.dist-info/licenses/LICENSE.txt,sha256=DVQuDIgE45qn836wDaWnYhSdxoLXgpRRKH4RuTjpRZQ,10174
15
- seer_pas_sdk-0.3.2.dist-info/METADATA,sha256=WZECPlPd8k2mEgEznlhfXqYbbMHbdOZn8q2D51B4blo,13448
16
- seer_pas_sdk-0.3.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
- seer_pas_sdk-0.3.2.dist-info/top_level.txt,sha256=-2kZ-KFMGtXwr8H1O5llMKlcJ8gRKohEmrIvazXB61s,13
18
- seer_pas_sdk-0.3.2.dist-info/RECORD,,
14
+ seer_pas_sdk-0.3.4.dist-info/licenses/LICENSE.txt,sha256=DVQuDIgE45qn836wDaWnYhSdxoLXgpRRKH4RuTjpRZQ,10174
15
+ seer_pas_sdk-0.3.4.dist-info/METADATA,sha256=QuSAislG3NV9SE66n1xNF4Kf7Nk704jSEPCyefSoP_E,13448
16
+ seer_pas_sdk-0.3.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
+ seer_pas_sdk-0.3.4.dist-info/top_level.txt,sha256=-2kZ-KFMGtXwr8H1O5llMKlcJ8gRKohEmrIvazXB61s,13
18
+ seer_pas_sdk-0.3.4.dist-info/RECORD,,