Esempio n. 1
0
def getExpandPop(logger=None,**kwargs):
	"""
	Wrapper for simuGWAS.py
	"""
	options = simuGWAS.options
	short_desc = '''This program evolves a subset of the HapMap dataset
	forward in time in order to simulate case control samples with realistic
	allele frequency and linkage disequilibrium structure.'''
	
	if len(kwargs) > 0:
		pars = Params(options,short_desc,**kwargs)
	else:
		pars = Params(options,short_desc)
		if not pars.guiGetParam():
			sys.exit(1)
	if os.path.isfile(pars.filename):
		logger.info("Expanded population %s already exists, skipping ahead!" % pars.filename)
		return pars
	if pars.run_mode == "Now":
		init=simuPOP.loadPopulation(pars.initPop)
		logger.info('Loaded initial population from file %s. ' % pars.initPop)
		pop = simuGWAS.simuGWAS(pars,init,logger)
		if pars.filename:
			logger.info("Saving expanded population to %s" % pars.filename)
			pop.vars().clear()
			pop.save(pars.filename)
		pars.expandPop =pop
	elif pars.run_mode == "Batch":
		pars.saveConfig("simuGWAS.config")
	
	return pars
Esempio n. 2
0
def addMutantsFrom(pop, param):
    # Adding mutants
    extMutantFile, regions, logger = param
    mPop = sim.loadPopulation(extMutantFile)
    # convert allele-based population to mutation based population.
    mPop = allelesToMutants(mPop, regions, logger)
    #
    mPop.resize(pop.popSize())
    # Add loci to pop
    for ch in range(mPop.numChrom()):
        pop.addLoci([ch] * mPop.numLoci(ch),
                    list(
                        range(
                            pop.numLoci(ch) + 1,
                            pop.numLoci(ch) + mPop.numLoci(ch) + 1)))
    if logger:
        # if an initial population is given
        logger.info('Adding mutants to population after bottleneck')
    # Add mutants to pop
    for ind, mInd in zip(pop.individuals(), mPop.individuals()):
        for p in range(2):
            for ch in range(pop.numChrom()):
                geno = ind.genotype(p, ch)
                mGeno = mInd.genotype(p, ch)
                idx = geno.index(0)
                for i, m in enumerate(mGeno):
                    if m == 0:
                        break
                    geno[idx + i] = m
    return True
Esempio n. 3
0
def single_mode(pipeline_pars,logger=None):
	if pipeline_pars.download:
		download_pars=downloadData(logger)
	
	if pipeline_pars.init:
		init_pop_pars =getInitPop(logger)
	
	if pipeline_pars.expand:
		expand_pop_pars = getExpandPop(logger)
	
	if pipeline_pars.penetrance:
		case_control_pars = getCaseControl(logger)
		if pipeline_pars.expand:
			if expand_pop_pars.filename == case_control_pars.expandPop:
				case_control_pars.pop = expand_pop_pars.expandPop
				logger.info("Using expandPop from simuGWAS!")
			else:
				case_control_pars.pop = simuPOP.loadPopulation(case_control_pars.expandPop)
				logger.info("Expanded population %s loaded!" %case_control_pars.expandPop)
		if os.path.isfile(case_control_pars.sampledPop):
			logger.info("Skipping case control dataset, file %s exists." %case_control_pars.sampledPop)
		else:
			case_control_dataset = singleGeneModel.penetrance(case_control_pars,logger)	
			case_control_dataset.save(case_control_pars.sampledPop)
			logger.info("Sampled population saved at %s" %case_control_pars.sampledPop)

	if pipeline_pars.format:
		format_filenames = get_formatters(logger)
	
	if pipeline_pars.cline:
		cline_filenames = get_cline(logger)
Esempio n. 4
0
def inRead(filename):
	"""
	Reads a binary file containing a population in simuPOP format.
	Returns the population as a simuPOP object.
	"""
	pop = inputsimuPop.loadPopulation(filename)
	return pop
	
