create_db¶
gffbase.create_db.create_db ¶
create_db(data, dbfn, id_spec=None, force=False, verbose=False, checklines=10, merge_strategy='error', transform=None, gtf_transcript_key='transcript_id', gtf_gene_key='gene_id', gtf_subfeature='exon', force_gff=False, force_dialect_check=False, from_string=False, keep_order=False, text_factory=str, force_merge_fields=None, pragmas=None, sort_attribute_values=False, dialect=None, _keep_tempfiles=False, infer_gene_extent=True, disable_infer_genes=False, disable_infer_transcripts=False, mode='compat', validation=None, on_error=None, on_multipart_conflict='error', **kwargs) -> FeatureDB
Create a database from a GFF3/GTF source.
Parameters¶
data :
Path to a GFF3/GTF file (optionally gzipped), or the file contents
themselves when from_string=True.
dbfn :
Destination database path, or ":memory:".
id_spec :
Primary-key policy. None uses the per-dialect default: "ID" for
GFF3, {"gene": "gene_id", "transcript": "transcript_id"} for GTF.
May also be an attribute name, an ordered list of names (first match
wins), a featuretype -> name mapping, or a callable returning an id
(or "autoincrement:BASE"). A name of the form ":seqid:" reads
that GFF column instead of an attribute.
force :
Overwrite dbfn if it exists. Without it, an existing file raises.
verbose :
Progress reporting. "debug" selects DEBUG level.
checklines :
Lines sampled to infer the dialect.
merge_strategy :
What to do when two features resolve to the same id: "error",
"warning", "merge", "create_unique" or "replace".
transform :
Callable applied to each feature. Returning anything falsy drops it.
gtf_transcript_key, gtf_gene_key, gtf_subfeature :
Attribute names used to reconstruct GTF hierarchy.
force_gff :
Skip format autodetection and treat the input as GFF.
force_dialect_check :
Infer the dialect from every line rather than the first checklines.
Mutually exclusive with dialect.
from_string :
Treat data as file contents rather than a path.
keep_order :
Preserve attribute order when features are rendered.
text_factory :
Text coercion applied to values read back out.
force_merge_fields :
With merge_strategy="merge", fields allowed to differ and be
combined. start/end are rejected: they must stay numeric.
pragmas :
Database pragmas.
sort_attribute_values :
Sort attribute values when features are rendered.
dialect :
Explicit dialect, bypassing inference.
infer_gene_extent :
Deprecated. False sets both disable_infer_* flags.
disable_infer_genes, disable_infer_transcripts :
Skip synthesizing GTF gene/transcript rows from their children.
mode : {"compat", "strict"}
"compat" (default) applies gffutils' rule set, so files that break
the GFF3 specification load exactly as they do under gffutils, with
every violation recorded in FeatureDB.warnings. "strict"
applies the full NCBI specification and rejects violations.
``"strict"`` is also the only mode that fuses several lines sharing one
``ID`` into a single discontinuous feature. That is deliberate: it is
new behaviour rather than gffutils behaviour, since gffutils'
``merge_strategy="merge"`` requires all eight non-attribute columns to
match and so never merges a genuine split feature.
validation : {"gffutils", "ncbi"} | None
Which rule set to apply, overriding the one mode implies. None
(default) takes the mode's. Use it to keep gffutils-compatible
handling while applying the full NCBI rules -- the combination
validation="ncbi", on_error="warn" audits a file without stopping
on it, leaving every violation in FeatureDB.warnings.
on_error : {"raise", "warn"} | None
What a rejected line does, overriding the one mode implies.
"raise" stops at the first violation; "warn" records it and
carries on. None (default) takes the mode's.
on_multipart_conflict : {"error", "split"}
Under mode="strict", what to do when lines sharing an ID
disagree on seqid, source, featuretype or strand -- which GFF3 requires
the segments of a discontinuous feature to share. "error" (default)
raises :class:~gffbase.exceptions.MultipartConstraintError naming the
diverging column and both line numbers; "split" partitions the run
by those four columns, the lowest file_order keeping the bare id.
Returns¶
FeatureDB
Source code in python/gffbase/create_db.py
51 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 103 104 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 213 214 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 | |
gffbase.ingest.from_file¶
Lower-level ingestion entrypoint used by create_db. Returns the raw
(duckdb.Connection, IngestStats) pair.
gffbase.ingest.from_file ¶
from_file(path: str, dbfn: str = ':memory:', **kwargs) -> tuple[duckdb.DuckDBPyConnection, IngestStats]
Ingest a GFF3 or GTF file into a DuckDB database, atomically.
The destination either does not exist or is a complete database: the ingest writes to a scratch file beside it and renames on success, so a failure part-way leaves nothing behind and an existing database is not destroyed until its replacement is finished.
Before this, a failed ingest left a file that was valid DuckDB but held no
data and no meta rows. Retrying then refused with "already exists. Pass
force=True", and opening it silently produced an empty database that
reported itself as current -- the two ways this could mislead someone were
to make them force-overwrite something, or to believe their data had
loaded.
See _build_database for the ingest itself and the full argument list.
Source code in python/gffbase/ingest.py
gffbase.ingest.IngestStats¶
gffbase.ingest.IngestStats
dataclass
¶
IngestStats(n_features_raw: int = 0, n_features_synthetic_transcripts: int = 0, n_features_synthetic_genes: int = 0, n_attributes: int = 0, n_edges: int = 0, n_closure_rows: int = 0, rtree_built: bool = False, fmt: str = 'gff3', dialect: dict = None, directives: list[str] = None, warnings: list[dict] = None, n_skipped: int = 0, n_multipart: int = 0)
Reported back to the caller for benchmarking and tests.