This repository has been archived by the owner on Apr 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconftest.py
67 lines (50 loc) · 3.09 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pytest
import requests
import shutil
from imctoolkit import ImageSingleCellData, SpatialCellGraph
from pathlib import Path
def _download_and_extract_asset(tmp_dir_path: Path, asset_url: str):
asset_file_path = tmp_dir_path / 'asset.tar.gz'
response = requests.get(asset_url, stream=True)
if response.status_code == 200:
with asset_file_path.open(mode='wb') as f:
f.write(response.raw.read())
shutil.unpack_archive(asset_file_path, tmp_dir_path)
@pytest.fixture(scope='session')
def analysis_cpout_images_path(tmp_path_factory):
tmp_dir_path: Path = tmp_path_factory.mktemp('analysis_cpout_images')
_download_and_extract_asset(tmp_dir_path, 'https://github.com/BodenmillerGroup/TestData/releases/download/v1.0.0/210308_ImcTestData_analysis_cpout_images.tar.gz')
yield tmp_dir_path / 'datasets' / '210308_ImcTestData' / 'analysis' / 'cpout' / 'images'
shutil.rmtree(tmp_dir_path)
@pytest.fixture(scope='session')
def analysis_cpout_masks_path(tmp_path_factory):
tmp_dir_path: Path = tmp_path_factory.mktemp('analysis_cpout_images')
_download_and_extract_asset(tmp_dir_path, 'https://github.com/BodenmillerGroup/TestData/releases/download/v1.0.0/210308_ImcTestData_analysis_cpout_masks.tar.gz')
yield tmp_dir_path / 'datasets' / '210308_ImcTestData' / 'analysis' / 'cpout' / 'masks'
shutil.rmtree(tmp_dir_path)
@pytest.fixture(scope='session')
def analysis_ometiff_path(tmp_path_factory):
tmp_dir_path: Path = tmp_path_factory.mktemp('analysis_ometiff')
_download_and_extract_asset(tmp_dir_path, 'https://github.com/BodenmillerGroup/TestData/releases/download/v1.0.1/210308_ImcTestData_analysis_ometiff.tar.gz')
yield tmp_dir_path / 'datasets' / '210308_ImcTestData' / 'analysis' / 'ometiff'
shutil.rmtree(tmp_dir_path)
@pytest.fixture(scope='session')
def raw_path(tmp_path_factory):
tmp_dir_path: Path = tmp_path_factory.mktemp('raw')
_download_and_extract_asset(tmp_dir_path, 'https://github.com/BodenmillerGroup/TestData/releases/download/v1.0.0/210308_ImcTestData_raw.tar.gz')
yield tmp_dir_path / 'datasets' / '210308_ImcTestData' / 'raw'
shutil.rmtree(tmp_dir_path)
@pytest.fixture
def data(analysis_cpout_images_path: Path, analysis_cpout_masks_path: Path):
img_file_path = analysis_cpout_images_path / '20210305_NE_mockData1_s0_a1_ac_fullFiltered.tiff'
mask_file_path = analysis_cpout_masks_path / '20210305_NE_mockData1_s0_a1_ac_ilastik_s2_Probabilities_mask.tiff'
channel_names = ['Ag107', 'Pr141', 'Sm147', 'Eu153', 'Yb172']
return ImageSingleCellData(img_file_path, mask_file_path, channel_names=channel_names)
@pytest.fixture
def knn_graph(data: ImageSingleCellData):
dist_mat = data.compute_cell_centroid_distances(metric='euclidean')
return SpatialCellGraph.construct_knn_graph(data, dist_mat, k=5, cell_properties=True, cell_channel_properties=True)
@pytest.fixture
def dist_graph(data: ImageSingleCellData):
dist_mat = data.compute_cell_centroid_distances(metric='euclidean')
return SpatialCellGraph.construct_dist_graph(data, dist_mat, 15, cell_properties=True, cell_channel_properties=True)