Esempio n. 5
0
def downloadData(logger=None,**kwargs):
	'''
	Download and create populations from the third phase of the HapMap3 data.
	By default it grabs all available populations.
	
	chroms -- a list of human chromosome numbers. (required)
	mypops -- a list of HapMap population names. (optional)
	
	If the directory "HapMap" does not exist in the current directory, it will create one.
	In the HapMap directory, if a HapMap population file already exists, it will not be overwritten.
	
	From Peng and Amos example_2.py
	This equivalent to command

	> loadHapMap3.py --chroms='[2, 5,10]' --dest=HapMap
	'''
	options = loadHapMap3.options
	short_desc = """This script downloads the second release of the phase 3 of the HapMap datasets\n'
		'and saves them in simuPOP format. It also downloads the fine-scale\n'
		'recombination map and saves the genetic distance of each marker in\n'
		'a dictionary (geneticMap) in the population\'s local namespace."""
	
	if len(kwargs) > 0:
		pars = Params(options,short_desc,kwargs)
	else:
		pars = Params(options,short_desc)
		if not pars.guiGetParam(nCol=2):
			sys.exit(1)
	
	if not pars.skip:
		for chrom in pars.chroms:
			for sample in loadHapMap3.HapMap3_pops:
				popFile = os.path.join(pars.dest, "HapMap3_%s_chr%d.pop" % (sample, chrom))
				try:
					if os.path.isfile(popFile):
						pop = simuPOP.loadPopulation(popFile)
						if pop.popSize() == loadHapMap3.HapMap3_pop_sizes[sample]:
							if logger:
								logger.info("Skipping existing population %s." % popFile)
							continue
				except:
					print "do or do not, there is no try"# continue to load file
					pass
				pop = loadHapMapPop(chrom, sample)
				if logger:
					logger.info("Save population to %s." % popFile)
				pop.save(popFile)

	return pars
Esempio n. 6
0
# call function simuRareVariants to get simulated population. You can
# also call the script from command line.
#
# We only need pop file to further analysis. No .ped file is saved.
simuRareVariants(regions=['chr1:1..63000'],
                 N=(8100, 8100, 7900, 900000),
                 G=(20000, 10, 370),
                 mu=1.8e-8,
                 steps=[100, 1, 10],
                 selModel='multiplicative',
                 selDist='constant',
                 selCoef=None,
                 popFile='example.pop')

# load population
pop = sim.loadPopulation('example.pop')
# add an information field to every individual
pop.addInfoFields('trait')


def trait(geno):
    '''
    Define a quantitative trait model. geno is the genotype of each individual
    passed by pyQuanTrait. Note that this population is in mutational space so
    geno is the location instead of value of mutants. 0 values should be ignored.
    '''
    # get number of mutants
    count = len(geno) - geno.count(0)
    # N(count, 1) using simuPOP's random number generator.
    return sim.getRNG().randNormal(count, 1)
Esempio n. 7
0
	
def removeDPL(pop,DPL=['rs4491689'],savefile=False):
	"""
	Removes a locus by name and (if specified) saves the population to savefile.
	Expands upon the simuPOP.removeLoci() by returning an error if one of the DPL is already removed. 
	"""
	for locus in DPL:
		try:
			pop.removeLoci(pop.locusByName(locus))
		except ValueError:
			return "Locus %s already removed!" %locus
	if savefile:
		pop.save(savefile)
	return 0
	
if __name__=='__main__':
	popname = 'rep_1.pop'
	newDPLfile = popname.split('.')[0] + "_newDPL_loc.txt"
	
	pop = sim.loadPopulation(popname)
	print "Started with %d loci" % pop.totNumLoci()
	numRemoved,newLoc = removeRare(pop,savefile='MAFremoved_'+popname)
	print "Removed %d Loci!" % numRemoved
	print "pop now has %d loci" % pop.totNumLoci()
	
	writeSNPLoc(newLoc,newDPLfile)
	
	removeDPL_success = removeDPL(pop,savefile='DPLremoved_'+popname)
	print removeDPL_success
	removeDPL_success = removeDPL(pop,savefile='DPLremoved_'+popname)
	print removeDPL_success
