예제 #1
0
def calc_average_distance(genomes):
    genetic_distance_list = []
    for genome in genomes:
        chromosome = genome[0].sequence
        random_chromosome = random.choice(genomes)[0].sequence
        genetic_distance_list.append(analytics.hamming_distance(random_chromosome, chromosome))
    return analytics.average(genetic_distance_list)
예제 #2
0
def calc_average_distance(genomes):
    genetic_distance_list = []
    for genome in genomes:
        chromosome = genome[0].sequence
        random_chromosome = random.choice(genomes)[0].sequence
        genetic_distance_list.append(
            analytics.hamming_distance(random_chromosome, chromosome))
    return analytics.average(genetic_distance_list)
예제 #3
0
    organisms = database_calls.db_reconstruct_organisms(cur, starting_time, pop_name, generation)
    organism_chromosomes = {}
    for location in locations:
        organism_chromosomes[location] = []
        for organism in organisms:
            if organism.status['location'] == location:
                organism_chromosomes[location].append(organism.genome[0].sequence)
    return organism_chromosomes

print('Writing outputfile header...')
header = [str(locations[i]).replace(", ","-") for i in range(len(locations))]
header = ['Generation'] + header
outputfile.write(','.join(header) + '\n')

print('Starting main analysis...\n')
for generation in range(1, 1001):
    print('\rInitializing generation ' + str(generation) + '...')
    chromo_db = get_chromosomes_by_location(starting_time, 'pop_01', generation)
    result = [str(generation)]
    for location in locations:
        print('\rAnalyzing location: ' + str(location) + '...')
        genetic_distance_list = []
        for chromosome in chromo_db[location]:
            random_chromosome = random.choice(chromo_db[location])
            genetic_distance_list.append(analytics.hamming_distance(random_chromosome, chromosome))
        average_distance = float(sum(genetic_distance_list))/len(genetic_distance_list)
        result.append(str(average_distance))
    outputfile.write(','.join(result) + '\n')
    print('\rGeneration ' + str(generation) + ' analysis complete...')

print('\nAnalysis complete!')
예제 #4
0
            if organism.status['location'] == location:
                organism_chromosomes[location].append(
                    organism.genome[0].sequence)
    return organism_chromosomes


print('Writing outputfile header...')
header = [str(locations[i]).replace(", ", "-") for i in range(len(locations))]
header = ['Generation'] + header
outputfile.write(','.join(header) + '\n')

print('Starting main analysis...\n')
for generation in range(1, 1001):
    print('\rInitializing generation ' + str(generation) + '...')
    chromo_db = get_chromosomes_by_location(starting_time, 'pop_01',
                                            generation)
    result = [str(generation)]
    for location in locations:
        print('\rAnalyzing location: ' + str(location) + '...')
        genetic_distance_list = []
        for chromosome in chromo_db[location]:
            random_chromosome = random.choice(chromo_db[location])
            genetic_distance_list.append(
                analytics.hamming_distance(random_chromosome, chromosome))
        average_distance = float(
            sum(genetic_distance_list)) / len(genetic_distance_list)
        result.append(str(average_distance))
    outputfile.write(','.join(result) + '\n')
    print('\rGeneration ' + str(generation) + ' analysis complete...')

print('\nAnalysis complete!')
예제 #5
0
def get_chromosomes_by_location(starting_time, pop_name, generation):
    organisms = database_calls.db_reconstruct_organisms(cur, starting_time, pop_name, generation)
    organism_chromosomes = {}
    for location in locations:
        organism_chromosomes[location] = []
        for organism in organisms:
            if organism.status['location'] == location:
                organism_chromosomes[location].append(organism.genome[0].sequence)
    return organism_chromosomes

print('Starting main analysis...\n')
for generation in [1, 100, 200, 300, 400,500, 600, 700, 800, 900, 1000]:
    print('\rInitializing generation ' + str(generation) + '...')
    chromo_db = get_chromosomes_by_location(starting_time, 'pop_01', generation)
    results = [str(generation)]
    for location1 in locations:
        for location2 in locations:
            location_results = []
            if location1 != location2:
                print('\rAnalyzing ' + str(location1) + ' and ' + str(location2) + '...')
                for organism1 in chromo_db[location1]:
                    organism_results = []
                    for organism2 in chromo_db[location2]:
                        organism_results.append(analytics.hamming_distance(organism1, organism2))
                    location_results.append(analytics.average(organism_results))
                results.append(str(analytics.average(location_results)))
    outputfile.write(','.join(results) + '\n')
    print('\rGeneration ' + str(generation) + ' analysis complete...')

print('Simulation Anaysis Complete!')