Spectrum_mod
Contains Spectrum object, which represents frequency spectra.
Spectrum
Bases: masked_array
Represents a frequency spectrum.
Spectra are represented by masked arrays. The masking allows us to ignore specific entries in the spectrum. Most often, these are the absent and fixed categories.
The constructor has the format
fs = dadi.Spectrum(data, mask, mask_corners, data_folded, check_folding, pop_ids, extrap_x) data: The frequency spectrum data mask: An optional array of the same size as data. 'True' entires in this array are masked in the Spectrum. These represent missing data categories. (For example, you may not trust your singleton SNP calling.) mask_corners: If True (default), the 'observed in none' and 'observed in all' entries of the FS will be masked. Typically these entries are unobservable, and dadi cannot reliably calculate them, so you will almost always want mask_corners=True. data_folded: If True, it is assumed that the input data is folded. An error will be raised if the input data and mask are not consistent with a folded Spectrum. check_folding: If True and data_folded=True, the data and mask will be checked to ensure they are consistent with a folded Spectrum. If they are not, a warning will be printed. pop_ids: Optional list of strings containing the population labels. extrap_x: Optional floating point value specifying x value to use for extrapolation.
Fst()
Wright's Fst between the populations represented in the fs.
This estimate of Fst assumes random mating, because we don't have heterozygote frequencies in the fs.
Calculation is by the method of Weir and Cockerham Evolution 38:1358 (1984). For a single SNP, the relevant formula is at the top of page 1363. To combine results between SNPs, we use the weighted average indicated by equation 10.
Source code in dadi/Spectrum_mod.py
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 | |
S()
Segregating sites.
Source code in dadi/Spectrum_mod.py
1150 1151 1152 1153 1154 1155 1156 1157 1158 | |
Tajima_D()
Tajima's D.
Following Gillespie "Population Genetics: A Concise Guide" pg. 45
Source code in dadi/Spectrum_mod.py
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 | |
Watterson_theta()
Watterson's estimator of theta.
Note that is only sensible for 1-dimensional spectra.
Source code in dadi/Spectrum_mod.py
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 | |
Zengs_E()
Zeng et al.'s E statistic.
Citation
Zeng et al. "Statistical Tests for Detecting Positive Selection by Utilizing High-Frequency Variants" (2006) Genetics
Source code in dadi/Spectrum_mod.py
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 | |
combine_pops(tocombine)
Combine two or more populations in the fs, treating them as a single pop
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tocombine
|
list
|
Unordered set of population numbers to combine, numbering from 1. |
required |
Note
-
The populations will alwasy be combined into the slot of the population with the smallest index. For example, if the sample sizes of the spectrum are (1,2,3,4,5) and tocombine=[4,2,1], then the output spectrum will have sample_sizes (7,3,5) when populations 1, 2, and 4 are combined.
-
The pop_ids of the new population will be the pop_ids of the combined populations with a '+' in between them.
Source code in dadi/Spectrum_mod.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | |
combine_two_pops(tocombine)
Combine two populations in the fs, treating them as a single pop
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tocombine
|
list
|
Indices for populations being combined (starting from 1) |
required |
Notes
-
The two populations will alwasy be combined into the slot of the population with the smallest index. For example, if the sample sizes of the spectrum are (2,3,4,5) and tocombine=[4,2], then the output spectrum will have sample_sizes (2,8,4) when populations 2 and 4 are combined.
-
The pop_ids of the new population will be the pop_ids of the two combined populations with a '+' in between them.
Source code in dadi/Spectrum_mod.py
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | |
filter_pops(tokeep, mask_corners=True)
Filter Spectrum to keep only certain populations.
Returns new Spectrum with len(tokeep) populations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokeep
|
int
|
Unordered set of population numbers to keep, numbering from 1. |
required |
mask_corners
|
bool
|
If True, the typical corners of the resulting fs will be masked |
True
|
Note
This is similar in practice to the marginalize operation. But here populations are numbered from 1, as in the majority of dadi.
Source code in dadi/Spectrum_mod.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | |
fixed_size_sample(nsamples, only_nonmasked=False)
Generate a resampled fs from the current one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nsamples
|
int
|
Number of samples to include in the new FS. |
required |
only_nonmasked
|
bool
|
If True, only SNPs from non-masked will be resampled. Otherwise, all SNPs will be used. |
False
|
Source code in dadi/Spectrum_mod.py
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 | |
fold()
Folded frequency spectrum
The folded fs assumes that information on which allele is ancestral or derived is unavailable. Thus the fs is in terms of minor allele frequency. Note that this makes the fs into a "triangular" array.
Note that if a masked cell is folded into non-masked cell, the destination cell is masked as well.
Note also that folding is not done in-place. The return value is a new Spectrum object.
Source code in dadi/Spectrum_mod.py
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 | |
from_data_dict(data_dict, pop_ids, projections, mask_corners=True, polarized=True)
staticmethod
Spectrum from a dictionary of polymorphisms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pop_ids
|
list[str]
|
list of which populations to make fs for. |
required |
projections
|
list[int]
|
list of sample sizes to project down to for each population. |
required |
mask_corners
|
bool
|
If True (default), the 'observed in none' and 'observed in all' entries of the FS will be masked. |
True
|
polarized
|
bool
|
If True, the data are assumed to be correctly polarized by `outgroup_allele'. SNPs in which the 'outgroup_allele' information is missing or '-' or not concordant with the segregating alleles will be ignored. If False, any 'outgroup_allele' info present is ignored, and the returned spectrum is folded. |
True
|
The data dictionary should be organized as:
{snp_id:{'segregating': ['A','T'],
'calls': {'YRI': (23,3),
'CEU': (7,3)
},
'outgroup_allele': 'T'
}
}
The 'calls' entry gives the successful calls in each population, in the order that the alleles are specified in 'segregating'. Non-diallelic polymorphisms are skipped.
Source code in dadi/Spectrum_mod.py
2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 | |
from_data_dict_corrected(data_dict, pop_ids, projections, fux_filename, force_pos=True, mask_corners=True)
staticmethod
Spectrum from a dictionary of polymorphisms, corrected for ancestral misidentification.
The correction is based upon
Hernandez, Williamson & Bustamante Mol_Biol_Evol 24:1792 (2007)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force_pos
|
bool
|
If the correction is too agressive, it may leave some small entries in the fs less than zero. If force_pos is true, these entries will be set to zero, in such a way that the total number of segregating SNPs is conserved. |
True
|
fux_filename
|
str
|
The name of the file containing the misidentification probabilities. |
required |
The file (fux_filename) is of the form:
# Any number of comments lines beginning with #
AAA T 0.001
AAA G 0.02
...
Where every combination of three + one bases is considered (order is not important). The triplet is the context and putatively derived allele (x) in the reference species. The single base is the base (u) in the outgroup. The numerical value is 1-f_{ux} in the notation of the paper.
The data dictionary should be organized as:
{snp_id:{'segregating': ['A','T'],
'calls': {'YRI': (23,3),
'CEU': (7,3)
},
'outgroup_allele': 'T',
'context': 'CAT',
'outgroup_context': 'CAT'
}
}
The additional entries are 'context', which includes the two flanking bases in the species of interest, and 'outgroup_context', which includes the aligned bases in the outgroup.
This method skips entries for which the correction cannot be applied. Most commonly this is because of missing or non-constant context.
Source code in dadi/Spectrum_mod.py
2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 | |
from_demes(g, sampled_demes, sample_sizes, pts, log_extrap=False, sample_times=None, Ne=None, ancestral_misid=False)
staticmethod
Takes a deme graph and computes the SFS. demes is a package for
specifying demographic models in a user-friendly, human-readable YAML
format. This function automatically parses the demographic description
and returns a SFS for the specified populations and sample sizes.
This function is new in version 1.1.0. Future developments will allow for
inference using demes-based demographic descriptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
str or DemeGraph
|
A |
required |
sampled_demes
|
list[str]
|
A list of deme IDs to take samples from. We can repeat demes, as long as the sampling of repeated deme IDs occurs at distinct times. |
required |
sample_sizes
|
list[int]
|
A list of the same length as |
required |
sample_times
|
list[floats]
|
If None, assumes all sampling occurs at the end of the
existence of the sampled deme. If there are
ancient samples, |
None
|
Ne
|
float
|
reference population size. If none is given, we use the initial size of the root deme. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
fs |
Spectrum
|
A |
Source code in dadi/Spectrum_mod.py
2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 | |
from_file(fname, mask_corners=True, return_comments=False)
staticmethod
Read frequency spectrum from file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
String with file name to read from. If it ends in .gz, gzip compression is assumed. |
required |
mask_corners
|
bool
|
If True, mask the 'absent in all samples' and 'fixed in all samples' entries. |
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
|
Note
See to_file method for details on the file format.
Source code in dadi/Spectrum_mod.py
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 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
from_ms_file(fid, average=True, mask_corners=True, return_header=False, pop_assignments=None, pop_ids=None, bootstrap_segments=1)
staticmethod
Read frequency spectrum from file of ms output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fid
|
str
|
string with file name to read from or an open file object. |
required |
average
|
bool
|
If True, the returned fs is the average over the runs in the ms file. If False, the returned fs is the sum. |
True
|
mask_corners
|
bool
|
If True, mask the 'absent in all samples' and 'fixed in all samples' entries. |
True
|
return_header
|
bool
|
If True, the return value is (fs, (command,seeds), where command and seeds are strings containing the ms commandline and the seeds used. |
False
|
pop_assignments
|
list[int]
|
If None, the assignments of samples to populations is done automatically, using the assignment in the ms command line. To manually assign populations, pass a list of the from [6,8]. This example places the first 6 samples into population 1, and the next 8 into population 2. |
None
|
pop_ids
|
list[str]
|
Optional list of strings containing the population labels. If pop_ids is None, labels will be "pop0", "pop1", ... |
None
|
bootstrap_segments
|
int
|
If bootstrap_segments is an integer greater than 1, the data will be broken up into that many segments based on SNP position. Instead of single FS, a list of spectra will be returned, one for each segment. |
1
|
Source code in dadi/Spectrum_mod.py
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 | |
from_phi(phi, ns, xxs, mask_corners=True, pop_ids=None, admix_props=None, het_ascertained=None, force_direct=False)
staticmethod
Compute sample Spectrum from population frequency distribution phi.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi
|
array - like
|
P-dimensional population frequency distribution. |
required |
ns
|
list[int]
|
Sequence of P sample sizes for each population. |
required |
xxs
|
tuple[int]
|
Sequence of P one-dimesional grids on which phi is defined. |
required |
mask_corners
|
bool
|
If True, resulting FS is masked in 'absent' and 'fixed' entries. |
True
|
pop_ids
|
list[str]
|
Optional list of strings containing the population labels. If pop_ids is None, labels will be "pop0", "pop1", ... |
None
|
admix_props
|
tuple[tuple]
|
Admixture proportions for sampled individuals. For example, if there are two populations, and individuals from the first pop are admixed with fraction f from the second population, then admix_props=((1-f,f),(0,1)). For three populations, the no-admixture setting is admix_props=((1,0,0),(0,1,0),(0,0,1)). (Note that this option also forces direct integration, which may be less accurate than the semi-analytic method.) |
None
|
het_ascertained
|
str['xx', 'yy', or 'zz']
|
If 'xx', then FS is calculated assuming that SNPs have been ascertained by being heterozygous in one individual from population 1. (This individual is not in the current sample.) If 'yy' or 'zz', it assumed that the ascertainment individual came from population 2 or 3, respectively. (Note that this option also forces direct integration, which may be less accurate than the semi-analytic method. This could be fixed if there is interest. Note also that this option cannot be used simultaneously with admix_props.) |
None
|
force_direct
|
bool
|
Forces integration to use older direct integration method, rather than using analytic integration of sampling formula. |
False
|
Source code in dadi/Spectrum_mod.py
1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 | |
from_phi_inbreeding(phi, ns, xxs, Fs, ploidys, mask_corners=True, pop_ids=None, admix_props=None, het_ascertained=None, force_direct=True)
staticmethod
Compute a sample Spectrum from a population frequency distribution (phi) with inbreeding.
This function calculates the frequency spectrum while accounting for inbreeding coefficients and ploidy levels for each population.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phi
|
array - like
|
P-dimensional population frequency distribution. |
required |
ns
|
list[int]
|
Sequence of P sample sizes for each population. |
required |
xxs
|
list[array - like]
|
Sequence of P one-dimensional grids on which phi is defined. |
required |
Fs
|
list[float]
|
Sequence of P inbreeding coefficients for each population. |
required |
ploidys
|
list[int]
|
Sequence of P ploidy levels for each population. |
required |
mask_corners
|
bool
|
If True, resulting FS is masked in 'absent' and 'fixed' entries. |
True
|
pop_ids
|
list[str]
|
Optional list of strings containing the population labels. If None, labels will be "pop0", "pop1", etc. |
None
|
admix_props
|
list[tuple]
|
Admixture proportions for sampled individuals. For example, if there are two populations and individuals from the first population are admixed with fraction f from the second population, then admix_props=((1-f, f), (0, 1)). For three populations, the no-admixture setting is admix_props=((1, 0, 0), (0, 1, 0), (0, 0, 1)). Note: This option forces direct integration, which may be less accurate than the semi-analytic method. |
None
|
het_ascertained
|
str
|
If 'xx', the FS is calculated assuming that SNPs have been ascertained by being heterozygous in one individual from population 1. This individual is not in the current sample. If 'yy' or 'zz', it is assumed that the ascertainment individual came from population 2 or 3, respectively. Note: This option forces direct integration, which may be less accurate than the semi-analytic method. This option cannot be used simultaneously with admix_props. |
None
|
force_direct
|
bool
|
Forces integration to use the older direct integration method, rather than using analytic integration of the sampling formula. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
fs |
Spectrum
|
The resulting frequency spectrum. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dimensionality of phi and lengths of ns, xxs, ploidys, and Fs do not all agree, or if invalid values are provided for het_ascertained. |
NotImplementedError
|
If admix_props and het_ascertained are used simultaneously. |
Source code in dadi/Spectrum_mod.py
2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 | |
from_sfscode_file(fid, sites='all', average=True, mask_corners=True, return_header=False, pop_ids=None)
staticmethod
Read a frequency spectrum from an sfs_code output file.
This function parses the output of sfs_code and returns a frequency spectrum based on the specified filtering and formatting options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fid
|
str or file object
|
Path to the file or an open file object containing sfs_code output. |
required |
sites
|
str
|
Site type to include in the spectrum. Options are:
|
'all'
|
average
|
bool
|
If True, return the average spectrum across runs; if False, return the sum. |
True
|
mask_corners
|
bool
|
If True, mask entries corresponding to alleles absent or fixed in all samples. |
True
|
return_header
|
bool
|
If True, return a tuple (fs, (command, seeds)), where |
False
|
pop_ids
|
list of str
|
Population labels. If None, defaults to ["pop0", "pop1", ...]. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
fs |
Spectrum
|
The frequency spectrum, optionally with metadata if |
Source code in dadi/Spectrum_mod.py
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 | |
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/Spectrum_mod.py
598 599 600 601 602 603 604 605 606 607 608 609 | |
marginalize(over, mask_corners=True)
Reduced dimensionality spectrum summing over some populations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
over
|
list of int
|
sequence of axes to sum over. For example (0,2) will sum over populations 0 and 2. |
required |
mask_corners
|
bool
|
If True, the typical corners of the resulting fs will be masked |
True
|
Source code in dadi/Spectrum_mod.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
mask_corners()
Mask the 'seen in 0 samples' and 'seen in all samples' entries.
Source code in dadi/Spectrum_mod.py
178 179 180 181 182 | |
pi()
Estimated expected number of pairwise differences between two chromosomes in the population.
Note that this estimate includes a factor of sample_size / (sample_size - 1) to make E( π̂ ) = θ.
Source code in dadi/Spectrum_mod.py
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 | |
project(ns)
Project to smaller sample size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ns
|
int
|
Sample sizes for new spectrum. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
fs |
Spectrum
|
Spectrum object with sample sizes ns. |
Source code in dadi/Spectrum_mod.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
reorder_pops(neworder)
Get Spectrum with populations in new order
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
neworder
|
list[int]
|
Integer list defining new order of populations, indexing the orginal populations from 1. Must contain all integers from 1 to number of pops. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
fs |
Spectrum
|
New Spectrum with same number of populations, but in a different order |
Source code in dadi/Spectrum_mod.py
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 | |
sample()
Generate a Poisson-sampled fs from the current one.
Note
Entries where the current fs is masked will be masked in the output sampled fs.
Source code in dadi/Spectrum_mod.py
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 | |
scramble_pop_ids(mask_corners=True)
Spectrum corresponding to scrambling individuals among populations.
This is useful for assessing how diverged populations are. Essentially, it pools all the individuals represented in the fs and generates new populations of random individuals (without replacement) from that pool. If this fs is significantly different from the original, that implies population structure.
Source code in dadi/Spectrum_mod.py
2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 | |
theta_L()
theta_L as defined by Zeng et al. "Statistical Tests for Detecting Positive Selection by Utilizing High-Frequency Variants" (2006) Genetics
Note that is only sensible for 1-dimensional spectra.
Source code in dadi/Spectrum_mod.py
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 | |
to_file(fname, precision=16, comment_lines=[], foldmaskinfo=True)
Write frequency spectrum to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
File name to write to. If string ends in .gz, file will be saved with gzip compression. |
required |
precision
|
int
|
precision with which to write out entries of the SFS. (They
are formated via |
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
|
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' or 'unfolded' denoting the
folding status of the array
- On the *same line*, optional strings each containing the population
labels in quotes separated by spaces, e.g. "pop 1" "pop 2"
- 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/Spectrum_mod.py
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 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
unfold()
Unfolded frequency spectrum
It is assumed that each state of a SNP is equally likely to be ancestral.
Note also that unfolding is not done in-place. The return value is a new Spectrum object.
Source code in dadi/Spectrum_mod.py
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | |
unmask_all()
Unmask all values.
Source code in dadi/Spectrum_mod.py
184 185 186 187 188 | |