popsize = 10000
females = 400
males = 400
generations = 10
replicates = 100

td = TusonDrift(genetic_map_filename=map_filename, population_size=popsize,
                number_of_breeding_females=females,
                number_of_breeding_males=males,
                number_of_generations=generations,
                founder_population_filename=founder_filename,
                population_structure_filename=popst_filename)

recom_rates = parser.parse_recombination_rates(map_filename)

tuson = sim.loadPopulation(td.founder_population_filename)
tuson.setSubPopName('tuson', 0)

sim.tagID(tuson, reset=True)
# tuson_meta = td.initialize_meta_population(tuson, number_of_reps=replicates)


# sites, inds = td.find_fixed_sites(tuson, 0.15, 0.03)
sim.stat(tuson, numOfSegSites=sim.ALL_AVAIL,
         vars=['numOfFixedSites', 'fixedSites'])

sites = tuson.dvars().fixedSites



Esempio n. 9
0
#import h5py
#import collections as col
np.set_printoptions(suppress=True, precision=3)

input_file_prefix = '/home/vakanas/BISB/rjwlab-scripts/saegus_project/devel/magic/1478/'

mg = analyze.MultiGeneration('epsilon')
run_id = 'epsilon'
generations = 10
heritability = 0.7
number_of_qtl = 50
number_of_replicates = 2
founders = [[2, 26], [3, 25], [4, 24], [5, 23]]
os_per_pair = 500
recombination_rates = [0.01] * 1478
prefounders = sim.loadPopulation(input_file_prefix + 'bia_prefounders.pop')
config_file_template = input_file_prefix + 'gwas_pipeline.xml'

sim.tagID(prefounders, reset=True)
alleles = np.array(
    pd.read_hdf(input_file_prefix + 'parameters/alleles_at_1478_loci.hdf'))

rdm_populations = sim.Simulator(prefounders,
                                number_of_replicates,
                                stealPops=False)
rdm_magic = breed.MAGIC(rdm_populations, founders, recombination_rates)
sim.tagID(prefounders, reset=27)
rdm_magic.generate_f_one(founders, os_per_pair)

