Data Models
The refget package uses Pydantic and SQLModel for data validation and database ORM. These models represent the core data structures for sequence collections, DRS objects, and related metadata.
!!! success “Data models” Data Models are only needed if you want to develop new packages that rely on the refget Python API.
Model hierarchy
Section titled “Model hierarchy”DrsObject (base)└── FastaDrsObject (table)
SQLModel (base)├── SequenceCollection (table)├── Pangenome (table)├── Sequence (table)├── AccessMethod├── AccessURL└── ChecksumCore Models
Section titled “Core Models”SequenceCollection
Section titled “SequenceCollection”The primary model representing a GA4GH sequence collection.
class SequenceCollection
Section titled “class SequenceCollection”A SQLModel/pydantic model that represents a refget sequence collection.
Properties
Section titled “Properties”digest: str
: Top-level digest of the SequenceCollection.
human_readable_names: List[HumanReadableNames]
lengths: LengthsAttr
: Array of sequence lengths.
lengths_digest: str
name_length_pairs: NameLengthPairsAttr
: Array of name-length pairs, representing the coordinate system of the collection.
name_length_pairs_digest: str
names: NamesAttr
: Array of sequence names.
names_digest: str
pangenomes: List[Pangenome]
sequences: SequencesAttr
: Array of sequence digests.
sequences_digest: str
sorted_name_length_pairs_digest: str
: Digest of the sorted name-length pairs, representing a unique digest of sort-invariant coordinate system.
sorted_sequences: SortedSequencesAttr
: Array of sorted sequence digests.
sorted_sequences_digest: str
Class Methods
Section titled “Class Methods”from_PySequenceCollection(gtars_seq_col: gtarsSequenceCollection)
Section titled “from_PySequenceCollection(gtars_seq_col: gtarsSequenceCollection)”Given a PySequenceCollection object (from Rust bindings), create a SequenceCollection object.
Args: gtars_seq_col (PySequenceCollection): PySequenceCollection object from Rust bindings.
Returns: (SequenceCollection): The SequenceCollection object.
Raises: ImportError: If gtars is not installed (required for this conversion)
from_dict(seqcol_dict: dict, inherent_attrs: Optional[list] = DEFAULT_INHERENT_ATTRS)
Section titled “from_dict(seqcol_dict: dict, inherent_attrs: Optional[list] = DEFAULT_INHERENT_ATTRS)”Given a dict representation of a sequence collection, create a SequenceCollection object. This is the primary way to create a SequenceCollection object.
Args: seqcol_dict (dict): Dictionary representation of a canonical sequence collection object inherent_attrs (list, optional): List of inherent attributes to digest
Returns: (SequenceCollection): The SequenceCollection object
from_fasta_file(fasta_file: str)
Section titled “from_fasta_file(fasta_file: str)”Given a FASTA file, create a SequenceCollection object.
Args: fasta_file (str): Path to a FASTA file
Returns: (SequenceCollection): The SequenceCollection object
Raises: ImportError: If gtars is not installed (required for FASTA processing)
Methods
Section titled “Methods”itemwise(limit = None)
Section titled “itemwise(limit = None)”Converts object into a list of dictionaries, one for each sequence in the collection.
level1()
Section titled “level1()”Converts object into dict of level 1 representation of the SequenceCollection.
Returns attribute digests for most attributes, but returns raw values for passthru attributes. Note: Passthru handling for dict-based construction happens in seqcol_dict_to_level1_dict(). When passthru attributes are added to the database model, return .value instead of .digest here.
level2()
Section titled “level2()”Converts object into dict of level 2 representation of the SequenceCollection.
FastaDrsObject
Section titled “FastaDrsObject”A DRS object specialized for FASTA files, storing file metadata and FAI index information.
class FastaDrsObject
Section titled “class FastaDrsObject”A DRS object specialized for FASTA sequence files. Stores file metadata including size, checksums (SHA-256, MD5, and refget sequence collection digest), and creation time. The refget digest serves as the object ID, enabling content-addressable retrieval.
Properties
Section titled “Properties”extra_line_bytes: Optional[int]
id: str
line_bases: Optional[int]
offsets: Optional[List[int]]
self_uri: Optional[str]
Class Methods
Section titled “Class Methods”from_fasta_file(fasta_file: str, digest: str = None)
Section titled “from_fasta_file(fasta_file: str, digest: str = None)”Given a FASTA file, create a FastaDrsObject object, return a populated FastaDrsObject with computed size and checksum.
Args: fasta_file (str): Path to a FASTA file digest (str): The refget digest of the sequence collection (optional). If not included, it will be computed
Returns: (FastaDrsObject): The FastaDrsObject object
Raises: ImportError: If gtars is not installed (required for FASTA processing)
Methods
Section titled “Methods”to_response(base_uri: str = None)
Section titled “to_response(base_uri: str = None)”Return a copy of this object with self_uri populated for API response.
Args: base_uri: Base URI for the DRS service (e.g., “drs://seqcolapi.databio.org”) If not provided, returns self unchanged.
Returns: FastaDrsObject with self_uri populated
DrsObject
Section titled “DrsObject”Base model for GA4GH Data Repository Service (DRS) objects.
class DrsObject
Section titled “class DrsObject”A data object representing a single blob of bytes with metadata, checksums, and access methods. DRS objects are self-contained and provide all information needed for clients to retrieve the data. Conforms to GA4GH Data Repository Service (DRS) specification v1.4.0.
Properties
Section titled “Properties”access_methods: List[AccessMethod]
aliases: List[str]
checksums: List[Checksum]
created_time: datetime
description: Optional[str]
id: str
mime_type: Optional[str]
name: Optional[str]
self_uri: str
size: int
updated_time: Optional[datetime]
version: Optional[str]
Class Methods
Section titled “Class Methods”coerce_access_methods(v)
Section titled “coerce_access_methods(v)”Coerce dicts to AccessMethod objects when loading from JSON.
coerce_checksums(v)
Section titled “coerce_checksums(v)”Coerce dicts to Checksum objects when loading from JSON.
Methods
Section titled “Methods”serialize_access_methods(v)
Section titled “serialize_access_methods(v)”Serialize AccessMethod objects (or dicts) to dicts for JSON output.
serialize_checksums(v)
Section titled “serialize_checksums(v)”Serialize Checksum objects (or dicts) to dicts for JSON output.
Pangenome
Section titled “Pangenome”A collection of sequence collections representing a pangenome.
class Pangenome
Section titled “class Pangenome”Properties
Section titled “Properties”collections: List[SequenceCollection]
collections_digest: str
digest: str
names: CollectionNamesAttr
names_digest: str
Class Methods
Section titled “Class Methods”from_dict(pangenome_obj: dict, inherent_attrs: Optional[list] = None)
Section titled “from_dict(pangenome_obj: dict, inherent_attrs: Optional[list] = None)”Given a dict representation of a pangenome, create a Pangenome object. This is the primary way to create a Pangenome object.
Args: pangenome_obj (dict): Dictionary representation of a canonical pangenome object
Returns: (Pangenome): The Pangenome object
Methods
Section titled “Methods”level1()
Section titled “level1()”Converts object into dict of level 1 representation of the Pangenome.
level2()
Section titled “level2()”Converts object into dict of level 2 representation of the Pangenome.
level3()
Section titled “level3()”Converts object into dict of level 3 representation of the Pangenome.
level4()
Section titled “level4()”Converts object into dict of level 4 representation of the Pangenome.
Sequence
Section titled “Sequence”An individual sequence with its digest and content.
class Sequence
Section titled “class Sequence”Properties
Section titled “Properties”digest: str
length: int
sequence: str
Supporting Models
Section titled “Supporting Models”AccessMethod
Section titled “AccessMethod”Describes how to access object bytes (protocol type, URL, region).
class AccessMethod
Section titled “class AccessMethod”Describes a method for accessing object bytes, including the protocol type (e.g., https, s3, gs) and either a direct URL or an access_id for the /access endpoint. At least one of access_url or access_id must be provided.
DRS 1.5.0 adds the ‘cloud’ field to explicitly specify the cloud provider.
Properties
Section titled “Properties”access_id: Optional[str]
access_url: Optional[AccessURL]
cloud: Optional[str]
region: Optional[str]
type: Literal[‘s3’, ‘gs’, ‘ftp’, ‘gsiftp’, ‘globus’, ‘htsget’, ‘https’, ‘file’]
AccessURL
Section titled “AccessURL”A fully resolvable URL with optional headers for authentication.
class AccessURL
Section titled “class AccessURL”A fully resolvable URL that can be used to fetch the actual object bytes. Optionally includes headers (e.g., authorization tokens) required for access.
Properties
Section titled “Properties”headers: Optional[List[str]]
url: str
Checksum
Section titled “Checksum”A checksum for data integrity verification.
class Checksum
Section titled “class Checksum”A checksum for data integrity verification. The type field indicates the hash algorithm (e.g., “sha-256”, “md5”) and the checksum field contains the hex-string encoded hash value.
Properties
Section titled “Properties”checksum: str
type: str
Response Models
Section titled “Response Models”PaginationResult
Section titled “PaginationResult”Pagination metadata for list endpoints.
class PaginationResult
Section titled “class PaginationResult”Properties
Section titled “Properties”page: int
page_size: int
total: int
ResultsSequenceCollections
Section titled “ResultsSequenceCollections”Paginated sequence collection results.
class ResultsSequenceCollections
Section titled “class ResultsSequenceCollections”Sequence collection results with pagination
Properties
Section titled “Properties”pagination: PaginationResult
results: Dict[str, dict]
Similarities
Section titled “Similarities”Results from Jaccard similarity calculations.
class Similarities
Section titled “class Similarities”Model to contain results from similarities calculations
Properties
Section titled “Properties”pagination: PaginationResult
reference_digest: Optional[str]
similarities: List[Dict[str, Any]]
Attribute Tables
Section titled “Attribute Tables”These models store individual attributes of sequence collections in normalized database tables:
NamesAttr
Section titled “NamesAttr”class NamesAttr
Section titled “class NamesAttr”Properties
Section titled “Properties”collection: List[SequenceCollection]
digest: str
value: list
LengthsAttr
Section titled “LengthsAttr”class LengthsAttr
Section titled “class LengthsAttr”Properties
Section titled “Properties”collection: List[SequenceCollection]
digest: str
value: list
SequencesAttr
Section titled “SequencesAttr”class SequencesAttr
Section titled “class SequencesAttr”Properties
Section titled “Properties”collection: List[SequenceCollection]
digest: str
value: list
NameLengthPairsAttr
Section titled “NameLengthPairsAttr”class NameLengthPairsAttr
Section titled “class NameLengthPairsAttr”Properties
Section titled “Properties”collection: List[SequenceCollection]
digest: str
value: list
Usage Examples
Section titled “Usage Examples”Creating a SequenceCollection from a FASTA file
Section titled “Creating a SequenceCollection from a FASTA file”from refget.models import SequenceCollection
# From a FASTA file (requires gtars)seqcol = SequenceCollection.from_fasta_file("genome.fa")
# Access different representationsprint(seqcol.digest) # Top-level digestprint(seqcol.level1()) # Attribute digestsprint(seqcol.level2()) # Full arraysprint(seqcol.itemwise()) # Per-sequence dictsCreating a SequenceCollection from a dictionary
Section titled “Creating a SequenceCollection from a dictionary”from refget.models import SequenceCollection
seqcol_dict = { "names": ["chr1", "chr2"], "lengths": [1000, 2000], "sequences": ["SQ.abc123...", "SQ.def456..."]}
seqcol = SequenceCollection.from_dict(seqcol_dict)Creating a FastaDrsObject
Section titled “Creating a FastaDrsObject”from refget.models import FastaDrsObject
# From a FASTA filedrs_obj = FastaDrsObject.from_fasta_file("genome.fa")
# Access DRS metadataprint(drs_obj.id) # Sequence collection digestprint(drs_obj.size) # File size in bytesprint(drs_obj.checksums) # SHA-256, MD5print(drs_obj.access_methods) # How to download