Specimens
Generate snail specimens.
SpecimenParams
Bases: BaseModel
Parameters for specimen generation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
end_date
|
date
|
End date for specimen collection |
required |
length
|
int
|
Length of specimen genomes (must be positive) |
required |
max_mass
|
float
|
Maximum mass for specimens (must be positive) |
required |
min_mass
|
float
|
Minimum mass for specimens (must be positive and less than max_mass) |
required |
mut_scale
|
float
|
Scale factor for mutation effect |
required |
mutations
|
int
|
Number of mutations in specimens (must be between 0 and length) |
required |
number
|
int
|
Number of specimens to generate (must be positive) |
required |
seed
|
int
|
Random seed for reproducibility |
required |
start_date
|
date
|
Start date for specimen collection |
required |
Source code in src/snailz/specimens.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
validate_fields()
Validate requirements on fields.
Source code in src/snailz/specimens.py
45 46 47 48 49 50 51 52 53 54 |
|
Specimen
Bases: BaseModel
A single specimen.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ident
|
str
|
unique identifier |
required |
collected_on
|
date
|
date when specimen was collected |
required |
genome
|
str
|
bases in genome |
required |
mass
|
float
|
snail mass in grams |
required |
site
|
Point
|
grid location where specimen was collected |
required |
territory
|
float
|
share of the grid that belongs to this specimen |
0.0
|
Source code in src/snailz/specimens.py
57 58 59 60 61 62 63 64 65 66 67 |
|
AllSpecimens
Bases: BaseModel
A set of generated specimens.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
individuals
|
list[Specimen]
|
list of individual specimens |
required |
loci
|
list[int]
|
locations where mutations can occur |
required |
params
|
SpecimenParams
|
parameters used to generate this data |
required |
reference
|
str
|
unmutated genome |
required |
susceptible_base
|
str
|
mutant base that induces mass changes |
required |
susceptible_locus
|
int
|
location of mass change mutation |
required |
Source code in src/snailz/specimens.py
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 |
|
to_csv()
Return a CSV string representation of the specimens data.
Returns:
Type | Description |
---|---|
str
|
A CSV-formatted string with people data (without parameters) |
Source code in src/snailz/specimens.py
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 |
|
specimens_generate(params, grid=None)
Generate specimens with random genomes and masses.
Each genome is a string of bases of the same length. One locus is randomly chosen as "significant", and a specific mutation there predisposes the snail to mass changes. Other mutations are added randomly at other loci. Specimen masses are only mutated if a grid is provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
SpecimenParams
|
SpecimenParams object |
required |
grid
|
Grid | None
|
Grid object to place specimens on for mass mutation |
None
|
Returns:
Type | Description |
---|---|
AllSpecimens
|
AllSpecimens object containing the generated specimens and parameters |
Source code in src/snailz/specimens.py
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 |
|
calculate_ranges(size, specimens)
Calculate the territory of each specimen.
Source code in src/snailz/specimens.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
mutate_masses(grid, specimens, mut_scale, specific_index=None)
Mutate mass based on grid values and genetic susceptibility.
For each specimen, choose a random cell from the grid and modify the mass if the cell's value is non-zero and the genome is susceptible. Records the chosen site coordinates for each specimen regardless of whether mutation occurs. Modifies specimen masses in-place for susceptible individuals; updates site coordinates for all individuals.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
grid
|
Grid
|
A Grid object containing pollution values |
required |
specimens
|
AllSpecimens
|
A AllSpecimens object with individuals to potentially mutate |
required |
mut_scale
|
float
|
Scaling factor for mutation effect |
required |
specific_index
|
int | None
|
Optional index to mutate only a specific specimen |
None
|
Source code in src/snailz/specimens.py
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 |
|
mutate_mass(original, mut_scale, cell_value)
Mutate a single specimen's mass.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
original
|
float
|
The original mass value |
required |
mut_scale
|
float
|
Scaling factor for mutation effect |
required |
cell_value
|
int
|
The grid cell value affecting the mutation |
required |
Returns:
Type | Description |
---|---|
float
|
The mutated mass value, rounded to PRECISION decimal places |
Source code in src/snailz/specimens.py
218 219 220 221 222 223 224 225 226 227 228 229 |
|
_choose_one(values)
Choose a single random item from a collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values
|
list[int]
|
A sequence to choose from |
required |
Returns:
Type | Description |
---|---|
int
|
A randomly selected item from the values sequence |
Source code in src/snailz/specimens.py
232 233 234 235 236 237 238 239 240 241 |
|
_choose_other(values, exclude)
Choose a value at random except for the excluded values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values
|
str
|
A collection to choose from |
required |
exclude
|
str
|
Value or collection of values to exclude from the choice |
required |
Returns:
Type | Description |
---|---|
str
|
A randomly selected item from values that isn't in exclude |
Source code in src/snailz/specimens.py
244 245 246 247 248 249 250 251 252 253 254 255 |
|
_make_genome(reference, loci)
Make an individual genome by mutating the reference genome.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reference
|
str
|
Reference genome string to base the new genome on |
required |
loci
|
list[int]
|
List of positions that can be mutated |
required |
Returns:
Type | Description |
---|---|
str
|
A new genome string with random mutations at some loci |
Source code in src/snailz/specimens.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
_make_idents(count)
Create unique specimen identifiers.
Each identifier is a 6-character string: - First two characters are the same uppercase letters for all specimens - Remaining four chararacters are random uppercase letters and digits
Parameters:
Name | Type | Description | Default |
---|---|---|---|
count
|
int
|
Number of identifiers to generate |
required |
Returns:
Type | Description |
---|---|
list[str]
|
List of unique specimen identifiers |
Source code in src/snailz/specimens.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
|
_make_locations(size, num)
Generate non-adjacent locations for specimens or fail.
Source code in src/snailz/specimens.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
_make_loci(params)
Make a list of mutable loci positions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
SpecimenParams
|
SpecimenParams with length and mutations attributes |
required |
Returns:
Type | Description |
---|---|
list[int]
|
A list of unique randomly selected positions that can be mutated |
Source code in src/snailz/specimens.py
315 316 317 318 319 320 321 322 323 324 |
|
_make_masses(params, genomes, susceptible_locus, susceptible_base)
Generate random masses for specimens.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
SpecimenParams
|
SpecimenParams with min_mass and max_mass attributes |
required |
genomes
|
list[str]
|
List of genome strings |
required |
susceptible_locus
|
int
|
Position that determines susceptibility |
required |
susceptible_base
|
str
|
Base that makes a specimen susceptible |
required |
Returns:
Type | Description |
---|---|
list[float]
|
List of randomly generated mass values between min_mass and max_mass, |
list[float]
|
rounded to PRECISION decimal places |
Source code in src/snailz/specimens.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|
_make_collection_dates(params)
Generate random collection dates for specimens.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
SpecimenParams
|
SpecimenParams with start_date, end_date, and number attributes |
required |
Returns:
Type | Description |
---|---|
list[date]
|
List of randomly generated collection dates between start_date and end_date |
Source code in src/snailz/specimens.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
|
_make_reference_genome(params)
Make a random reference genome.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
SpecimenParams
|
SpecimenParams with length attribute |
required |
Returns:
Type | Description |
---|---|
str
|
A randomly generated genome string of the specified length |
Source code in src/snailz/specimens.py
368 369 370 371 372 373 374 375 376 377 |
|