Skip to content

Commit

Permalink
check if plotting tests is compatable with github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ajitjohnson committed Apr 24, 2024
1 parent 72d5ebf commit c6456e2
Show file tree
Hide file tree
Showing 17 changed files with 11,528 additions and 254 deletions.
Empty file removed .Rhistory
Empty file.
6 changes: 4 additions & 2 deletions scimap/helpers/downloadDemoData.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from tqdm import tqdm
import os

def downloadDemoData(directory):
def downloadDemoData(directory, api_url=None):
"""
Downloads all files from a Zenodo record into the specified directory,
showing a progress bar for each file.
Expand All @@ -27,7 +27,9 @@ def downloadDemoData(directory):
print(f"Created directory: {directory}")

# Get record details from Zenodo API
api_url = "https://zenodo.org/api/records/10845625"
if api_url is None:
api_url = "https://zenodo.org/api/records/10845625"

response = requests.get(api_url)
if response.status_code != 200:
print(f"Failed to retrieve record details. HTTP status code: {response.status_code}")
Expand Down
10 changes: 4 additions & 6 deletions scimap/helpers/merge_adata_obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def merge_adata_obs (adata,
df = pd.DataFrame()
uns_count = []
for i in adata:
tmp = ad.read(i)
tmp = ad.read_h5ad(i)
# OBS
tmp_df = tmp.obs
df = pd.concat([df, tmp_df], axis=1)
Expand Down Expand Up @@ -120,7 +120,7 @@ def merge_adata_obs (adata,
# create the final anndata object
# Load the data
if isinstance(adata[0], str):
final_adata = ad.read(adata[uns_index])
final_adata = ad.read_h5ad(adata[uns_index])
else:
final_adata = adata[uns_index]

Expand All @@ -129,15 +129,13 @@ def merge_adata_obs (adata,

# replace obs
final_adata.obs = df

# Find name of file
image_path = pathlib.Path(adata[0])


# Save data if requested
if output_dir is not None:
output_dir = pathlib.Path(output_dir)
output_dir.mkdir(exist_ok=True, parents=True)
final_adata.write(output_dir / image_path.name)
final_adata.write(output_dir / 'combined_adata.h5ad')
else:
# Return data
return final_adata
Expand Down
11,202 changes: 11,202 additions & 0 deletions scimap/tests/scimapExampleData/exemplar-001--unmicst_cell.csv

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions scimap/tests/scimapExampleData/manual_gates.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
marker,exemplar-001--unmicst_cell
ELANE,7.8
CD57,8.9
CD45,6.4
CD11B,7.6
SMA,7.5
CD16,6.5
ECAD,7.35
FOXP3,7.4
NCAM,7
13 changes: 13 additions & 0 deletions scimap/tests/scimapExampleData/markers.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
channel_number,cycle_number,marker_name,Filter,excitation_wavelength,emission_wavelength,background,exposure,remove
21,6,DNA_6,DAPI,395,431,,100,
22,6,ELANE,FITC,485,525,,100,
23,6,CD57,Sytox,555,590,,100,
24,6,CD45,Cy5,640,690,,100,
25,7,DNA_7,DAPI,395,431,,100,
26,7,CD11B,FITC,485,525,,100,
27,7,SMA,Sytox,555,590,,100,
28,7,CD16,Cy5,640,690,,100,
29,8,DNA_8,DAPI,395,431,,100,
30,8,ECAD,FITC,485,525,,100,
31,8,FOXP3,Sytox,555,590,,100,
32,8,NCAM,Cy5,640,690,,100,
8 changes: 8 additions & 0 deletions scimap/tests/scimapExampleData/phenotype_workflow.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
,,ELANE,CD57,CD45,CD11B,SMA,CD16,ECAD,FOXP3,NCAM
all,ECAD+,,,,,,,pos,,
all,Immune,,,pos,,,,,,
all,SMA+,,,,,pos,,,,
Immune,NK cells,,allpos,,neg,,allpos,,,
Immune,Other myeloid cells,,,,pos,,,,,
Immune,Treg,,,,,,,,pos,
Other myeloid cells,Dendritic cells,,allneg,,,,allneg,,,
Binary file not shown.
45 changes: 0 additions & 45 deletions scimap/tests/test_helpers.py

This file was deleted.

65 changes: 65 additions & 0 deletions scimap/tests/test_hl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 23 20:14:55 2024
@author: aj
Test helper function
"""

import pytest
import os
import anndata as ad
import pandas as pd

# load data
@pytest.fixture
def adata():
image_path = os.getcwd() + '/scimap/tests/scimapExampleData/scimapExampleData.h5ad'
adata = ad.read_h5ad(image_path)
return adata


# classify
def test_classify (adata):
from scimap.helpers.classify import classify
adata = classify(adata, pos=['FOXP3'], neg=['ECAD'], phenotype='phenotype')
assert adata.obs['classify'].value_counts()['passed_classify'] == 228

