crispr_analysis_utils.guide_annotation.db¶
crispr_analysis_utils.guide_annotation.db ¶
The annotation store: a GENCODE GTF reduced to what annotating needs.
Reading a full GENCODE takes most of a minute, so a run reads this instead.
The store is parquet, which pyranges1 loads in about a second.
FEATURES
module-attribute
¶
FEATURES = ('gene', 'transcript', 'exon', 'CDS', 'UTR')
The feature rows the store keeps. Everything else is dropped.
GENE_TYPES
module-attribute
¶
GENE_TYPES = ('protein_coding',)
The gene types a guide is annotated against.
Every call of genic, exon, intron and promoter follows these. Genes of other types are kept as one row each, so a protospacer overlapping one can be reported without that overlap deciding where the guide sits.
COLUMNS
module-attribute
¶
COLUMNS = ('Chromosome', 'Start', 'End', 'Strand', 'Feature', 'ensg', 'gene_symbol', 'enst', 'exon_id', 'exon_number', 'is_reference', 'gene_type')
The store's columns. The first four are what pyranges needs.
StoreError ¶
Bases: RuntimeError
The store is missing, unreadable, or holds no usable annotation.
Source code in src/crispr_analysis_utils/guide_annotation/db.py
48 49 | |
Store
dataclass
¶
A loaded annotation store.
Attributes:
-
features(DataFrame) –Every kept row: genes, transcripts, exons, CDS and UTR.
-
provenance(dict) –What the store was built from, as
build_storerecorded it.
Source code in src/crispr_analysis_utils/guide_annotation/db.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
gene_types
property
¶
gene_types: tuple[str, ...]
The gene types this store's annotation is called against.
rows ¶
rows(feature: str, *, reference_only: bool = False, primary: bool = True) -> pd.DataFrame
The rows of one feature.
Parameters:
-
feature(str) –One of
FEATURES. -
reference_only(bool, default:False) –Keep only the reference transcript's rows.
-
primary(bool, default:True) –Keep only genes of
gene_types. On by default, so a store that also carries other gene types cannot widen what counts as genic.
Source code in src/crispr_analysis_utils/guide_annotation/db.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
other_genes ¶
other_genes() -> pd.DataFrame
Gene rows whose type is not one the annotation is called against.
Source code in src/crispr_analysis_utils/guide_annotation/db.py
94 95 96 97 | |
build_store ¶
build_store(gtf: str | PathLike[str], out: str | PathLike[str], *, gene_types: tuple[str, ...] = GENE_TYPES) -> Store
Reduce a GENCODE GTF to an annotation store.
Parameters:
-
gtf(str | PathLike[str]) –A GENCODE GTF, gzipped or not. It must hold
transcriptandexonrows: a genes-only GTF cannot say exon, intron or transcript. -
out(str | PathLike[str]) –The parquet file to write.
-
gene_types(tuple[str, ...], default:GENE_TYPES) –The gene types a guide is annotated against: genic, exon, intron and promoter all follow these, and every feature row is kept for them. Genes of every other type are kept as one row each, so an overlap can be reported without it deciding where the guide sits.
Returns:
-
Store–The store just written.
Raises:
-
StoreError–The GTF holds no gene of those types, or no exons.
Source code in src/crispr_analysis_utils/guide_annotation/db.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
load_store ¶
load_store(path: str | PathLike[str]) -> Store
Load a store written by build_store.
Parameters:
-
path(str | PathLike[str]) –The parquet file.
Returns:
-
Store–Its rows and its provenance.
Raises:
-
StoreError–The file is missing, or was not written by
build_store.
Source code in src/crispr_analysis_utils/guide_annotation/db.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |