diff --git a/src/vfb_connect/cross_server_tools.py b/src/vfb_connect/cross_server_tools.py index 349d0a1e..0951f1cb 100644 --- a/src/vfb_connect/cross_server_tools.py +++ b/src/vfb_connect/cross_server_tools.py @@ -764,12 +764,13 @@ def get_transcriptomic_profile(self, cell_type, gene_type=False, no_subtypes=Fal else: return dc - def get_expressed_genes_by_cell_and_gene_type(self, cell_type, gene_type, no_subtypes=False, query_by_label=True, return_dataframe=True): + def get_expressed_genes_by_cell_and_gene_type(self, cell_type, gene_type, no_subtypes=False, query_by_label=True, + return_dataframe=True, verbose=False): """Get expressed genes (as a list) for scRNAseq clusters of a given cell type. Returns a DataFrame with one cluster per row, annotated as the specified cell type (or subtypes). Must restrict to a gene type (to prevent overly long gene lists), which can be retrieved using `get_gene_function_filters`. - If no data is found, returns Empty DataFrame. + If no data is found, returns False. :param cell_type: The ID, name, or symbol of a class in the Drosophila Anatomy Ontology (FBbt) or a list of these. NB lists must contain either no FBbt IDs or only FBbt IDs (with query_by_label=False). @@ -827,7 +828,22 @@ def get_expressed_genes_by_cell_and_gene_type(self, cell_type, gene_type, no_sub "ds.total_gene_count[0] AS dataset_total_gene_count, cluster_genes, " "apoc.coll.sort(apoc.coll.subtract(dataset_genes, cluster_genes)) AS genes_in_dataset_not_cluster" % (cell_type_short_form, gene_label, equal_condition, gene_label)) - print(query) + + if verbose: + print(query) + + r = self.nc.commit_list([query]) + if not r: + warnings.warn( + f"No results returned in get_expressed_genes_by_cell_and_gene_type for cell_type={cell_type} and gene_type={gene_type}" + ) + return False + dc = dict_cursor(r) + if return_dataframe: + return pd.DataFrame.from_records(dc) + else: + return dc + def get_cell_types_by_genes(self, genes=None, gene_type=False, cell_type=None, query_by_label=True, return_dataframe=True, verbose=False): """Get cell types that express a given gene, list of genes and/or type of gene based on transcriptomics data.