Skip to content

Commit

Permalink
Merge pull request #42 from sansomlab/yz_singleR
Browse files Browse the repository at this point in the history
YZ_general
  • Loading branch information
snsansom committed Jul 7, 2023
2 parents a35d233 + f146a27 commit 56b880d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion R/scripts/singleR_run.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ref_path = file.path(opt$refstashdir, paste(opt$reference,"rds",sep="."))
print(ref_path)
ref.se <- readRDS(ref_path)

if (grepl("ENSMUSG", rownames(ref.se)[1]))
if (grepl("ENSMUSG", rownames(ref.se)[1]) & grepl("ENSG",rownames(sce)[1]))
{
message("cleaning up mouse ensembl indentifiers")
rownames(ref.se) <- gsub("ENSMUSG", "ENSG", rownames(ref.se))
Expand Down
20 changes: 2 additions & 18 deletions cellhub/pipeline_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def taskSummary(infile, outfile):
tab = pd.DataFrame(list(zip(tasks,run)),columns=["task","run"])
tab.to_latex(buf=outfile, index=False, escape=True)


@files(PARAMS["source_anndata"],
"preflight.sentinel")
def preflight(infile, outfile):
Expand Down Expand Up @@ -428,20 +428,6 @@ def compareClusters(infile, outfile):

reductiontype = PARAMS["source_rdim_name"]

if t.resolution == "predefined":

# TODO: Fix.
cluster_file = sample + ".cluster_ids.rds"

if os.path.exists(cluster_file):
predefined = "--predefined=%(cluster_file)s" % locals()

else:
raise ValueError("Predefined cluster assignment file (%(cluster_file)s) not found" % locals())

else:
predefined = ""

statement = '''python %(cellhub_code_dir)s/python/cluster_compare.py
--source_anndata=%(source_anndata)s
--clusterids=%(cluster_ids)s
Expand Down Expand Up @@ -1911,15 +1897,13 @@ def cellxgene(infile, outfile):
# ##################### full target: to run all tasks ####################### #
# ########################################################################### #


@follows(report, cellxgene)
def full():
pass


# ------------------- < ***** end of pipeline **** > ------------------------ #


def main(argv=None):
if argv is None:
argv = sys.argv
Expand All @@ -1929,4 +1913,4 @@ def main(argv=None):
if __name__ == "__main__":
sys.exit(P.main(sys.argv))

#endregion
#endregion
4 changes: 2 additions & 2 deletions cellhub/pipeline_fetch_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def GEX(infile, outfile):
TODO: support down-sampling
'''

t = T.setup(infile, outfile, PARAMS, memory=PARAMS["resource_memory"])
t = T.setup(infile, outfile, PARAMS, memory=PARAMS["resources_memory"])

cell_table = infile.replace(".sentinel", ".tsv.gz")
api_path = os.path.join(PARAMS["cellhub_location"],"api")
Expand Down Expand Up @@ -177,7 +177,7 @@ def ADT(infile, outfile):
TODO: support down-sampling
'''

t = T.setup(infile, outfile, PARAMS, memory=PARAMS["resource_memory"])
t = T.setup(infile, outfile, PARAMS, memory=PARAMS["resources_memory"])

cell_table = infile.replace(".sentinel", ".tsv.gz")
api_path = os.path.join(PARAMS["cellhub_location"],"api")
Expand Down
1 change: 1 addition & 0 deletions cellhub/tasks/celldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def load(table_name,
statement = '''python -m cgatcore.tables
--regex-filename "%(regex_filename)s"
--cat "filename"
--missing-value NULL
%(table_path)s/%(glob)s
| gzip -c
> %(table_file)s
Expand Down
5 changes: 3 additions & 2 deletions cellhub/yaml/pipeline_cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ runspecs:
# --------------------------
neighbors:

# scanpy | hnsw
# scanpy | hnsw | precomputed
# if precomputed -> adata file needs to have neighbors to read
method: hnsw

# for hnsw
Expand Down Expand Up @@ -502,4 +503,4 @@ cellxgene:
# only one factor may be specified
# default: None
cluster_split: None


19 changes: 17 additions & 2 deletions python/cluster_neighbor_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
parser.add_argument("--ncomps", default=20, type=int,
help="Number of reduced components to include in the knn computation")
parser.add_argument("--method", default="scanpy", type=str,
help="scanpy|hnsw|sklearn (scanpy uses pynndescent)")
help="scanpy|hnsw|sklearn|precomputed (scanpy uses pynndescent)")
parser.add_argument("--k", default=20, type=int,
help="number of neighbors")
parser.add_argument("--metric", default="euclidean", type=str,
Expand Down Expand Up @@ -87,7 +87,6 @@
use_rep = nn_rdims)



elif args.method == "hnsw":

L.info("Computing neighbors using hnswlib (with scvelo a la pegasus!)")
Expand Down Expand Up @@ -129,6 +128,22 @@
# metric_kwds = {}
num_threads=args.threads)


elif args.method == "precomputed":

L.info("Using precomputed neighbors")

from scanpy._utils import NeighborsView

#add knn to adata
adata.uns["neighbors"] = sourceAdata.uns["neighbors"]
adata.obsp = sourceAdata.obsp

#rename rep_use to 'X___'
neighbors = NeighborsView(adata, "neighbors")
neighbors["params"]["use_rep"]='X_'+args.reduced_dims_name+'_copy_for_nn'
adata.uns["neighbors"]["params"]=neighbors["params"]

else:
raise ValueError("nn method not recognised")

Expand Down
6 changes: 2 additions & 4 deletions python/fetch_cells_from_h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
# ########################################################################### #

L.info("Reading cell table")

cell_table = pd.read_csv(args.cells, sep="\t")

good_cols = [x for x in cell_table.columns if
Expand All @@ -55,9 +56,6 @@
zip([x.split("-")[0] for x in cell_table["barcode"].values],
cell_table["library_id"].values)]

print(cell_table)
print(cell_table.index)

libraries = set(cell_table["library_id"].values)

anndata_slices = {}
Expand Down Expand Up @@ -158,7 +156,7 @@

# drop unnecessary .obs columns
anndata.obs.drop("barcode", axis=1, inplace=True)

# save the anndata
anndata.write_h5ad(os.path.join(args.outdir, args.outname))

Expand Down

0 comments on commit 56b880d

Please sign in to comment.