Skip to content

Commit

Permalink
small update on reading from multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
leoguignard committed Jul 18, 2023
1 parent fe96ab8 commit a7e38ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
17 changes: 13 additions & 4 deletions src/sc3D/sc3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import anndata
from sc3D.transformations import transformations as tr


class Embryo:
"""
Embryo class to handle samples from 3D spatial
Expand Down Expand Up @@ -993,14 +994,19 @@ def registration_3d(

all_cs_names = sorted(self.anndata.obs[self.array_id].unique())
exp = re.compile("[0-9]+")
init_cs_numbers = [int(exp.findall(x)[self.array_id_num_pos]) for x in all_cs_names]
init_cs_numbers = [
int(exp.findall(x)[self.array_id_num_pos])
for x in all_cs_names
]
num_to_name = dict(zip(init_cs_numbers, all_cs_names))
M_raw_filtered.obsm['spatial'] = M_raw_filtered.obsm[self.pos_id]
M_raw_filtered.obsm["spatial"] = M_raw_filtered.obsm[self.pos_id]
slices_id = sorted(cs_to_treat)
slices = []
for s_id in slices_id:
slices.append(
M_raw_filtered[M_raw_filtered.obs[self.array_id] == num_to_name[s_id]]
M_raw_filtered[
M_raw_filtered.obs[self.array_id] == num_to_name[s_id]
]
)
if timing:
start = time()
Expand Down Expand Up @@ -2322,7 +2328,10 @@ def __init__(
self.pos_id = pos_id
self.__diff_expr_processed = {}

if Path(data_path).suffix in [".h5ad", ".h5", ".csv"]:
if Path(data_path).suffix in [".h5ad", ".h5", ".csv"] or (
0 < len(sample_list)
and Path(sample_list[0]).suffix in [".h5ad", ".h5", ".csv"]
):
self.read_anndata(
data_path,
xy_resolution=xy_resolution,
Expand Down
15 changes: 9 additions & 6 deletions src/sc3D/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import numpy as np
import math


class transformations:
_EPS = np.finfo(float).eps * 4.0

Expand Down Expand Up @@ -60,7 +61,7 @@ def unit_vector(clf, data, axis=None, out=None):
if out is None:
return data
return None

@classmethod
def rotation_matrix(clf, angle, direction, point=None):
"""Return matrix to rotate about axis defined by point and direction.
Expand Down Expand Up @@ -88,6 +89,7 @@ def rotation_matrix(clf, angle, direction, point=None):
"""
import math

sina = math.sin(angle)
cosa = math.cos(angle)
direction = clf.unit_vector(direction[:3])
Expand All @@ -109,7 +111,7 @@ def rotation_matrix(clf, angle, direction, point=None):
point = np.array(point[:3], dtype=np.float64, copy=False)
M[:3, 3] = point - np.dot(R, point)
return M

@classmethod
def vector_norm(clf, data, axis=None, out=None):
"""Return length, i.e. Euclidean norm, of ndarray along axis.
Expand Down Expand Up @@ -195,7 +197,9 @@ def quaternion_matrix(clf, quaternion):
)

@classmethod
def affine_matrix_from_points(clf, v0, v1, shear=True, scale=True, usesvd=True):
def affine_matrix_from_points(
clf, v0, v1, shear=True, scale=True, usesvd=True
):
"""Return affine transform matrix to register two point sets.
v0 and v1 are shape (ndims, -1) arrays of at least ndims non-homogeneous
Expand Down Expand Up @@ -241,7 +245,7 @@ def affine_matrix_from_points(clf, v0, v1, shear=True, scale=True, usesvd=True):

ndims = v0.shape[0]
if ndims < 2 or v0.shape[1] < ndims or v0.shape != v1.shape:
raise ValueError('input arrays are of wrong shape or type')
raise ValueError("input arrays are of wrong shape or type")

# move centroids to origin
t0 = -np.mean(v0, axis=1)
Expand All @@ -253,7 +257,6 @@ def affine_matrix_from_points(clf, v0, v1, shear=True, scale=True, usesvd=True):
M1[:ndims, ndims] = t1
v1 += t1.reshape(ndims, 1)


if shear:
# Affine transformation
A = np.concatenate((v0, v1), axis=0)
Expand Down Expand Up @@ -304,4 +307,4 @@ def affine_matrix_from_points(clf, v0, v1, shear=True, scale=True, usesvd=True):
# move centroids back
M = np.dot(np.linalg.inv(M1), np.dot(M, M0))
M /= M[ndims, ndims]
return M
return M

0 comments on commit a7e38ac

Please sign in to comment.