sim.stat(rdm_populations.population(0), alleleFreq=sim.ALL_AVAIL)
af = analyze.allele_data(rdm_populations.population(0), alleles,
Esempio n. 10
0
pop.popSize()
pop.alleleName(1)
pop.numChrom()
pop.chromBegin(1)
ind = pop.individual(2)  # access individual
ind.chromName(0)

# fitness in infoFields

# recombination

# save and load a population
pop = sim.Population(100, loci=5, chromNames=['chrom1'])
pop.dvars().name = 'my sim.Population'
pop.save('sample.pop')
pop1 = sim.loadPopulation('sample.pop')

# genetic drift with 1 replication

pop = sim.Population(100, loci=[5])
startfreq = .5
gens = 100
steps = 10
f = open('simtest_out.txt', 'w+')
f.write('gen,freq\n')
f.close()
pop.evolve(
    initOps=[
        sim.InitGenotype(
            freq=[startfreq, 1 -
                  startfreq]),  # initalize genotypes with, 2 alleles w/ freq
Esempio n. 11
0
def test_generate_operating_population():

    genetic_map = pd.read_csv('nam_prefounders_genetic_map.txt', index_col=None,
                             sep='\t')

    pf_map = shelve.open('pf_map')
    misc_gmap = shelve.open('misc_gmap')
    uniparams = shelve.open('uniparams')

    locus_names = uniparams['locus_names']
    pos_column = uniparams['pos_column']
    allele_names = uniparams['allele_names']
    snp_to_integer = uniparams['snp_to_integer']
    integer_to_snp = uniparams['integer_to_snp']

    alleles = misc_gmap['alleles']
    chr_cM_positions = misc_gmap['chr_cM_positions']
    cM_positions = misc_gmap['cM_positions']
    integral_valued_loci = misc_gmap['integral_valued_loci']
    relative_integral_valued_loci = misc_gmap['relative_integral_valued_loci']
    recombination_rates = misc_gmap['recombination_rates']

    nam = sim.loadPopulation(uniparams['prefounder_file_name'])
    sim.tagID(nam, reset=True)
    nam.setSubPopName('maize_nam_prefounders', 0)

    selection_statistics = {
        'aggregate': {},
        'selected': {},
        'non-selected': {}
    }

    ind_names_for_gwas = {i: {} for i in range(uniparams[
        'number_of_replicates'])}
    uniparams['meta_pop_sample_sizes'] = {i: 100 for i in
                                          range(0, uniparams['generations_of_selection'] + 1, 2)
                                          }

    s = simulate.Truncation(uniparams['generations_of_selection'],
                           uniparams['generations_of_random_mating'],
                           uniparams['operating_population_size'],
                            uniparams[
                                'proportion_of_individuals_saved'],
                           uniparams['overshoot_as_proportion'],
                       uniparams['individuals_per_breeding_subpop'],
                           uniparams['heritability'],
                           uniparams['meta_pop_sample_sizes'],
                           uniparams['number_of_replicates'])

    ind_names_for_gwas = {i: {} for i in range(uniparams[
        'number_of_replicates'])}

    founders = uniparams['founders']
    replicated_nam = sim.Simulator(nam, rep=2, stealPops=False)
    pop = replicated_nam.extract(0)

    assert pop.popSize() == 26, "Population is too large."

    s.generate_f_one(pop, recombination_rates, founders, 100)

    assert pop.popSize() == 400, "Population should have size: {} after the F_1 mating " \
                                               "procedure." \
                                               "".format(len(founders) * 100)

    #pop.splitSubPop(0, [100] * 4)
    #subpop_list = list(range(pop.numSubPop()))

    intmd_os_struct = s.restructure_offspring(pop, 100, 4)
    snd_order = breed.SecondOrderPairIDChooser(intmd_os_struct, 1)

    pop.evolve(
        preOps=[sim.MergeSubPops()],
        matingScheme=sim.HomoMating(
            sim.PyParentsChooser(snd_order.snd_ord_id_pairs),
            sim.OffspringGenerator(ops=[
                sim.IdTagger(),
                sim.ParentsTagger(),
                sim.PedigreeTagger(),
                sim.Recombinator(rates=recombination_rates)
            ],
                numOffspring=1),
            subPopSize=[200],
        ),
        gen=1,
    )

    assert pop.popSize() == 1, "Population does not have correct size after second round of mating."

    second_intmd_os_struct = s.restructure_offspring(pop, 100, 2)
    third_order = breed.SecondOrderPairIDChooser(second_intmd_os_struct, 1)


    pop.evolve(
        preOps=[sim.MergeSubPops()],
        matingScheme=sim.HomoMating(
            sim.PyParentsChooser(third_order.snd_ord_id_pairs),
            sim.OffspringGenerator(ops=[
                sim.IdTagger(),
                sim.ParentsTagger(),
                sim.PedigreeTagger(),
                sim.Recombinator(rates=recombination_rates)
            ],
                numOffspring=1),
            subPopSize=[100],
        ),
        gen=1,
    )

    assert pop.popSize() == 100, "Second merge of breeding sub-populations. Offspring population does not have " \
                                 "correct size"
Esempio n. 12
0
#

# This script is an example in the simuPOP user's guide. Please refer to
# the user's guide (http://simupop.sourceforge.net/manual) for a detailed
# description of this example.
#

import simuPOP as sim
pop = sim.Population(100, loci=10)
# five copies of the same population
simu = sim.Simulator(pop, rep=5)
simu.numRep()
# evolve for ten generations and save the populations
simu.evolve(initOps=[sim.InitSex(),
                     sim.InitGenotype(freq=[0.3, 0.7])],
            matingScheme=sim.RandomMating(),
            finalOps=sim.SavePopulation('!"pop%d.pop"%rep'),
            gen=10)
# load the population and create another Simulator
simu = sim.Simulator([sim.loadPopulation('pop%d.pop' % x) for x in range(5)])
# continue to evolve
simu.evolve(matingScheme=sim.RandomMating(), gen=10)
# print out allele frequency
for pop in simu.populations():
    sim.stat(pop, alleleFreq=0)
    print('%.2f' % pop.dvars().alleleFreq[0][0])

# get a population
pop = simu.extract(0)
simu.numRep()
Esempio n. 13
0
def simuRareVariants(regions,
                     N,
                     G,
                     mu,
                     selDist,
                     selCoef,
                     selModel='exponential',
                     recRate=0,
                     splitTo=[1],
                     splitAt=0,
                     migrRate=0,
                     steps=[100],
                     mutationModel='finite_sites',
                     initPop='',
                     extMutantFile='',
                     addMutantsAt=0,
                     postHook=None,
                     statFile='',
                     popFile='',
                     markerFile='',
                     mutantFile='',
                     genotypeFile='',
                     verbose=1,
                     logger=None):
    '''
    Please refer to simuRareVariants.py -h for a detailed description of all parameters.
    Note that a user-defined function can be passed to parameter selDist to specify
    arbitrary distribution of fitness. A script-only feature is that a Python function
    can be provided through parameter postHook to process the population at each generation.
    '''
    #
    # convert regions to start/end positions
    ranges = []
    chromTypes = []
    for region in regions:
        start, end = [int(x) for x in region.split(':')[1].split('..')]
        ranges.append((start, end + 1))
        if region.split(':')[0] == 'chrX':
            chromTypes.append(sim.CHROMOSOME_X)
            if len(regions) > 1:
                raise ValueError(
                    'The current implementation only allows one region if it is on chromosome X'
                )
            logger.info('Chromosome {} is on chromosome X'.format(region))
        elif region.split(':')[0] == 'chrY':
            raise ValueError(
                'The current implementation does not support chromosome Y')
            chromTypes.append(sim.CHROMOSOME_Y)
            logger.info('Chromosome {} is on chromosome Y'.format(region))
        else:
            chromTypes.append(sim.AUTOSOME)
    if logger:
        logger.info('%s regions with a total length of %d basepair.' %
                    (len(ranges), sum([x[1] - x[0] for x in ranges])))
    #
    # set default parameter
    if selCoef is None:
        # set default parameters
        if selDist == 'mixed_gamma':
            selCoef = [0.0186, 0.0001, 0.184, 0.160 * 2, 0.5, 0.0001, 0.1]
        elif selDist == 'mixed_gamma1':
            selCoef = [0, -1, 0.562341, 0.01, 0.5, 0.00001, 0.1]
        elif selDist == 'gamma1':
            selCoef = [0.23, 0.185 * 2, 0.5]
        elif selDist == 'gamma2':
            selCoef = [0.184, 0.160 * 2, 0.5]
        elif selDist == 'gamma3':
            selCoef = [0.206, 0.146 * 2, 0.5]
        elif selDist == 'constant':
            selCoef = [0.01, 0.5]
        elif not isinstance(selDist, collections.Callable):
            raise ValueError("Unsupported random distribution")
    else:
        # force to list type
        selCoef = list(selCoef)
    if len(steps) == 0:
        # at the end of each stage
        steps = G
    elif len(steps) == 1:
        # save step for each stage
        steps = steps * len(G)
    # use a right selection operator.
    collector = fitnessCollector()
    mode = {
        'multiplicative': sim.MULTIPLICATIVE,
        'additive': sim.ADDITIVE,
        'exponential': sim.EXPONENTIAL
    }[selModel]
    #
    if type(popFile) == str:
        popFile = [popFile, -1]
    #
    if isinstance(selDist, collections.Callable):
        mySelector = MutSpaceSelector(selDist=selDist,
                                      mode=mode,
                                      output=collector.getCoef)
    elif selDist == 'mixed_gamma':
        mySelector = MutSpaceSelector(selDist=mixedGamma(selCoef),
                                      mode=mode,
                                      output=collector.getCoef)
    elif selDist == 'mixed_gamma1':
        mySelector = MutSpaceSelector(selDist=mixedGamma1(selCoef),
                                      mode=mode,
                                      output=collector.getCoef)
    elif selDist.startswith('gamma'):
        mySelector = MutSpaceSelector(selDist=[sim.GAMMA_DISTRIBUTION] +
                                      selCoef,
                                      mode=mode,
                                      output=collector.getCoef)
    elif selDist == 'constant':
        if selCoef == 0:
            mySelector = sim.NoneOp()
        else:
            mySelector = MutSpaceSelector(selDist=[sim.CONSTANT] + selCoef,
                                          mode=mode,
                                          output=collector.getCoef)
    #
    # Evolve
    if os.path.isfile(initPop):
        if logger:
            logger.info('Loading initial population %s...' % initPop)
        pop = sim.loadPopulation(initPop)
        if pop.numChrom() != len(regions):
            raise ValueError(
                'Initial population %s does not have specified regions.' %
                initPop)
        for ch, reg in enumerate(regions):
            if pop.chromName(ch) != reg:
                raise ValueError(
                    'Initial population %s does not have region %s' %
                    (initPop, reg))
        pop.addInfoFields(['fitness', 'migrate_to'])
    else:
        pop = sim.Population(size=N[0],
                             loci=[10] * len(regions),
                             chromNames=regions,
                             infoFields=['fitness', 'migrate_to'],
                             chromTypes=chromTypes)
    if logger:
        startTime = time.clock()
    #
    progGen = []
    # 0, G[0], G[0]+G[1], ..., sum(G)
    Gens = [sum(G[:i]) for i in range(len(G) + 1)]
    for i in range(len(Gens) - 1):
        progGen += list(range(Gens[i], Gens[i + 1], steps[i]))
    pop.evolve(
        initOps=sim.InitSex(),
        preOps=[
            sim.PyOutput('''Statistics outputted are
1. Generation number,
2. population size (a list),
3. number of segregation sites,
4. average number of segregation sites per individual
5. average allele frequency * 100
6. average fitness value
7. minimal fitness value of the parental population
''', at = 0)] + \
            [sim.PyOutput('Starting stage %d\n' % i, at = Gens[i]) for i in range(0, len(Gens))] + \
            # add alleles from an existing population

            [sim.IfElse(extMutantFile != '',
                ifOps = [
                    sim.PyOutput('Loading and converting population %s' % extMutantFile),
                    sim.PyOperator(func=addMutantsFrom, param=(extMutantFile, regions, logger)),
                ], at = addMutantsAt),
            # revert alleles at fixed loci to wildtype
            MutSpaceRevertFixedSites(),
            # mutate in a region at rate mu, if verbose > 2, save mutation events to a file
            MutSpaceMutator(mu, ranges, {'finite_sites':1, 'infinite_sites':2}[mutationModel],
                output='' if verbose < 2 else '>>mutations.lst'),
            # selection on all loci
            mySelector,
            # output statistics in verbose mode
            sim.IfElse(verbose > 0, ifOps=[
                sim.Stat(popSize=True, meanOfInfo='fitness', minOfInfo='fitness'),
                NumSegregationSites(),
                sim.PyEval(r'"%5d %s %5d %.6f %.6f %.6f %.6f\n" '
                    '% (gen, subPopSize, numSites, avgSites, avgFreq*100, meanOfInfo["fitness"], minOfInfo["fitness"])',
                    output='>>' + statFile),
                ], at = progGen
            ),
            sim.IfElse(len(splitTo) > 1,
                sim.Migrator(rate=migrIslandRates(migrRate, len(splitTo)),
                    begin=splitAt + 1)
            ),
        ],
        matingScheme=sim.RandomMating(ops=MutSpaceRecombinator(recRate, ranges),
            subPopSize=multiStageDemoFunc(N, G, splitTo, splitAt)),
        postOps = [
            sim.NoneOp() if postHook is None else sim.PyOperator(func=postHook),
            sim.SavePopulation(popFile[0], at=popFile[1]),
        ],
        finalOps=[
            # revert fixed sites so that the final population does not have fixed sites
            MutSpaceRevertFixedSites(),
            sim.IfElse(verbose > 0, ifOps=[
                # statistics after evolution
                sim.Stat(popSize=True),
                NumSegregationSites(),
                sim.PyEval(r'"%5d %s %5d %.6f %.6f %.6f %.6f\n" '
                    '% (gen+1, subPopSize, numSites, avgSites, avgFreq*100, meanOfInfo["fitness"], minOfInfo["fitness"])',
                    output='>>' + statFile),
                sim.PyEval(r'"Simulated population has %d individuals, %d segregation sites.'
                           r'There are on average %.1f sites per individual. Mean allele frequency is %.4f%%.\n"'
                           r'% (popSize, numSites, avgSites, avgFreq*100)'),
            ]),
        ],
        gen = Gens[-1]
    )
    # record selection coefficients to population
    if len(collector.selCoef) == 0:
        # this must be the neutral case where a NonOp has been used.
        pop.dvars().selCoef = 0
    else:
        pop.dvars().selCoef = collector.selCoef
    # re-save the file with the added selCoef
    if popFile[-1] == -1:
        pop.save(popFile[0])
    #
    if logger:
        logger.info('Population simulation takes %.2f seconds' %
                    (time.clock() - startTime))
    if markerFile or genotypeFile:
        if logger:
            logger.info('Saving marker information to file %s' % markerFile)
        mutants = saveMarkerInfoToFile(pop, markerFile, logger)
        if genotypeFile:
            if logger:
                logger.info('Saving genotype in .ped format to file %s' %
                            genotypeFile)
            saveGenotypeToFile(pop, genotypeFile, mutants, logger)
    if mutantFile:
        if logger:
            logger.info('Saving mutants to file %s' % mutantFile)
        saveMutantsToFile(pop, mutantFile, logger=logger)
    return pop
Esempio n. 14
0
            line = ListGEN.write(g + "\n")

        ListGEN.close()

#====================== Save Informations ======================#

file_to_open_3 = os.path.join(PATHF, "savepop0.pop")
file_to_open_4 = os.path.join(PATHF, "Resultats", "savepop0.pop")

shutil.copy(file_to_open_3, file_to_open_4)

for g in range(nb_gen):

    file_to_open_5 = os.path.join(PATHF, "Resultats", "savepop%d.pop" % g)

    pop = sim.loadPopulation(file_to_open_5)

    file_to_open_6 = os.path.join(PATHF, "Resultats",
                                  "myPOP_Generation_" + str(g) + ".tmp")

    export(pop,
           format='csv',
           infoFields=['sum_g1', 'z1', 'fitness'],
           output=file_to_open_6,
           gui=False)

#====================== Execute the script wich paste the gen column ======================#

file_to_open_7 = os.path.join(PATHF, "Script", "GenCol_Script.sh %s %s")

subprocess.call([file_to_open_7 % (nb_indiv, nb_gen)], shell=True)
Esempio n. 15
0
proto_prefix = 'C:\\Users\\DoubleDanks\\BISB\\wisser\\code\\rjwlab-scripts' \
               '\\saegus_project\\devel\\data_dump' \
               '\\fourth_generation_simulated_gwas\\'

run_prefix = 'rs_L10_H04\\'

tassel_input_dir_prefix = proto_prefix + run_prefix + 'tassel_input\\'
tassel_output_dir_prefix = proto_prefix + run_prefix + 'tassel_output\\'
tassel_config_prefix = proto_prefix + run_prefix + 'tassel_config_files\\'
various_simulation_info_prefix = proto_prefix + run_prefix + 'simulation_data\\'
populations_prefix = proto_prefix + run_prefix + 'populations\\'
parameter_prefix = proto_prefix + run_prefix + 'simulation_parameters\\'
ind_names_prefix = proto_prefix + run_prefix + 'ind_names\\'

nam = sim.loadPopulation(u_parameters['prefounder_file_name'])
sim.tagID(nam, reset=True)
nam.setSubPopName('maize_nam_prefounders', 0)

selection_statistics = {'aggregate': {}, 'selected': {}, 'non-selected': {}}

ind_names_for_gwas = {
    i: {}
    for i in range(u_parameters['number_of_replicates'])
}
u_parameters['meta_pop_sample_sizes'] = {
    i: 100
    for i in range(0, u_parameters['generations_of_selection'] + 1, 2)
}

s = simulate.Truncation(u_parameters['generations_of_selection'],
Esempio n. 16
0
recombination_rates = []
for chromosome in cM_positions:
    for cM in chromosome:
        if str(cM)[-2:] == '.6':
            recombination_rates.append(0.01)
        else:
            recombination_rates.append(0.0)

flat_cM_positions = []
for cMs in cM_positions:
    flat_cM_positions.extend(cMs)

# In[ ]:

nam = sim.loadPopulation('nam_prefounders.pop')
sim.tagID(nam, reset=True)
nam.setSubPopName('prefounders', 0)
sample_sizes = {i: 100 for i in range(0, 21, 2)}
locus_names = list(range(nam.totNumLoci()))

genetic_structure = {}
#genetic_structure['cM_positions'] = cM_positions
#enetic_structure['chr_cM_positions'] = chr_cM_positions
genetic_structure['allele_names'] = allele_names
genetic_structure['integral_valued_loci'] = integral_valued_loci
genetic_structure[
    'relative_integral_valued_loci'] = relative_integral_valued_loci
genetic_structure['alleles'] = alleles
genetic_structure['recombination_rates'] = recombination_rates
Esempio n. 17
0
def tuson_pop():
    tuson = sim.loadPopulation('tuson.pop')
    return tuson
Esempio n. 18
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

# This script is an example in the simuPOP user's guide. Please refer to
# the user's guide (http://simupop.sourceforge.net/manual) for a detailed
# description of this example.
#

import simuPOP as sim
from simuPOP.sampling import drawNuclearFamilySample
pop = sim.loadPopulation('log/pedigree.pop')
sample = drawNuclearFamilySample(pop,
                                 families=2,
                                 numOffspring=(2, 4),
                                 affectedParents=(1, 2),
                                 affectedOffspring=(1, 3))
# try to separate two families?
sample.asPedigree()
#= sim.Pedigree(sample, loci=sim.ALL_AVAIL, infoFields=sim.ALL_AVAIL)
sample.addInfoFields('ped_id')
# return size of families
sz = sample.identifyFamilies(pedField='ped_id')
print(sz)
ped1 = sample.extractIndividuals(IDs=0, idField='ped_id')
# print the ID of all individuals in the first pedigree
print([ind.ind_id for ind in ped1.allIndividuals()])
Esempio n. 19
0
def load_nam():
    nam = sim.loadPopulation('nam_prefounders.pop')
    return nam