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

attempt to fix failed checks #65

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
27 changes: 27 additions & 0 deletions scimap/helpers/_add_roi_omero.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import matplotlib.patches as mpatches
import scipy.spatial.distance as sdistance
from joblib import Parallel, delayed
import argparse


def add_roi_omero (adata, roi, x_coordinate='X_centroid',y_coordinate='Y_centroid',
Expand Down Expand Up @@ -182,3 +183,29 @@ def add_roi_internal (roi_id):

# return
return adata

parser = argparse.ArgumentParser(description='Add ROI to AnnData object from Omero')

parser.add_argument('adata', help='Path to the AnnData object')
parser.add_argument('roi', help='Path to the ROI DataFrame')
parser.add_argument('--x_coordinate', default='X_centroid', help='Column name for x-coordinates')
parser.add_argument('--y_coordinate', default='Y_centroid', help='Column name for y-coordinates')
parser.add_argument('--imageid', default='imageid', help='Column name for image IDs')
parser.add_argument('--subset', help='List of image names to add ROIs')
parser.add_argument('--overwrite', action='store_true', help='Overwrite the label column')
parser.add_argument('--label', default='ROI', help='Key for the returned data')
parser.add_argument('--n_jobs', type=int, default=-1, help='Number of cores to use')
parser.add_argument('--verbose', action='store_true', help='Enable verbose mode')

args = parser.parse_args()

# Call the add_roi_omero function
result = add_roi_omero(args.adata,args.roi, x_coordinate=args.x_coordinate, y_coordinate=args.y_coordinate,
imageid=args.imageid, subset=args.subset, overwrite=args.overwrite,
label=args.label, n_jobs=args.n_jobs, verbose=args.verbose)

# Save the modified AnnData object
result.write('modified_anndata.h5ad')

if __name__ == '__main__':
add_roi_omero_command_line()
46 changes: 36 additions & 10 deletions scimap/tools/_spatial_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# Import library
import pandas as pd
import numpy as np
import argparse
from sklearn.neighbors import BallTree

# Function
Expand All @@ -24,40 +25,40 @@ def spatial_aggregate (adata, x_coordinate='X_centroid',y_coordinate='Y_centroid
Parameters:
adata : AnnData object

x_coordinate : float, required
x_coordinate (float):
Column name containing the x-coordinates values.

y_coordinate : float, required
y_coordinate (float):
Column name containing the y-coordinates values.

purity : int, optional
purity (int):
Supply a value between 1 to 100. It is the percent purity of neighbouring cells.
For e.g. if 60 is chosen, every neighbourhood is tested such that if a
particular phenotype makes up greater than 60% of the total
population it is annotated to be an aggregate of that particular phenotype.

phenotype : string, required
phenotype (string):
Column name of the column containing the phenotype information.
It could also be any categorical assignment given to single cells.

method : string, optional
method (string):
Two options are available: a) 'radius', b) 'knn'.
a) radius - Identifies the neighbours within a given radius for every cell.
b) knn - Identifies the K nearest neigbours for every cell.

radius : int, optional
radius (int):
The radius used to define a local neighbhourhood.

knn : int, optional
knn (int):
Number of cells considered for defining the local neighbhourhood.

imageid : string, optional
imageid (string):
Column name of the column containing the image id.

subset : string, optional
subset (string):
imageid of a single image to be subsetted for analyis.

label : string, optional
label (string):
Key for the returned data, stored in `adata.obs`.

Returns:
Expand Down Expand Up @@ -183,3 +184,28 @@ def spatial_aggregate_internal (adata_subset, x_coordinate,y_coordinate,phenotyp
# Return
return adata

if __name__ == '__main__':
# Create argparse parser
parser = argparse.ArgumentParser(description='Perform spatial aggregation analysis.')

# Add arguments
parser.add_argument('adata', help='Path to the AnnData object file.')
parser.add_argument('--x_coordinate', default='X_centroid', help='Column name for x-coordinates.')
parser.add_argument('--y_coordinate', default='Y_centroid', help='Column name for y-coordinates.')
parser.add_argument('--purity', type=int, default=60, help='Percent purity of neighboring cells.')
parser.add_argument('--phenotype', default='phenotype', help='Column name for phenotype information.')
parser.add_argument('--method', default='radius', help='Method for identifying neighbors.')
parser.add_argument('--radius', type=int, default=30, help='Radius used to define a local neighborhood.')
parser.add_argument('--knn', type=int, default=10, help='Number of cells considered for defining the local neighborhood.')
parser.add_argument('--imageid',type=str, default='imageid', help='Column name for image ID.')
parser.add_argument('--subset',type=str, help='Image ID of a single image to be subsetted for analysis.')
parser.add_argument('--label',type=str, default='spatial_aggregate', help='Key for the returned data.')

# Parse the command line arguments
args = parser.parse_args()

# Call the spatial_aggregate function with the parsed arguments
spatial_aggregate(args.adata, args.x_coordinate, args.y_coordinate, args.purity,
args.phenotype, args.method, args.radius, args.knn,
args.imageid, args.subset, args.label)

45 changes: 35 additions & 10 deletions scimap/tools/_spatial_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# Import library
import pandas as pd
import numpy as np
import argparse
from sklearn.neighbors import BallTree

# Function
Expand All @@ -39,34 +40,34 @@ def spatial_count (adata,
Parameters:
adata : anndata object

x_coordinate : float, required
x_coordinate (float):
Column name containing the x-coordinates values.

y_coordinate : float, required
y_coordinate (float):
Column name containing the y-coordinates values.

phenotype : string, required
phenotype (string):
Column name of the column containing the phenotype information.
It could also be any categorical assignment given to single cells.

method : string, optional
method (string):
Two options are available: a) `radius`, b) `knn`.
a) radius - Identifies the neighbours within a given radius for every cell.
b) knn - Identifies the K nearest neigbours for every cell.

