rename "geneset" to "gene set" in CLI (#2088)

* remove dead code

* rename geneset to gene_set
This commit is contained in:
Bruce Martin
2021-03-02 15:36:01 -08:00
committed by GitHub
parent b00496198d
commit c037f4eaa6
14 changed files with 101 additions and 102 deletions

View File

@@ -411,7 +411,6 @@ export const saveGenesetsAction = () => async (dispatch, getState) => {
const tid = (lastTid ?? 0) + 1;
const genesets = [];
for (const [name, gs] of lastGenesets) {
// const genes = Array.from(gs.genes.values());
const genes = [];
for (const g of gs.genes.values()) {
genes.push({

View File

@@ -42,7 +42,7 @@ def annotation_args(func):
multiple=False,
metavar="<directory path>",
help="Directory of where to save output annotations; filename will be specified in the application. "
"Incompatible with --annotations-file and --genesets-file.",
"Incompatible with --annotations-file and --gene-sets-file.",
)
@click.option(
"--experimental-annotations-ontology",
@@ -59,16 +59,16 @@ def annotation_args(func):
help="Location of OBO file defining cell annotation autosuggest terms.",
)
@click.option(
"--disable-genesets-save",
"--disable-gene-sets-save",
is_flag=True,
default=DEFAULT_CONFIG.dataset_config.user_annotations__genesets__readonly,
default=DEFAULT_CONFIG.dataset_config.user_annotations__gene_sets__readonly,
show_default=False,
help="Disable saving gene sets. If disabled, users will be able to make changes to gene sets but all "
"changes will be lost on browser refresh.",
)
@click.option(
"--genesets-file",
default=DEFAULT_CONFIG.dataset_config.user_annotations__local_file_csv__genesets_file,
"--gene-sets-file",
default=DEFAULT_CONFIG.dataset_config.user_annotations__local_file_csv__gene_sets_file,
show_default=True,
multiple=False,
metavar="<path>",
@@ -334,8 +334,8 @@ def launch(
disable_annotations,
annotations_file,
user_generated_data_dir,
genesets_file,
disable_genesets_save,
gene_sets_file,
disable_gene_sets_save,
backed,
disable_diffexp,
experimental_annotations_ontology,
@@ -394,8 +394,8 @@ def launch(
user_annotations__enable=not disable_annotations,
user_annotations__local_file_csv__file=annotations_file,
user_annotations__local_file_csv__directory=user_generated_data_dir,
user_annotations__local_file_csv__genesets_file=genesets_file,
user_annotations__genesets__readonly=disable_genesets_save,
user_annotations__local_file_csv__gene_sets_file=gene_sets_file,
user_annotations__gene_sets__readonly=disable_gene_sets_save,
user_annotations__ontology__enable=experimental_annotations_ontology,
user_annotations__ontology__obo_location=experimental_annotations_ontology_obo,
presentation__max_categories=max_category_items,

View File

@@ -21,15 +21,15 @@ class Annotations(metaclass=ABCMeta):
def user_annotations_enabled(self):
return self.config.get("user-annotations", False)
def genesets_save_enabled(self):
def gene_sets_save_enabled(self):
return self.config.get("genesets-save", False)
def check_user_annotations_enabled(self):
if not self.user_annotations_enabled():
raise DisabledFeatureError("User annotations are disabled.")
def check_genesets_save_enabled(self):
if not self.genesets_save_enabled():
def check_gene_sets_save_enabled(self):
if not self.gene_sets_save_enabled():
raise DisabledFeatureError("User genesets save is disabled.")
def load_ontology(self, path):
@@ -80,12 +80,12 @@ class Annotations(metaclass=ABCMeta):
pass
@abstractmethod
def read_genesets(self, data_adaptor):
def read_gene_sets(self, data_adaptor):
"""Return the genesets from persistent storage """
pass
@abstractmethod
def write_genesets(self, gs, data_adaptor):
def write_gene_sets(self, gs, data_adaptor):
"""Write the genesets (gs) to a persistent storage such that it can later be read"""
pass
@@ -95,16 +95,16 @@ class Annotations(metaclass=ABCMeta):
pass
Genesets_Header = [
"geneset_name",
"geneset_description",
"gene_set_name",
"gene_set_description",
"gene_symbol",
"gene_description",
]
@staticmethod
def genesets_to_csv(genesets):
def gene_sets_to_csv(genesets):
"""
Convert the internal genesets format (returned by read_geneset) into
Convert the internal genesets format (returned by read_gene_set) into
the simple Tidy CSV.
"""
from io import StringIO
@@ -136,9 +136,9 @@ class Annotations(metaclass=ABCMeta):
return sio.getvalue()
@staticmethod
def genesets_to_response(genesets):
def gene_sets_to_response(genesets):
"""
Convert the internal genesets format (returned by read_geneset) into
Convert the internal genesets format (returned by read_gene_set) into
the dict expected by the JSON REST API
"""
return list(genesets.values())

View File

@@ -17,14 +17,14 @@ from local_server.common.errors import AnnotationsError, ObsoleteRequest
class AnnotationsLocalFile(Annotations):
CXG_ANNO_COLLECTION = "cxg_anno_collection"
def __init__(self, config, output_dir, label_output_file, genesets_output_file):
def __init__(self, config, output_dir, label_output_file, gene_sets_output_file):
super().__init__(config)
self.output_dir = output_dir
self.label_output_file = label_output_file
self.genesets_output_file = genesets_output_file
self.gene_sets_output_file = gene_sets_output_file
# lock used to protect label file write ops
self.label_lock = threading.RLock()
self.genesets_lock = threading.RLock()
self.gene_sets_lock = threading.RLock()
# cache the most recent annotations.
self.last_fname = None
@@ -105,29 +105,29 @@ class AnnotationsLocalFile(Annotations):
self.last_fname = fname
self.last_labels = df
def read_genesets(self, data_adaptor, context=None):
def read_gene_sets(self, data_adaptor, context=None):
if has_request_context():
if not current_app.auth.is_user_authenticated():
return ({}, self.last_geneset_tid)
fname = self._get_genesets_filename(data_adaptor)
genesets = {}
gene_sets = {}
tid = None
with self.genesets_lock:
with self.gene_sets_lock:
tid = self.last_geneset_tid # inside the critical section
if fname is not None and os.path.exists(fname) and os.path.getsize(fname) > 0:
with open(fname, newline="") as f:
genesets = read_geneset_tidycsv(f, context)
gene_sets = read_gene_set_tidycsv(f, context)
return (genesets, tid)
return (gene_sets, tid)
def write_genesets(self, genesets, tid, data_adaptor):
self.check_genesets_save_enabled() # raises
def write_gene_sets(self, gene_sets, tid, data_adaptor):
self.check_gene_sets_save_enabled() # raises
if type(tid) != int or tid < 0:
raise ValueError("tid must be a positive integer")
with self.genesets_lock:
with self.gene_sets_lock:
# skip if the request is stale
if tid is not None:
if tid <= self.last_geneset_tid:
@@ -137,7 +137,7 @@ class AnnotationsLocalFile(Annotations):
lastmod = data_adaptor.get_last_mod_time()
lastmodstr = "'unknown'" if lastmod is None else lastmod.isoformat(timespec="seconds")
header = (
f"# Geneset generated on {datetime.now().isoformat(timespec='seconds')} "
f"# Gene set generated on {datetime.now().isoformat(timespec='seconds')} "
f"using cellxgene version {cellxgene_version}\n"
f"# Input data file was {data_adaptor.get_location()}, "
f"which was last modified on {lastmodstr}\n"
@@ -147,7 +147,7 @@ class AnnotationsLocalFile(Annotations):
self._backup(fname)
with open(fname, "w", newline="") as f:
f.write(header)
f.write(self.genesets_to_csv(genesets))
f.write(self.gene_sets_to_csv(gene_sets))
def _get_userdata_idhash(self, data_adaptor):
"""
@@ -163,7 +163,7 @@ class AnnotationsLocalFile(Annotations):
if self.output_dir:
return self.output_dir
output_file = self.label_output_file or self.genesets_output_file
output_file = self.label_output_file or self.gene_sets_output_file
if output_file:
return os.path.dirname(os.path.abspath(output_file))
@@ -177,9 +177,9 @@ class AnnotationsLocalFile(Annotations):
return self._get_filename(data_adaptor, "celllabels")
def _get_genesets_filename(self, data_adaptor):
""" return the current genesets file name """
if self.genesets_output_file:
return self.genesets_output_file
""" return the current gene sets file name """
if self.gene_sets_output_file:
return self.gene_sets_output_file
return self._get_filename(data_adaptor, "genesets")
@@ -236,7 +236,7 @@ class AnnotationsLocalFile(Annotations):
def update_parameters(self, parameters, data_adaptor):
params = {}
params["annotations"] = self.user_annotations_enabled()
params["annotations_genesets_readonly"] = not self.genesets_save_enabled()
params["annotations_genesets_readonly"] = not self.gene_sets_save_enabled()
params["user_annotation_collection_name_enabled"] = True
if self.ontology_data:
@@ -263,7 +263,7 @@ class AnnotationsLocalFile(Annotations):
parameters.update(params)
def read_geneset_tidycsv(f, context=None):
def read_gene_set_tidycsv(f, context=None):
"""
Read & parse the Tidy CSV format, applying validation checks for mandatory
values, and de-duping rules.
@@ -271,9 +271,9 @@ def read_geneset_tidycsv(f, context=None):
Format is a four-column CSV, with a mandatory header row, and optional "#" prefixed
comments. Format:
geneset_name, geneset_description, gene_symbol, gene_description
gene_set_name, gene_set_description, gene_symbol, gene_description
geneset_name and gene_symbol must be non-null; others are optional.
gene_set_name must be non-null; others are optional.
Returns: a dictionary of the shape (values in angle-brackets vary):
@@ -305,7 +305,7 @@ def read_geneset_tidycsv(f, context=None):
messagefn = context["messagefn"] if context else (lambda x: None)
reader = csv.reader(f, dialect=myDialect())
genesets = {}
gene_sets = {}
haveReadHeader = False
lineno = 0
for row in reader:
@@ -329,10 +329,10 @@ def read_geneset_tidycsv(f, context=None):
if (not gene_symbol) and gene_description:
messagefn(f"Warning: Missing gene name in geneset name {geneset_name} on line {lineno}.")
if geneset_name in genesets:
gs = genesets[geneset_name]
if geneset_name in gene_sets:
gs = gene_sets[geneset_name]
else:
gs = genesets[geneset_name] = {
gs = gene_sets[geneset_name] = {
"geneset_name": geneset_name,
"geneset_description": geneset_description,
"genes": [],
@@ -349,4 +349,4 @@ def read_geneset_tidycsv(f, context=None):
}
)
return genesets
return gene_sets

View File

@@ -45,7 +45,7 @@ def get_client_config(app_config, data_adaptor):
"annotations_file": None,
"annotations_dir": None,
"annotations_genesets": True, # feature flag
"annotations_genesets_readonly": dataset_config.user_annotations__genesets__readonly,
"annotations_genesets_readonly": dataset_config.user_annotations__gene_sets__readonly,
"annotations_genesets_summary_methods": ["mean"],
"annotations_cell_ontology_enabled": False,
"annotations_cell_ontology_obopath": None,

View File

@@ -32,9 +32,9 @@ class DatasetConfig(BaseConfig):
self.user_annotations__ontology__obo_location = default_config["user_annotations"]["ontology"][
"obo_location"
]
self.user_annotations__genesets__readonly = default_config["user_annotations"]["genesets"]["readonly"]
self.user_annotations__local_file_csv__genesets_file = default_config["user_annotations"]["local_file_csv"][
"genesets_file"
self.user_annotations__gene_sets__readonly = default_config["user_annotations"]["gene_sets"]["readonly"]
self.user_annotations__local_file_csv__gene_sets_file = default_config["user_annotations"]["local_file_csv"][
"gene_sets_file"
]
self.embeddings__names = default_config["embeddings"]["names"]
@@ -99,15 +99,15 @@ class DatasetConfig(BaseConfig):
"user_annotations__local_file_csv__file", (type(None), str)
)
self.validate_correct_type_of_configuration_attribute(
"user_annotations__local_file_csv__genesets_file", (type(None), str)
"user_annotations__local_file_csv__gene_sets_file", (type(None), str)
)
self.validate_correct_type_of_configuration_attribute("user_annotations__ontology__enable", bool)
self.validate_correct_type_of_configuration_attribute(
"user_annotations__ontology__obo_location", (type(None), str)
)
self.validate_correct_type_of_configuration_attribute("user_annotations__genesets__readonly", bool)
self.validate_correct_type_of_configuration_attribute("user_annotations__gene_sets__readonly", bool)
if self.user_annotations__enable or not self.user_annotations__genesets__readonly:
if self.user_annotations__enable or not self.user_annotations__gene_sets__readonly:
server_config = self.app_config.server_config
if not self.app__authentication_enable:
raise ConfigurationError("user annotations requires authentication to be enabled")
@@ -134,7 +134,7 @@ class DatasetConfig(BaseConfig):
def handle_local_file_csv_annotations(self, context):
dirname = self.user_annotations__local_file_csv__directory
filename = self.user_annotations__local_file_csv__file
genesets_filename = self.user_annotations__local_file_csv__genesets_file
genesets_filename = self.user_annotations__local_file_csv__gene_sets_file
if dirname is not None and (filename is not None or genesets_filename is not None):
raise ConfigurationError(
@@ -159,7 +159,7 @@ class DatasetConfig(BaseConfig):
anno_config = {
"user-annotations": self.user_annotations__enable,
"genesets-save": not self.user_annotations__genesets__readonly,
"genesets-save": not self.user_annotations__gene_sets__readonly,
}
self.user_annotations = AnnotationsLocalFile(anno_config, dirname, filename, genesets_filename)
@@ -170,9 +170,9 @@ class DatasetConfig(BaseConfig):
data_adaptor = self.get_data_adaptor()
if self.user_annotations__local_file_csv__file:
data_adaptor.check_new_labels(self.user_annotations.read_labels(data_adaptor))
if self.user_annotations__local_file_csv__genesets_file:
if self.user_annotations__local_file_csv__gene_sets_file:
try:
data_adaptor.check_new_genesets(self.user_annotations.read_genesets(data_adaptor, context), context)
data_adaptor.check_new_gene_sets(self.user_annotations.read_gene_sets(data_adaptor, context), context)
except (ValueError, AnnotationsError, KeyError) as e:
raise ConfigurationError(f"Unable to read genesets CSV file: {str(e)}") from e

View File

@@ -336,11 +336,11 @@ def genesets_get(request, data_adaptor):
try:
annotations = data_adaptor.dataset_config.user_annotations
(genesets, tid) = data_adaptor.check_new_genesets(annotations.read_genesets(data_adaptor))
(genesets, tid) = data_adaptor.check_new_gene_sets(annotations.read_gene_sets(data_adaptor))
if preferred_mimetype == "text/csv":
return make_response(
annotations.genesets_to_csv(genesets),
annotations.gene_sets_to_csv(genesets),
HTTPStatus.OK,
{
"Content-Type": "text/csv",
@@ -349,7 +349,7 @@ def genesets_get(request, data_adaptor):
)
else:
return make_response(
jsonify({"genesets": annotations.genesets_to_response(genesets), "tid": tid}), HTTPStatus.OK
jsonify({"genesets": annotations.gene_sets_to_response(genesets), "tid": tid}), HTTPStatus.OK
)
except (ValueError, KeyError, AnnotationsError) as e:
return abort_and_log(HTTPStatus.BAD_REQUEST, str(e))
@@ -357,7 +357,7 @@ def genesets_get(request, data_adaptor):
def genesets_put(request, data_adaptor):
annotations = data_adaptor.dataset_config.user_annotations
if not annotations.genesets_save_enabled():
if not annotations.gene_sets_save_enabled():
return abort(HTTPStatus.NOT_IMPLEMENTED)
anno_collection = request.args.get("annotation-collection-name", default=None)
@@ -373,8 +373,8 @@ def genesets_put(request, data_adaptor):
if genesets is None:
abort(HTTPStatus.BAD_REQUEST)
(gs, _) = data_adaptor.check_new_genesets((genesets, tid))
annotations.write_genesets(gs, tid, data_adaptor)
(gs, _) = data_adaptor.check_new_gene_sets((genesets, tid))
annotations.write_gene_sets(gs, tid, data_adaptor)
return make_response(jsonify({"status": "OK"}), HTTPStatus.OK)
except (ValueError, DisabledFeatureError, KeyError) as e:
return abort_and_log(HTTPStatus.BAD_REQUEST, str(e), include_exc_info=True)

View File

@@ -262,7 +262,7 @@ class DataAdaptor(metaclass=ABCMeta):
return labels_df
def check_new_genesets(self, args, context=None):
def check_new_gene_sets(self, args, context=None):
"""
Check validity of gene sets, return if correct, else raise error.
May also modify the gene set for conditions that should be resolved,

View File

@@ -64,12 +64,12 @@ dataset:
local_file_csv:
directory: null
file: null # annotations file name
genesets_file: null # gene sets file name
gene_sets_file: null # gene sets file name
ontology:
enable: false
obo_location: null
genesets:
readonly: false # genesets CRUD enabled/disabled
gene_sets:
readonly: false # gene sets CRUD enabled/disabled
embeddings:
names : []

View File

@@ -16,12 +16,12 @@ dataset:
local_file_csv:
directory: {local_file_csv_directory}
file: {local_file_csv_file}
genesets_file: {local_file_csv_genesets_file}
gene_sets_file: {local_file_csv_gene_sets_file}
ontology:
enable: {ontology_enabled}
obo_location: {obo_location}
genesets:
readonly: {genesets_readonly}
gene_sets:
readonly: {gene_sets_readonly}
embeddings:
names: {embedding_names}

View File

@@ -1,12 +1,12 @@
# Test fixture
geneset_name, geneset_description, gene_symbol, gene_description
first geneset name,,F5, a gene_description
first geneset name,a description, NO_SUCH_GENE, non-existent gene
first geneset name,a description, F5, duplicate gene
first geneset name, a description, SUMO3,
first geneset name,, SRM,
second geneset,,RER1
second geneset,,SIK1
third geneset,,NO_SUCH_GENE
fourth_geneset,fourth description,,gene intentionally missing
gene_set_name, gene_set_description, gene_symbol, gene_description
first gene set name,,F5, a gene_description
first gene set name,a description, NO_SUCH_GENE, non-existent gene
first gene set name,a description, F5, duplicate gene
first gene set name, a description, SUMO3,
first gene set name,, SRM,
second gene set,,RER1
second gene set,,SIK1
third gene set,,NO_SUCH_GENE
fourth_gene_set,fourth description,,gene intentionally missing
fifth_dataset,,,
1 # Test fixture
2 geneset_name, geneset_description, gene_symbol, gene_description gene_set_name, gene_set_description, gene_symbol, gene_description
3 first geneset name,,F5, a gene_description first gene set name,,F5, a gene_description
4 first geneset name,a description, NO_SUCH_GENE, non-existent gene first gene set name,a description, NO_SUCH_GENE, non-existent gene
5 first geneset name,a description, F5, duplicate gene first gene set name,a description, F5, duplicate gene
6 first geneset name, a description, SUMO3, first gene set name, a description, SUMO3,
7 first geneset name,, SRM, first gene set name,, SRM,
8 second geneset,,RER1 second gene set,,RER1
9 second geneset,,SIK1 second gene set,,SIK1
10 third geneset,,NO_SUCH_GENE third gene set,,NO_SUCH_GENE
11 fourth_geneset,fourth description,,gene intentionally missing fourth_gene_set,fourth description,,gene intentionally missing
12 fifth_dataset,,,

View File

@@ -14,7 +14,7 @@ class AuthTest(unittest.TestCase):
app_config = AppConfig()
app_config.update_server_config(app__flask_secret_key="secret")
app_config.update_server_config(authentication__type=None, single_dataset__datapath=self.dataset_datapath)
app_config.update_dataset_config(user_annotations__enable=False, user_annotations__genesets__readonly=True)
app_config.update_dataset_config(user_annotations__enable=False, user_annotations__gene_sets__readonly=True)
app_config.complete_config()

View File

@@ -92,10 +92,10 @@ class ConfigTests(unittest.TestCase):
hosted_file_directory="null",
local_file_csv_directory="null",
local_file_csv_file="null",
local_file_csv_genesets_file="null",
local_file_csv_gene_sets_file="null",
ontology_enabled="false",
obo_location="null",
genesets_readonly="false",
gene_sets_readonly="false",
embedding_names=[],
enable_reembedding="false",
enable_difexp="true",
@@ -144,10 +144,10 @@ class ConfigTests(unittest.TestCase):
hosted_file_directory=hosted_file_directory,
local_file_csv_directory=local_file_csv_directory,
local_file_csv_file=local_file_csv_file,
local_file_csv_genesets_file=local_file_csv_genesets_file,
local_file_csv_gene_sets_file=local_file_csv_gene_sets_file,
ontology_enabled=ontology_enabled,
obo_location=obo_location,
genesets_readonly=genesets_readonly,
gene_sets_readonly=gene_sets_readonly,
embedding_names=embedding_names,
enable_reembedding=enable_reembedding,
enable_difexp=enable_difexp,
@@ -182,10 +182,10 @@ class ConfigTests(unittest.TestCase):
hosted_file_directory="null",
local_file_csv_directory="null",
local_file_csv_file="null",
local_file_csv_genesets_file="null",
local_file_csv_gene_sets_file="null",
ontology_enabled="false",
obo_location="null",
genesets_readonly="false",
gene_sets_readonly="false",
embedding_names=[],
enable_reembedding="false",
enable_difexp="true",

View File

@@ -388,7 +388,7 @@ class EndPointsAnndata(unittest.TestCase, EndPoints):
[
f"{PROJECT_ROOT}/example-dataset/pbmc3k.h5ad",
"--disable-annotations",
"--disable-genesets-save",
"--disable-gene-sets-save",
"--experimental-enable-reembedding",
],
)
@@ -465,7 +465,7 @@ class EndPointsAnnDataGenesets(unittest.TestCase, EndPoints):
[
f"{PROJECT_ROOT}/example-dataset/pbmc3k.h5ad",
"--disable-annotations",
"--genesets-file",
"--gene-sets-file",
genesets_file,
],
)
@@ -496,7 +496,7 @@ class EndPointsAnnDataGenesets(unittest.TestCase, EndPoints):
{"gene_description": "", "gene_symbol": "SRM"},
],
"geneset_description": "a description",
"geneset_name": "first geneset name",
"geneset_name": "first gene set name",
},
{
"genes": [
@@ -504,10 +504,10 @@ class EndPointsAnnDataGenesets(unittest.TestCase, EndPoints):
{"gene_description": "", "gene_symbol": "SIK1"},
],
"geneset_description": "",
"geneset_name": "second geneset",
"geneset_name": "second gene set",
},
{"genes": [], "geneset_description": "", "geneset_name": "third geneset"},
{"genes": [], "geneset_description": "fourth description", "geneset_name": "fourth_geneset"},
{"genes": [], "geneset_description": "", "geneset_name": "third gene set"},
{"genes": [], "geneset_description": "fourth description", "geneset_name": "fourth_gene_set"},
{"genes": [], "geneset_description": "", "geneset_name": "fifth_dataset"},
],
"tid": 0,
@@ -522,14 +522,14 @@ class EndPointsAnnDataGenesets(unittest.TestCase, EndPoints):
self.assertEqual(result.headers["Content-Type"], "text/csv")
self.assertEqual(
result.text,
"""geneset_name,geneset_description,gene_symbol,gene_description\r
first geneset name,a description,F5,a gene_description\r
first geneset name,a description,SUMO3,\r
first geneset name,a description,SRM,\r
second geneset,,RER1,\r
second geneset,,SIK1,\r
third geneset,,,\r
fourth_geneset,fourth description,,\r
"""gene_set_name,gene_set_description,gene_symbol,gene_description\r
first gene set name,a description,F5,a gene_description\r
first gene set name,a description,SUMO3,\r
first gene set name,a description,SRM,\r
second gene set,,RER1,\r
second gene set,,SIK1,\r
third gene set,,,\r
fourth_gene_set,fourth description,,\r
fifth_dataset,,,\r
""",
)