Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 Simplify read function and datasets calls #15

Merged
merged 6 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/examples/YYYY-MM-DD-task-slug.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "1d7b3b73-75f9-468d-8783-873ebadcab9b",
"metadata": {},
"source": [
"# My task description"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "97ec6631-8473-4a2d-b488-def921bb83de",
"metadata": {},
"outputs": [],
"source": [
"import pytometry"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.13 64-bit",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
},
"vscode": {
"interpreter": {
"hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
1 change: 1 addition & 0 deletions docs/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ The notebooks do **not** get executed in CI for testing because they involve lar
:glob:
:reversed:

*
```
60 changes: 60 additions & 0 deletions docs/guides/curate-data.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "0a9571ac-9c68-437f-ba51-95d06e283cac",
"metadata": {},
"source": [
"# How to curate data"
]
},
{
"cell_type": "markdown",
"id": "0abfc3c7",
"metadata": {},
"source": [
"```{note}\n",
"Any guide notebook is automatically run for testing! If a cell fails, the tests will fail! Try changing the assert statement below to observe.\n",
"\n",
"Note that task notebooks are neither tested, nor being built!\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bcc0c374-0224-4935-b862-0b013c624375",
"metadata": {},
"outputs": [],
"source": [
"assert 1 == 1"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.13 64-bit",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
},
"vscode": {
"interpreter": {
"hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
2 changes: 1 addition & 1 deletion docs/guides/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ These are guides on specific problems. The notebooks are executed in CI for test
```{toctree}
:maxdepth: 1


curate-data
```
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

tutorials/index
api
examples/index
guides/index
notes/index
examples/index
changelog
```
43 changes: 43 additions & 0 deletions docs/notes/YYYY-MM-DD-my-design-choice.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "1d7b3b73-75f9-468d-8783-873ebadcab9b",
"metadata": {},
"source": [
"# My design choice"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "97ec6631-8473-4a2d-b488-def921bb83de",
"metadata": {},
"outputs": [],
"source": [
"import pytometry"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
1 change: 1 addition & 0 deletions docs/notes/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ These are any notes on design decisions, prototypes, background that do not make
:glob:
:reversed:

*
```
16 changes: 8 additions & 8 deletions docs/tutorials/preprocessing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@
"metadata": {},
"outputs": [],
"source": [
"from urllib.request import urlretrieve\n",
"\n",
"path_data, _ = urlretrieve(readfcs.datasets.example(), \"example.fcs\")"
"path_data = readfcs.datasets.example()"
]
},
{
Expand Down Expand Up @@ -236,11 +234,8 @@
}
],
"metadata": {
"interpreter": {
"hash": "48c3c4927e81daf79217bae0bb1c93e3ab00a11990990ff2e155253980f357b0"
},
"kernelspec": {
"display_name": "Python 3.9.7 ('pyto_dev')",
"display_name": "Python 3.9.13 64-bit",
"language": "python",
"name": "python3"
},
Expand All @@ -254,7 +249,12 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.9.13"
},
"vscode": {
"interpreter": {
"hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e"
}
}
},
"nbformat": 4,
Expand Down
10 changes: 4 additions & 6 deletions docs/tutorials/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
"metadata": {},
"outputs": [],
"source": [
"from urllib.request import urlretrieve\n",
"\n",
"path_data, _ = urlretrieve(readfcs.datasets.example(), \"example.fcs\")"
"path_data = readfcs.datasets.example()"
]
},
{
Expand Down Expand Up @@ -81,7 +79,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.7 ('pyto_dev')",
"display_name": "Python 3.9.13 64-bit",
"language": "python",
"name": "python3"
},
Expand All @@ -95,11 +93,11 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.9.13"
},
"vscode": {
"interpreter": {
"hash": "48c3c4927e81daf79217bae0bb1c93e3ab00a11990990ff2e155253980f357b0"
"hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e"
}
}
},
Expand Down
33 changes: 16 additions & 17 deletions docs/tutorials/read_fcs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,19 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
"Read data from `readfcs` package example."
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Read data from `readfcs` package example."
"path_data = readfcs.datasets.example()"
]
},
{
Expand All @@ -47,9 +46,7 @@
"metadata": {},
"outputs": [],
"source": [
"from urllib.request import urlretrieve\n",
"\n",
"path_data, _ = urlretrieve(readfcs.datasets.example(), \"example.fcs\")"
"adata = pm.io.read_fcs(path_data)"
]
},
{
Expand All @@ -58,7 +55,7 @@
"metadata": {},
"outputs": [],
"source": [
"adata = pm.io.read_fcs(path_data)"
"adata"
]
},
{
Expand All @@ -67,7 +64,7 @@
"metadata": {},
"outputs": [],
"source": [
"adata"
"adata.var"
]
},
{
Expand Down Expand Up @@ -104,11 +101,8 @@
}
],
"metadata": {
"interpreter": {
"hash": "48c3c4927e81daf79217bae0bb1c93e3ab00a11990990ff2e155253980f357b0"
},
"kernelspec": {
"display_name": "Python 3.9.7 ('pyto_dev')",
"display_name": "Python 3.9.13 ('py39')",
"language": "python",
"name": "python3"
},
Expand All @@ -122,7 +116,12 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.9.13"
},
"vscode": {
"interpreter": {
"hash": "ae1fefc8646a06dd2e75004cd934adda7c5727b046986a772e3b44b0ffba9754"
}
}
},
"nbformat": 4,
Expand Down
23 changes: 2 additions & 21 deletions pytometry/read_write/_readfcs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from pathlib import PosixPath

import readfcs
from anndata import AnnData

Expand All @@ -8,27 +6,10 @@ def read_fcs(path: str) -> AnnData:
"""Read FCS file and convert into AnnData format.

Args:
path (str): path or Path
path: str or Path
location of fcs file to parse

Returns:
an AnnData object of the fcs file
"""
if isinstance(path, PosixPath):
path = path.as_posix()

adata = readfcs.read(path)

# move marker name to index. Then merging data becomes easier
if "marker" in adata.var_keys():
adata.var["channel"] = adata.var_names.values
# check in "marker" column that all cells have a value
# otherwise, copy from "channel"
marker_val = adata.var["marker"].values
for idx, marker in enumerate(marker_val):
if marker in ["", " "]:
marker_val[idx] = adata.var["channel"][idx]
adata.var_names = marker_val
del adata.var["marker"]

return adata
return readfcs.read(path)
10 changes: 1 addition & 9 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@


def test_read_fcs():
from urllib.request import urlretrieve

path_data, _ = urlretrieve(readfcs.datasets.example(), "example.fcs")
path_data = readfcs.datasets.example()
adata = read_fcs(path_data)
assert isinstance(adata, anndata._core.anndata.AnnData)


# def test_dummy():
# assert example_function("A") == "a"
# ex = ExampleClass(1)
# assert ex.bar() == "hello"