radius : int, optional
radius (int):
The radius used to define a local neighbhourhood.

knn : int, optional
knn (int):
Number of cells considered for defining the local neighbhourhood.

imageid : string, optional
imageid (string):
Column name of the column containing the image id.

subset : string, optional
subset (string):
imageid of a single image to be subsetted for analyis.

label : string, optional
label (string):
Key for the returned data, stored in `adata.uns`.

Returns:
Expand Down Expand Up @@ -172,4 +173,28 @@ def spatial_count_internal (adata_subset,x_coordinate,y_coordinate,phenotype,met
adata.uns[label] = result

# Return
return adata
return adata

if __name__ == '__main__':
# Create argparse parser
parser = argparse.ArgumentParser(description='Perform spatial counting analysis.')

# Add arguments
parser.add_argument('--adata',type=str ,help='Path to the AnnData object file.')
parser.add_argument('--x_coordinate',type=str, default='X_centroid', help='Column name for x-coordinates.')
parser.add_argument('--y_coordinate',type=str, default='Y_centroid', help='Column name for y-coordinates.')
parser.add_argument('--phenotype',type=str, default='phenotype', help='Column name for phenotype information.')
parser.add_argument('--method', type=str, default='radius', help='Method for identifying neighbors.')
parser.add_argument('--radius', type=int, default=30, help='Radius used to define a local neighborhood.')
parser.add_argument('--knn', type=int, default=10, help='Number of cells considered for defining the local neighborhood.')
parser.add_argument('--imageid', type=str, default='imageid', help='Column name for image ID.')
parser.add_argument('--subset', type=str, help='Image ID of a single image to be subsetted for analysis.')
parser.add_argument('--label', type=str, default='spatial_count', help='Key for the returned data.')

# Parse the command line arguments
args = parser.parse_args()

# Call the spatial_count function with the parsed arguments
spatial_count(args.adata, args.x_coordinate, args.y_coordinate, args.phenotype,
args.method, args.radius, args.knn, args.imageid,
args.subset, args.label)
36 changes: 29 additions & 7 deletions scimap/tools/_spatial_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# Import library
import pandas as pd
from sklearn.neighbors import BallTree
import argparse
from joblib import Parallel, delayed
import itertools

Expand All @@ -27,26 +28,26 @@ def spatial_distance (adata,x_coordinate='X_centroid',y_coordinate='Y_centroid',

adata : AnnData object

x_coordinate : float, required
x_coordinate (float):
Column name containing the x-coordinates values.

y_coordinate : float, required
y_coordinate (float):
Column name containing the y-coordinates values.

z_coordinate : float, optional
z_coordinate (float, optional):
Column name containing the z-coordinates values.

phenotype : string, required
phenotype (string):
Column name of the column containing the phenotype information.
It could also be any categorical assignment given to single cells.

subset : string, optional
subset (string):
imageid of a single image to be subsetted for analyis.

imageid : string, optional
imageid (string):
Column name of the column containing the image id.

label : string, optional
label (string):
Key for the returned data, stored in `adata.obs`.

Returns:
Expand Down Expand Up @@ -122,6 +123,27 @@ def distance (pheno):

# return
return adata

if __name__ == '__main__':
# Create argparse parser
parser = argparse.ArgumentParser(description='Compute spatial distances.')

# Add arguments
parser.add_argument('--adata', type = str, help='Path to the AnnData object file.')
parser.add_argument('--x_coordinate', type = float, default='X_centroid', help='Column name for x-coordinates.')
parser.add_argument('--y_coordinate', type= float, default='Y_centroid', help='Column name for y-coordinates.')
parser.add_argument('--z_coordinate', type= float, help='Column name for z-coordinates.')
parser.add_argument('--phenotype', type=str, default='phenotype', help='Column name for phenotype information.')
parser.add_argument('--subset', type=str, help='Image ID of a single image to be subsetted for analysis.')
parser.add_argument('--imageid', type=str, default='imageid', help='Column name for image ID.')
parser.add_argument('--label', type=str, default='spatial_distance', help='Key for the returned data.')

# Parse the command line arguments
args = parser.parse_args()

# Call the spatial_distance function with the parsed arguments
spatial_distance(args.adata, args.x_coordinate, args.y_coordinate, args.z_coordinate,
args.phenotype, args.subset, args.imageid, args.label)



58 changes: 46 additions & 12 deletions scimap/tools/_spatial_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from joblib import Parallel, delayed
import scipy
from functools import reduce
import argparse


# Function
Expand All @@ -31,36 +32,36 @@ def spatial_interaction (adata,x_coordinate='X_centroid',y_coordinate='Y_centroi
"""
Parameters:
adata : AnnData object
x_coordinate : float, required
x_coordinate (float):
Column name containing the x-coordinates values.
y_coordinate : float, required
y_coordinate (float):
Column name containing the y-coordinates values.
z_coordinate : float, optional
z_coordinate (float):
Column name containing the z-coordinates values.
phenotype : string, required
phenotype (string):
Column name of the column containing the phenotype information.
It could also be any categorical assignment given to single cells.
method : string, optional
method (string):
Two options are available: a) 'radius', b) 'knn'.
a) radius - Identifies the neighbours within a given radius for every cell.
b) knn - Identifies the K nearest neigbours for every cell.
radius : int, optional
radius (int):
The radius used to define a local neighbhourhood.
knn : int, optional
knn (int):
Number of cells considered for defining the local neighbhourhood.
permutation : int, optional
permutation (int):
The number of permutations to be performed for calculating the P-Value.
imageid : string, optional
imageid (string):
Column name of the column containing the image id.
subset : string, optional
subset (string):
imageid of a single image to be subsetted for analyis.
pval_method : string, optional
pval_method (string):
Two options are available: a) 'histocat', b) 'zscore'.
a) P-values are calculated by subtracting the permuted mean from the observed mean
divided by the number of permutations as described in the histoCAT manuscript (Denis et.al, Nature Methods 2017)
b) zscores are calculated from the mean and standard deviation and further p-values are
derived by fitting the observed values to a normal distribution. The default is 'histocat'.
label : string, optional
label (string):
Key for the returned data, stored in `adata.obs`. The default is 'spatial_interaction'.
Returns:
adata : AnnData object
Expand Down Expand Up @@ -231,4 +232,37 @@ def permutation_pval (data):
# return
return adata

if __name__ == '__main__':
# Create argparse parser
parser = argparse.ArgumentParser(description='Compute spatial interaction.')

parser.add_argument('--adata', type=str,help='Path to the AnnData object file.')
parser.add_argument('--x_coordinate', type=float, default='X_centroid', help='Column name for x-coordinates.')
parser.add_argument('--y_coordinate', type=float,default='Y_centroid', help='Column name for y-coordinates.')
parser.add_argument('--z_coordinate',type=float, help='Column name for z-coordinates.')
parser.add_argument('--phenotype',type=str, default='phenotype', help='Column name for phenotype information.')
parser.add_argument('--method',type=str, default='radius', choices=['radius', 'knn'], help='Method for identifying neighbors.')
parser.add_argument('--radius', type=int, default=30, help='Radius used to define a local neighborhood.')
parser.add_argument('--knn', type=int, default=10, help='Number of cells considered for defining the local neighborhood.')
parser.add_argument('--permutation', type=int, default=1000, help='Number of permutations for calculating p-value.')
parser.add_argument('--imageid',type=str, default='imageid', help='Column name for image ID.')
parser.add_argument('--subset',type=str, help='Image ID of a single image to be subsetted for analysis.')
parser.add_argument('--pval_method',type=str, default='histocat', choices=['histocat', 'zscore'], help='Method for calculating p-values.')
parser.add_argument('--label',type=str, default='spatial_interaction', help='Key for the returned data.')

# Parse the command-line arguments
args = parser.parse_args()

# Call the spatial_interaction function with the parsed arguments
spatial_interaction(args.adata, args.x_coordinate, args.y_coordinate, args.z_coordinate,
args.phenotype, args.method, args.radius, args.knn,
args.permutation, args.imageid, args.subset,
args.pval_method, args.label)








Loading