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.
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.
SequenceCollection
Section titled “SequenceCollection”class SequenceCollectionBases: SQLModel
A SQLModel/pydantic model that represents a refget sequence collection.
Attributes
Section titled “Attributes”digest(str): Top-level digest of the SequenceCollection.human_readable_names(List[HumanReadableNames]) =Relationship(back_populates='collection')lengths(LengthsAttr) =Relationship(back_populates='collection'): Array of sequence lengths.lengths_digest(str)name_length_pairs(NameLengthPairsAttr) =Relationship(back_populates='collection'): Array of name-length pairs, representing the coordinate system of the collection.name_length_pairs_digest(str)names(NamesAttr) =Relationship(back_populates='collection'): Array of sequence names.names_digest(str)pangenomes(List[Pangenome]) =Relationship(back_populates='collections', link_model=PangenomeCollectionLink)sequences(SequencesAttr) =Relationship(back_populates='collection'): 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) =Relationship(back_populates='collection'): Array of sorted sequence digests.sorted_sequences_digest(str)
Class methods
Section titled “Class methods”from_PySequenceCollection
Section titled “from_PySequenceCollection”@classmethoddef from_PySequenceCollection(gtars_seq_col: gtarsSequenceCollection) -> SequenceCollectionGiven a PySequenceCollection object (from Rust bindings), create a SequenceCollection object.
Parameters:
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
Section titled “from_dict”@classmethoddef from_dict(seqcol_dict: dict, inherent_attrs: Optional[list] = DEFAULT_INHERENT_ATTRS) -> SequenceCollectionGiven a dict representation of a sequence collection, create a SequenceCollection object. This is the primary way to create a SequenceCollection object.
Parameters:
seqcol_dict(dict): Dictionary representation of a canonical sequence collection objectinherent_attrs(list): List of inherent attributes to digest (default:DEFAULT_INHERENT_ATTRS)
Returns:
- SequenceCollection: The SequenceCollection object
from_fasta_file
Section titled “from_fasta_file”@classmethoddef from_fasta_file(fasta_file: str) -> SequenceCollectionGiven a FASTA file, create a SequenceCollection object.
Parameters:
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
Section titled “itemwise”def itemwise(limit=None)Converts object into a list of dictionaries, one for each sequence in the collection.
level1
Section titled “level1”def 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”def 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.
FastaDrsObject
Section titled “FastaDrsObject”class FastaDrsObjectBases: DrsObject
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.
Attributes
Section titled “Attributes”extra_line_bytes(Optional[int]) =Noneid(str)line_bases(Optional[int]) =Noneoffsets(Optional[List[int]]) =Noneself_uri(Optional[str]) =None
Class methods
Section titled “Class methods”from_fasta_file
Section titled “from_fasta_file”@classmethoddef from_fasta_file(fasta_file: str, digest: str = None) -> FastaDrsObjectGiven a FASTA file, create a FastaDrsObject object, return a populated FastaDrsObject with computed size and checksum.
Parameters:
fasta_file(str): Path to a FASTA filedigest(str): The refget digest of the sequence collection (optional). If not included, it will be computed (default:None)
Returns:
- FastaDrsObject: The FastaDrsObject object
Raises:
- ImportError: If gtars is not installed (required for FASTA processing)
Methods
Section titled “Methods”to_response
Section titled “to_response”def to_response(base_uri: str = None) -> FastaDrsObjectReturn a copy of this object with self_uri populated for API response.
Parameters:
base_uri(str): Base URI for the DRS service (e.g., "drs://seqcolapi.databio.org") If not provided, returns self unchanged. (default:None)
Returns:
- FastaDrsObject: FastaDrsObject with self_uri populated
DrsObject
Section titled “DrsObject”Base model for GA4GH Data Repository Service (DRS) objects.
DrsObject
Section titled “DrsObject”class DrsObjectBases: SQLModel
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.
Attributes
Section titled “Attributes”access_methods(List[AccessMethod])aliases(List[str])checksums(List[Checksum])created_time(datetime)description(Optional[str]) =Noneid(str)mime_type(Optional[str]) =Nonename(Optional[str]) =Noneself_uri(str)size(int)updated_time(Optional[datetime]) =Noneversion(Optional[str]) =None
Class methods
Section titled “Class methods”coerce_access_methods
Section titled “coerce_access_methods”@classmethoddef coerce_access_methods(v)Coerce dicts to AccessMethod objects when loading from JSON.
coerce_checksums
Section titled “coerce_checksums”@classmethoddef coerce_checksums(v)Coerce dicts to Checksum objects when loading from JSON.
Methods
Section titled “Methods”serialize_access_methods
Section titled “serialize_access_methods”def serialize_access_methods(v)Serialize AccessMethod objects (or dicts) to dicts for JSON output.
serialize_checksums
Section titled “serialize_checksums”def 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.
Pangenome
Section titled “Pangenome”class PangenomeBases: SQLModel
Attributes
Section titled “Attributes”collections(List[SequenceCollection]) =Relationship(back_populates='pangenomes', link_model=PangenomeCollectionLink)collections_digest(str)digest(str)names(CollectionNamesAttr) =Relationship(back_populates='pangenome')names_digest(str)
Class methods
Section titled “Class methods”from_dict
Section titled “from_dict”@classmethoddef from_dict(pangenome_obj: dict, inherent_attrs: Optional[list] = None) -> PangenomeGiven a dict representation of a pangenome, create a Pangenome object. This is the primary way to create a Pangenome object.
Parameters:
pangenome_obj(dict): Dictionary representation of a canonical pangenome object
Returns:
- Pangenome: The Pangenome object
Methods
Section titled “Methods”level1
Section titled “level1”def level1()Converts object into dict of level 1 representation of the Pangenome.
level2
Section titled “level2”def level2()Converts object into dict of level 2 representation of the Pangenome.
level3
Section titled “level3”def level3()Converts object into dict of level 3 representation of the Pangenome.
level4
Section titled “level4”def level4()Converts object into dict of level 4 representation of the Pangenome.
Sequence
Section titled “Sequence”An individual sequence with its digest and content.
Sequence
Section titled “Sequence”class SequenceBases: SQLModel
Attributes
Section titled “Attributes”Supporting Models
Section titled “Supporting Models”AccessMethod
Section titled “AccessMethod”Describes how to access object bytes (protocol type, URL, region).
AccessMethod
Section titled “AccessMethod”class AccessMethodBases: SQLModel
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.
Attributes
Section titled “Attributes”access_id(Optional[str]) =Noneaccess_url(Optional[AccessURL]) =Nonecloud(Optional[str]) =Noneregion(Optional[str]) =Nonetype(Literal['s3', 'gs', 'ftp', 'gsiftp', 'globus', 'htsget', 'https', 'file'])
AccessURL
Section titled “AccessURL”A fully resolvable URL with optional headers for authentication.
AccessURL
Section titled “AccessURL”class AccessURLBases: SQLModel
A fully resolvable URL that can be used to fetch the actual object bytes. Optionally includes headers (e.g., authorization tokens) required for access.
Attributes
Section titled “Attributes”Checksum
Section titled “Checksum”A checksum for data integrity verification.
Checksum
Section titled “Checksum”class ChecksumBases: SQLModel
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.
Attributes
Section titled “Attributes”Response Models
Section titled “Response Models”PaginationResult
Section titled “PaginationResult”Pagination metadata for list endpoints.
PaginationResult
Section titled “PaginationResult”class PaginationResultBases: BaseModel
Attributes
Section titled “Attributes”ResultsSequenceCollections
Section titled “ResultsSequenceCollections”Paginated sequence collection results.
ResultsSequenceCollections
Section titled “ResultsSequenceCollections”class ResultsSequenceCollectionsBases: BaseModel
Sequence collection results with pagination
Attributes
Section titled “Attributes”pagination(PaginationResult)results(Dict[str, dict])
Similarities
Section titled “Similarities”Results from Jaccard similarity calculations.
Similarities
Section titled “Similarities”class SimilaritiesBases: BaseModel
Model to contain results from similarities calculations
Attributes
Section titled “Attributes”pagination(PaginationResult)reference_digest(Optional[str]) =Nonesimilarities(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”NamesAttr
Section titled “NamesAttr”class NamesAttrBases: SQLModel
Attributes
Section titled “Attributes”collection(List[SequenceCollection]) =Relationship(back_populates='names')digest(str)value(list)
LengthsAttr
Section titled “LengthsAttr”LengthsAttr
Section titled “LengthsAttr”class LengthsAttrBases: SQLModel
Attributes
Section titled “Attributes”collection(List[SequenceCollection]) =Relationship(back_populates='lengths')digest(str)value(list)
SequencesAttr
Section titled “SequencesAttr”SequencesAttr
Section titled “SequencesAttr”class SequencesAttrBases: SQLModel
Attributes
Section titled “Attributes”collection(List[SequenceCollection]) =Relationship(back_populates='sequences')digest(str)value(list)
NameLengthPairsAttr
Section titled “NameLengthPairsAttr”NameLengthPairsAttr
Section titled “NameLengthPairsAttr”class NameLengthPairsAttrBases: SQLModel
Attributes
Section titled “Attributes”collection(List[SequenceCollection]) =Relationship(back_populates='name_length_pairs')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