Skip to content

Commit

Permalink
Merge pull request #135 from FertigLab/nextflow
Browse files Browse the repository at this point in the history
add anndata to dgcmatrix module
  • Loading branch information
dimalvovs authored Dec 13, 2024
2 parents 5595e8c + 02267b6 commit dc800bc
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion nextflow/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ process COGAPS {
"""
}

process PREPROCESS {
process TENX_2DGCMAT {
tag "$meta.id"
label 'process_low'
container 'docker.io/satijalab/seurat:5.0.0'
Expand Down Expand Up @@ -98,3 +98,61 @@ process PREPROCESS {
END_VERSIONS
"""
}

process ADATA_2DGCMAT {
tag "$meta.id"
label 'process_low'
container 'docker.io/satijalab/seurat:5.0.0'

input:
tuple val(meta), path(data)
output:
tuple val(meta), path("${prefix}/dgCMatrix.rds"), emit: dgCMatrix
path "versions.yml" , emit: versions

stub:
def args = task.ext.args ?: ''
prefix = task.ext.prefix ?: "${meta.id}"

"""
mkdir "${prefix}"
touch "${prefix}/dgCMatrix.rds"
cat <<-END_VERSIONS > versions.yml
"${task.process}":
hdf5r: \$(Rscript -e 'print(packageVersion("Seurat"))' | awk '{print \$2}')
R: \$(Rscript -e 'print(packageVersion("base"))' | awk '{print \$2}')
END_VERSIONS
"""

script:
def args = task.ext.args ?: ''
prefix = task.ext.prefix ?: "${meta.id}"
"""
mkdir "${prefix}"
Rscript -e 'message("Reading data from ", "$data");
f <- hdf5r::h5file(filename = "$data", mode="r");
i <- hdf5r::readDataSet(f[["X/indices"]]);
p <- hdf5r::readDataSet(f[["X/indptr"]]);
x <- hdf5r::readDataSet(f[["X/data"]]);
dims <- c(hdf5r::h5attributes(f[["X/"]])[["shape"]][1],
hdf5r::h5attributes(f[["X/"]])[["shape"]][2]);
res <- Matrix::sparseMatrix(i = i, p = p, x = x, dims = dims, index1=FALSE);
message("Read matrix with dimensions: ", dims[1],",",dims[2]);
colnames(res) <- hdf5r::readDataSet(f[["var/_index"]]);
rownames(res) <- hdf5r::readDataSet(f[["obs/_index"]]);
hdf5r::h5close(f);
message("Normalizing data");
res <- Seurat::NormalizeData(res);
message("Saving");
saveRDS(res, file="${prefix}/dgCMatrix.rds")';
cat <<-END_VERSIONS > versions.yml
"${task.process}":
seurat: \$(Rscript -e 'print(packageVersion("hdf5r"))' | awk '{print \$2}')
Matrix: \$(Rscript -e 'print(packageVersion("Matrix"))' | awk '{print \$2}')
Matrix: \$(Rscript -e 'print(packageVersion("Seurat"))' | awk '{print \$2}')
R: \$(Rscript -e 'print(packageVersion("base"))' | awk '{print \$2}')
END_VERSIONS
"""
}

0 comments on commit dc800bc

Please sign in to comment.