# rename
def test_rename (adata):
from scimap.helpers.rename import rename
name= {'renamed': ['Dendritic cells', 'NK cells']}
adata = rename (adata, name, from_column='phenotype', to_column='phenotype_renamed')
assert adata.obs['phenotype_renamed'].value_counts()['renamed'] == 85

# dropFeatures
def test_dropFeatures (adata):
from scimap.helpers.dropFeatures import dropFeatures
adata = dropFeatures(adata, drop_markers=['ELANE', 'NCAM'])
assert len(adata.var.index) == 7

# merge_adata_obs
def test_merge_adata_obs (adata):
from scimap.helpers.merge_adata_obs import merge_adata_obs
bdata = adata.copy()
bdata.obs['new_col'] = bdata.obs['imageid']
combined_adata = merge_adata_obs(adata=[adata, bdata])
assert len(combined_adata.obs.columns) == 14

# scimap_to_csv
def test_scimap_to_csv (adata):
from scimap.helpers.scimap_to_csv import scimap_to_csv
data = scimap_to_csv(adata)
assert data.shape == (11201, 22)

# downloadDemoData
def downloadDemoData ():
from scimap.helpers.downloadDemoData import downloadDemoData
download_directory = os.getcwd() + '/demodata'
downloadDemoData (download_directory, api_url="https://zenodo.org/api/records/11054442")
downloaded_data = pd.read_csv(os.getcwd() + '/demodata/manual_gates.csv')
assert downloaded_data.shape == (9, 2)

# addROI_omero

# animate
49 changes: 49 additions & 0 deletions scimap/tests/test_pl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 23 21:22:21 2024
@author: aj
Test plotting functions
"""

import pytest
import os
import anndata as ad
import matplotlib.pyplot as plt

# load data
@pytest.fixture
def adata():
image_path = os.getcwd() + '/scimap/tests/scimapExampleData/scimapExampleData.h5ad'
adata = ad.read_h5ad(image_path)
return adata


# heatmap
def test_heatmap (adata):
from scimap.plotting.heatmap import heatmap
heatmap(adata, groupBy='phenotype', standardScale='column')




# markerCorrelation
# groupCorrelation
# distPlot
# densityPlot2D
# cluster_plots
# umap
# foldchange
# spatial_scatterPlot
# spatial_distance
# spatial_interaction
# spatialInteractionNetwork
# spatial_pscore
# stacked_barplot
# pie
# voronoi


# image_viewer
# addROI_image
# gate_finder
59 changes: 59 additions & 0 deletions scimap/tests/test_pp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 22 22:16:06 2024
@author: aj
Pre processing tools tests
"""

import pytest
import os
import anndata as ad
import pandas as pd


#os.chdir ('/Users/aj/Dropbox (Partners HealthCare)/nirmal lab/softwares/scimap')

# loading via mcmicro
def test_mcmicro_to_scimap():
from scimap.preprocessing.mcmicro_to_scimap import mcmicro_to_scimap
feature_table_path = [os.getcwd() + '/scimap/tests/scimapExampleData/exemplar-001--unmicst_cell.csv']
adata = mcmicro_to_scimap (feature_table_path)
assert adata.shape == (11201, 9)


@pytest.fixture
def adata():
image_path = os.getcwd() + '/scimap/tests/scimapExampleData/scimapExampleData.h5ad'
adata = ad.read_h5ad(image_path)
return adata


# log1p
def test_log1p (adata):
from scimap.preprocessing.log1p import log1p
adata = log1p (adata, layer='log_test')
assert adata.layers['log_test'].shape == (11201, 9)


# rescale
def test_rescale (adata):
from scimap.preprocessing.rescale import rescale
manual_gate = pd.read_csv(os.getcwd() + '/scimap/tests/scimapExampleData/manual_gates.csv')
adata = rescale (adata, gate=manual_gate)
assert round(adata.X[0][0], 2) == 0.12


# combat
def test_combat (adata):
from scimap.preprocessing.combat import combat
adata = combat (adata, batch='ROI')
assert adata.layers['combat'].shape == (11201, 9)
adata = combat (adata, batch='ROI', layer='raw', label='combat_raw')
assert adata.layers['combat_raw'].shape == (11201, 9)
adata = combat (adata, batch='ROI', log=True, label='combat_log')
assert adata.layers['combat_log'].shape == (11201, 9)
adata = combat (adata, batch='ROI', layer='log', label='combat_log_layer')
assert adata.layers['combat_log_layer'].shape == (11201, 9)
adata = combat (adata, batch='ROI', replaceOriginal=True)
assert round(adata.X[0][0], 2) == 0.12
36 changes: 0 additions & 36 deletions scimap/tests/test_preprocessing.py

This file was deleted.

Loading

0 comments on commit c6456e2

Please sign in to comment.