TriSpectrum_mod
Contains triallelic Spectrum object
TriSpectrum
Bases: masked_array
Represents a triallelic frequency spectrum.
Similar structure to biallelic spectra as a masked array, but specific to the triallelic spectrum, so that infeasible entries are masked, and operations performed on triallelic spectra are different than typical spectra
The constructor has the format
fs = dadi.Triallele.TriSpectrum(data, mask, mask_infeasible, data_folded_major, data_folded_ancestral, extrap_x, extrap_t)
data: The triallelic frequency spectrum data
mask: An optional array of the same size as data, similar to dadi.Spectrum
data_folded_major: If True, it is assumed that the input data is folded for the major and minor derived alleles
data_folded_ancestral: If True, it is assumed that the input data is folded to account for uncertainty in the ancestral state. Note that if True, data_folded_major must also be True.
check_folding_major: If True and data_folded_ancestral=True, the data and mask will be checked to ensure they are consistent
check_folding_ancestral: If True and data_folded_ancestral=True, the data and mask will be checked to ensure they are consistent
extrap_x: Optional floating point value specifying x value to use in extrapolation.
extrap_t: Optional floating point value specifying t value to use in extrapolation.
S()
Segregating sites
Source code in dadi/Triallele/TriSpectrum_mod.py
400 401 402 403 404 | |
from_file(fid, mask_infeasible=True, return_comments=False)
staticmethod
Read frequency spectrum from file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fid
|
str
|
string with file name to read from or an open file object. |
required |
mask_infeasible
|
bool
|
If True, mask the infeasible entries in the triallelic spectrum. |
True
|
return_comments
|
bool
|
If true, the return value is (fs, comments), where comments is a list of strings containing the comments from the file (without #'s). |
False
|
See to_file method for details on the file format.
Source code in dadi/Triallele/TriSpectrum_mod.py
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 | |
log()
Return the natural logarithm of the entries of the frequency spectrum.
Only necessary because numpy.ma.log now fails to propagate extra attributes after numpy 1.10.
Source code in dadi/Triallele/TriSpectrum_mod.py
349 350 351 352 353 354 355 356 357 358 359 360 361 | |
mask_infeasible()
Mask any infeasible entries.
Source code in dadi/Triallele/TriSpectrum_mod.py
139 140 141 142 143 144 145 146 | |
to_file(fid, precision=16, comment_lines=[], foldmaskinfo=True, extrapinfo=True)
Write frequency spectrum to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fid
|
str
|
string with file name to write to or an open file object. |
required |
precision
|
precision with which to write out entries of the SFS. (They are formated via %. g, where is the precision.) |
16
|
|
comment_lines
|
list[str]
|
list of strings to be used as comment lines in the header of the output file. |
[]
|
foldmaskinfo
|
bool
|
If False, folding and mask and population label information will not be saved. This conforms to the file format for dadi versions prior to 1.3.0. |
True
|
extrapinfo
|
bool
|
If False, extrapolation information will not be saved. |
True
|
The file format is
Any number of comment lines beginning with a '#'
A single line containing N integers giving the dimensions of the fs array. So this line would be '5 5 3' for an SFS that was 5x5x3. (That would be 4x4x2 samples.)
On the same line, the string 'folded_major' or 'unfolded_major' denoting the folding status of the array
On the same line, the string 'folded_ancestral' or 'unfolded_ancestral' denoting the folding status of the array
A single line giving the array elements. The order of elements is e.g.: fs[0,0,0] fs[0,0,1] fs[0,0,2] ... fs[0,1,0] fs[0,1,1] ...
A single line giving the elements of the mask in the same order as the data line. '1' indicates masked, '0' indicates unmasked.
Source code in dadi/Triallele/TriSpectrum_mod.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |