Skip to content

Commit

Permalink
Deal with invalid metacell names.
Browse files Browse the repository at this point in the history
  • Loading branch information
orenbenkiki committed Mar 30, 2024
1 parent 764ff5b commit e2cec6e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/v0.1.0/.documenter-siteinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-03-30T08:58:06","documenter_version":"1.3.0"}}
{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-03-30T09:25:01","documenter_version":"1.3.0"}}
47 changes: 31 additions & 16 deletions src/anndata_format.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,18 @@ function import_h5ads!(;
type_properties::Maybe{AbstractStringSet} = nothing,
properties_defaults::Maybe{Dict} = nothing,
)::Nothing
metacells_daf =
anndata_as_daf(metacells_h5ad; name = "metacells", obs_is = "metacell", var_is = "gene", X_is = "fraction")

if raw_cells_h5ad != nothing
copy_raw_cells(destination, raw_cells_h5ad)
copy_raw_cells(destination, raw_cells_h5ad, metacells_daf)
end

copy_clean_cells(destination, clean_cells_h5ad; copy_axes = raw_cells_h5ad == nothing)
copy_clean_cells(destination, clean_cells_h5ad, metacells_daf; copy_axes = raw_cells_h5ad == nothing)

return copy_metacells(
destination,
metacells_h5ad,
metacells_daf,
type_property,
rename_type,
empty_type,
Expand All @@ -189,16 +192,16 @@ function import_h5ads!(;
)
end

function copy_raw_cells(destination::DafWriter, raw_cells_h5ad::AbstractString)::Nothing
function copy_raw_cells(destination::DafWriter, raw_cells_h5ad::AbstractString, metacells_daf::DafReader)::Nothing
raw_cells_daf = anndata_as_daf(raw_cells_h5ad; name = "raw_cells", obs_is = "cell", var_is = "gene", X_is = "UMIs")

copy_axis!(; destination = destination, source = raw_cells_daf, axis = "cell")
copy_axis!(; destination = destination, source = raw_cells_daf, axis = "gene")

copy_scalars_data(destination, raw_cells_daf)

copy_vectors(destination, raw_cells_daf, "gene", GENE_VECTORS_DATA)
copy_vectors(destination, raw_cells_daf, "cell", CELL_VECTORS_DATA)
copy_vectors(destination, raw_cells_daf, "gene", GENE_VECTORS_DATA, metacells_daf)
copy_vectors(destination, raw_cells_daf, "cell", CELL_VECTORS_DATA, metacells_daf)

sparsify_umis(raw_cells_daf)
copy_matrices(destination, raw_cells_daf, "cell", "gene", CELLS_MATRICES_DATA)
Expand All @@ -207,7 +210,12 @@ function copy_raw_cells(destination::DafWriter, raw_cells_h5ad::AbstractString):
return nothing
end

function copy_clean_cells(destination::DafWriter, clean_cells_h5ad::AbstractString; copy_axes::Bool)::Nothing
function copy_clean_cells(
destination::DafWriter,
clean_cells_h5ad::AbstractString,
metacells_daf::DafReader;
copy_axes::Bool,
)::Nothing
clean_cells_daf =
anndata_as_daf(clean_cells_h5ad; name = "clean_cells", obs_is = "cell", var_is = "gene", X_is = "UMIs")

Expand All @@ -230,8 +238,8 @@ function copy_clean_cells(destination::DafWriter, clean_cells_h5ad::AbstractStri
)
end

copy_vectors(destination, clean_cells_daf, "gene", GENE_VECTORS_DATA)
copy_vectors(destination, clean_cells_daf, "cell", CELL_VECTORS_DATA)
copy_vectors(destination, clean_cells_daf, "gene", GENE_VECTORS_DATA, metacells_daf)
copy_vectors(destination, clean_cells_daf, "cell", CELL_VECTORS_DATA, metacells_daf)

copy_matrices(destination, clean_cells_daf, "cell", "gene", CELLS_MATRICES_DATA)
copy_matrices(destination, clean_cells_daf, "gene", "cell", CELLS_MATRICES_DATA)
Expand All @@ -241,23 +249,28 @@ end

function copy_metacells(
destination::DafWriter,
metacells_h5ad::AbstractString,
metacells_daf::DafReader,
type_property::Maybe{AbstractString},
rename_type::Maybe{AbstractString},
empty_type::Maybe{AbstractString},
type_colors_csv::Maybe{AbstractString},
type_properties::Maybe{AbstractStringSet},
properties_defaults::Maybe{Dict},
)::Nothing
metacells_daf =
anndata_as_daf(metacells_h5ad; name = "metacells", obs_is = "metacell", var_is = "gene", X_is = "fraction")

copy_axis!(; destination = destination, source = metacells_daf, axis = "metacell")

copy_scalars_data(destination, metacells_daf)

copy_vectors(destination, metacells_daf, "gene", GENE_VECTORS_DATA)
copy_vectors(destination, metacells_daf, "metacell", METACELL_VECTORS_DATA, type_property, rename_type)
copy_vectors(destination, metacells_daf, "gene", GENE_VECTORS_DATA, metacells_daf)
copy_vectors(
destination,
metacells_daf,
"metacell",
METACELL_VECTORS_DATA,
metacells_daf,
type_property,
rename_type,
)

copy_matrices(destination, metacells_daf, "metacell", "gene", METACELLS_MATRICES_DATA)
copy_matrices(destination, metacells_daf, "gene", "metacell", METACELLS_MATRICES_DATA)
Expand Down Expand Up @@ -333,6 +346,7 @@ function copy_vectors(
source::DafWriter,
axis::AbstractString,
copy_data::CopyData,
metacells_daf::DafReader,
type_property::Maybe{AbstractString} = nothing,
rename_type::Maybe{AbstractString} = nothing,
)::Nothing
Expand All @@ -351,8 +365,9 @@ function copy_vectors(
vector .+= 1
set_vector!(source, axis, vector_name, sparse_vector(vector); overwrite = true)
elseif vector_name == "metacell_name"
valid_names = Set(get_axis(metacells_daf, "metacell"))
vector = get_vector(source, axis, vector_name)
vector = [name == "Outliers" ? "" : name for name in vector]
vector = [name in valid_names ? name : "" for name in vector]
set_vector!(source, axis, vector_name, vector; overwrite = true)
end
copy_vector!(; # NOJET
Expand Down

0 comments on commit e2cec6e

Please sign in to comment.