Created
April 15, 2015 09:52
-
-
Save romunov/02a030498312a7937538 to your computer and use it in GitHub Desktop.
writing to a file from a function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import simuPOP as sim | |
import numpy as np | |
from simuPOP.utils import viewVars | |
pop = sim.Population(size = [550, 400], loci = 10, infoFields = ["age", "migrate_to"], subPopNames = ["croatia", "slovenia"]) | |
sim.initInfo(pop = pop, values = np.random.choice([1, 2, 3, 4, 5], replace = True, size = 200), infoFields = "age") | |
sim.initGenotype(pop = pop, prop = [0.1]*10) | |
sim.initSex(pop, maleProp = 0.5) | |
pop.subPopSizes() | |
pop.subPopNames() | |
sim.splitSubPops(pop = pop, subPops = 0, sizes = [450, 100]) | |
sim.splitSubPops(pop = pop, subPops = 2, sizes = [300, 100]) | |
pop.subPopSizes() | |
pop.subPopNames() | |
sim.stat(pop = pop, popSize = "subPopSize_sp") | |
sim.stat(pop = pop, effectiveSize = sim.ALL_AVAIL, vars = "Ne_LD_sp") | |
# Construct a dictionary that can be read in columns: | |
# pop_num, pop_name, x, 0.0, 0.01, 0.02, 0.05 | |
# population num __/ / / / / / / | |
# population name _______/ / / / / / | |
# variable designation _________/ / / / / | |
# value without a cutoff __________/ / / / | |
# value at cutoff of 0.01 ______________/ / / | |
# value at cutoff of 0.02 ___________________/ / | |
# value at cutoff of 0.05 ________________________/ | |
for p in range(pop.numSubPop()): # all subpops | |
data = [] | |
xname = ["fit", "lci", "uci"] | |
for x in range(3): # fit, lci, uci | |
v = [] | |
for y in [0.0, 0.01, 0.02, 0.05]: | |
v.append(pop.dvars().subPop[p]["Ne_LD"][y][x]) | |
data.append(v) | |
# print("{pop}, {popname}, {x}, {data}".format(pop = p, popname = pop.subPopNames()[p], x = xname[x], data = data[x])) | |
to_print = "{pop}, {popname}, {x}, {data0}, {data01}, {data02}, {data05}".format(pop = pop.subPopNames()[p], popname = p, x = xname[x], | |
data0 = data[x][0], | |
data01 = data[x][1], | |
data02 = data[x][2], | |
data05 = data[x][3]) | |
sim.pyOutput(to_print) # doesn't work | |
print(to_print) # outputs fine, but only to console |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment