spacr.gene_tile¶
Resolve regression features to gene identities and screen statistics.
The gene_tile() function combines a regression feature with optional
coefficient, gRNA-reference, annotation, and localisation data. It returns a
GeneTile that can be rendered by the GUI or used independently.
Guide identifiers are resolved with spacr.hits.gene_of(). When the same
protospacer occurs under more than one gene in the supplied gRNA reference,
all candidate genes are retained and the mapping is marked as ambiguous.
Missing references or annotations are described in the returned record rather
than represented by an empty panel.
Bundled reference tables are read locally and cached. External database URLs are constructed for the user to open; this module does not fetch them.
Classes¶
One gene the clicked feature could be naming. |
|
Everything spaCR can say about one clicked point, in reading order. |
|
One guide of this gene, and how it behaved in this screen. |
|
An external record for this gene: a label and a URL to open. |
Functions¶
|
Build a gene record for a regression feature. |
|
Is |
|
The ToxoDB gene record page for a full accession. Never fetched. |
|
|
|
A UniProt link for this gene: the record when known, else a search. |
Module Contents¶
- class spacr.gene_tile.GeneCandidate[source]¶
One gene the clicked feature could be naming.
Usually there is exactly one. There is more than one when the guide’s protospacer sits in more than one gene, and then every one of them is here with whatever is known about it, because picking one would be inventing a result.
- Parameters:
gene – the bare gene id, as every spaCR table keys it (
411710).accession – the library’s own accession (
TGGT1_411710), when the gRNA reference names a strain;""when nothing said which strain.annotation_id – the
Gene IDof the annotation row that matched (TGME49_239740), or""when none did.product – the product description, or
"".symbol – the gene symbol, or
"".localisation – TAGM/LOPIT subcellular localisation, or
"".aliases – every other name this gene is known by here.
fields – the annotation columns worth showing, as
((label, value), ...)in reading order, gaps already dropped.annotation – the whole matched annotation row, for a caller that wants a column this module does not show.
reported –
Truefor the gene the regression itself attributed the reads to — the one a naive resolver would have picked alone.notes – what could not be resolved ABOUT THIS GENE, in sentences.
- class spacr.gene_tile.GeneTile[source]¶
Everything spaCR can say about one clicked point, in reading order.
Identity, then this screen’s numbers, then what spaCR already knew, then a link out — because a user who clicked a point wants to know what they clicked before they want a bibliography.
- Parameters:
feature – the string that was clicked, verbatim.
kind – what the feature turned out to be —
guide,gene,control,nuisanceorunresolved.guide – the guide id, for a guide term;
""otherwise.gene – the gene id the regression attributed the reads to.
candidates – every gene the feature could name, the reported one first. Length > 1 means
ambiguous.ambiguous –
Truewhen the guide’s protospacer sits in more than one gene, so the effect cannot be assigned to any one of them.ambiguity – the sentence explaining that, or
"".protospacer – the guide’s sequence, when the reference had it.
effect – the clicked term’s coefficient.
p_value – its p-value.
q_value – Its q-value, or the uncorrected p-value stored in the
q_valuecolumn whencorrectionis"none".correction – The multiple-testing method recorded by the run. When this is
"none", the tile labels the storedq_valueexplicitly as an uncorrected p-value.condition –
control/pc/nc/other, as fitted.n_obs – the observation count the results row carried.
n_obs_column – which column that count came from,
n_grnaorn_gene. Named rather than relabelled: the two count different things and only the run knows which one a row carries.gene_effect – the gene-level coefficient for this gene.
gene_p_value – its p-value.
gene_q_value – its q-value.
guides – every guide of this gene that was fitted, and how it moved.
n_agree – how many of them agree in sign with the gene effect.
unresolved – what could not be worked out, in sentences. NEVER empty when something is missing — this is the field that stops the tile reading as a bug.
notes – everything else worth saying that is not a failure.
- sections(translator: Callable[..., str] | None = None) Tuple[Tuple[str, Tuple[Tuple[str, str], ...]], ...][source]¶
The tile as
((heading, ((label, value), ...)), ...).The one ordering, defined once, so the Qt tile, the text form and the HTML form cannot drift into presenting the same record three ways.
translatorlocalizes presentation labels and structured messages; identifiers, measurements, annotations, and URLs remain unchanged.
- to_html(translator: Callable[..., str] | None = None) str[source]¶
The tile as HTML, for a Qt rich-text view.
- to_text(translator: Callable[..., str] | None = None) str[source]¶
The tile as plain text — what a test reads and a log records.
- class spacr.gene_tile.GuideRow[source]¶
One guide of this gene, and how it behaved in this screen.
- Parameters:
guide – the guide id as the results table carries it (
239740_3).feature – the model term it came from.
effect – the fitted coefficient.
p_value – its p-value.
q_value – its q-value, as the run reported one.
n_obs – the
n_grnacount behind it.agrees – whether it pushes the same way as the gene-level effect;
Nonewhen there is no gene-level effect to compare against, which is different from disagreeing and is shown differently.clicked –
Truefor the guide the user actually clicked.
- class spacr.gene_tile.Reference[source]¶
An external record for this gene: a label and a URL to open.
- Parameters:
label – what to show, e.g.
ToxoDB TGGT1_239740.url – where it goes. Built by string formatting and NEVER fetched — see the module docstring.
- spacr.gene_tile.gene_tile(feature: Any, results: pandas.DataFrame | None = None, *, barcodes: Any = BUNDLED, metadata: Any = BUNDLED, localisation: Any = BUNDLED) GeneTile[source]¶
Build a gene record for a regression feature.
- Parameters:
feature (Any) – Model term such as
fraction:grna[239740_3]orgene_fraction:gene[239740]. Bare gRNA accessions and gene identifiers are also accepted.results (pandas.DataFrame or None, optional) – Regression coefficient table. When
None, identity and annotation are still resolved and the missing screen statistics are recorded inGeneTile.unresolved.barcodes ({BUNDLED, None}, path-like, or pandas.DataFrame, optional) – gRNA reference with
nameandsequencecolumns. UseBUNDLEDfor the packaged reference orNoneto skip protospacer lookup. Ambiguous mappings can be detected only when this reference contains the guide.metadata ({BUNDLED, None}, path-like, or pandas.DataFrame, optional) – Gene annotation keyed by
Gene ID. UseNoneto omit annotation.localisation ({BUNDLED, None}, path-like, or pandas.DataFrame, optional) – TAGM/LOPIT localisation table keyed by
gene_nr. UseNoneto omit localisation data.
- Returns:
GeneTile – Resolved identity, screen statistics, annotations, references, and explicit notes about missing or ambiguous data. Unrecognised features return an unresolved record rather than
None.
Notes
The function reads only local data. Values in
GeneTile.referencesare URLs for the caller to open and are not fetched while building the record.
- spacr.gene_tile.is_toxoplasma_gene_id(gene: Any) bool[source]¶
Is
geneshaped like a Toxoplasma gene id spaCR would recognise?- Parameters:
gene – a bare gene id (
239740), an accession (TGGT1_239740), or anything at all.- Returns:
Truefor a Toxoplasma-shaped id. The point of the check is the negative: an id from a screen of some other organism must not be handed a ToxoDB link, because a link to a record that does not exist is worse than no link.
- spacr.gene_tile.toxodb_url(accession: str) str[source]¶
The ToxoDB gene record page for a full accession. Never fetched.
- Parameters:
accession – full ToxoDB gene accession to place in the URL.
- spacr.gene_tile.uniprot_accessions() Dict[str, str][source]¶
{gene number: accession}from the bundled table.Cached: it is read to build one line of a gene tile, which happens every time a point is clicked.
Returns an empty mapping rather than raising when the file is absent – a screen of another organism has no reason to carry it, and a gene tile without a UniProt line is still a gene tile.
- spacr.gene_tile.uniprot_reference(accession: str, annotation=None)[source]¶
A UniProt link for this gene: the record when known, else a search.
- Parameters:
accession – the gene accession, e.g.
TGGT1_239740.annotation – the gene’s annotation row, if there is one.
- Returns:
(label, url, is_record), orNonewhen there is nothing useful to offer.
THE DISTINCTION MATTERS AND IS CARRIED IN THE LABEL. A record link says “this is the protein”; a search link says “here is the question”. Only one of those is a claim, and only one of them can be wrong in a way the reader cannot see – a fabricated record URL that happens to resolve opens a real page for a different protein and looks exactly like a correct link.