To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit f5ceab0b authored by Eva Bons's avatar Eva Bons

install working with python3

parent 62ee2852
from gui import gui_run
from .gui import gui_run
from . import scenarios
import os
from collections import OrderedDict
import pkg_resources
import matplotlib
matplotlib.use('TkAgg')
from appJar import gui
import yaml
import scenarios
from . import scenarios
import fasta_tools
......@@ -14,11 +15,10 @@ def select():
selection = app.getAllOptionBoxes()
#display default settings organism
dir_path = os.path.dirname(os.path.realpath(__file__))
dir_path_up = os.sep.join(dir_path.split(os.sep)[:-1])
sim_settings_path = dir_path_up+os.sep+'SeqSimEvo'+os.sep+'simulation_settings/'
scenario_settings_path = dir_path_up+os.sep+'Scenarios'+os.sep+'settings_files/'
global sim_settings_path
sim_settings_path = pkg_resources.resource_filename('SeqSimEvo','simulation_settings/')
global scenario_settings_path
scenario_settings_path = pkg_resources.resource_filename('SeqSimEvo','Scenarios/settings_files/')
with open(sim_settings_path+selection['Organism']) as f:
OrgSettings = f.read()
app.clearTextArea('OrgSet')
......@@ -40,7 +40,7 @@ def settings_press(btn):
if btn == 'save organism settings':
#specify file location
filename = app.saveBox(title='Save organism settings',
dirName='../seq_sim/simulation_settings',
dirName=sim_settings_path,
fileExt="")
#save file
with open(filename, 'w') as f:
......@@ -48,7 +48,7 @@ def settings_press(btn):
elif btn == 'save scenario settings':
#specify file location
filename = app.saveBox(title='Save scenario settings',
dirName='settings_files/',
dirName=scenario_settings_path,
fileExt="")
#save file
with open(filename, 'w') as f:
......@@ -72,15 +72,14 @@ def settings_press(btn):
def gui_run():
os.chdir(os.path.dirname(os.path.abspath(__file__)))
global app
with gui('SeqSim') as app:
global app
dir_path = os.path.dirname(os.path.realpath(__file__))
dir_path_up = os.sep.join(dir_path.split(os.sep)[:-1])
sim_settings_path = dir_path_up+os.sep+'SeqSimEvo'+os.sep+'simulation_settings/'
sim_settings_path = pkg_resources.resource_filename('SeqSimEvo','simulation_settings/')
scenario_settings_path = pkg_resources.resource_filename('SeqSimEvo','Scenarios/settings_files/')
Organism_options = os.listdir(sim_settings_path)
app.addLabelOptionBox('Organism',Organism_options)
scenario_settings_path = dir_path_up+os.sep+'Scenarios'+os.sep+'settings_files/'
Scenario_options = os.listdir(scenario_settings_path)
app.addLabelOptionBox('Scenario',Scenario_options)
......
......@@ -55,6 +55,8 @@ class multiple_compartments(object):
n_seq = n_seq_init[i]
except IndexError:
n_seq = n_seq_init[0]
except TypeError:
n_seq = n_seq_init
if names is not None:
......@@ -132,74 +134,77 @@ def run(scenario_settings,organism_settings):
return fasta
if __name__ == '__main__':
import argparse
import ast
parser = argparse.ArgumentParser(description='simulation of evolution in multiple compartments')
parser.add_argument('-o', type=str,default='HIV',
help='organism settings to use, defaults to HIV')
parser.add_argument('-nc', type=int,default=2,
help='number of compartments to simulate. Defaults to 2')
parser.add_argument('-ng', type=int,default=100,
help='number of generations to simulate. Defaults to 100')
parser.add_argument('-d', type=float,default=0,
help='how different the fitness tables are for each of \
the compartments (0 - all the same, parallel \
evolution, 1 - all different, complete divergent \
evolution). Defaults to 0')
parser.add_argument('-mig',default='[[0,0],[0,0]]',type=str,
help='migration rate matrix, \
or single value (use migration rate between all populations),\
defaults to no migration')
parser.add_argument('-names',nargs='+',default = None,
help='names of the compartments')
parser.add_argument('-ninit',nargs='+',default = None,type=int,
help='number of initial sequences per compartment, defaults to one per compartment')
parser.add_argument('-mut',nargs='+',default = None,type=float,
help='mutation rates per compartment, defaults to the value in the organism settings')
parser.add_argument('-R0',nargs='+',default = None,type=float,
help='R0 per compartment')
parser.add_argument('-maxpop',nargs='+',default = None,type=int,
help='maximum population per compartment')
parser.add_argument('-st',nargs='+',default = None,type=int,
help='sampling times per compartment,defaults to last')
parser.add_argument('-sa', nargs='+',default=10,type=int,
help='sampling amount per compartment,defaults to 10')
args = parser.parse_args()
settings = {}
settings['n_comparments'] = args.nc
settings['diverse_index'] = args.d
settings['n_gen'] = args.ng
if '[' not in args.mig:
settings['migration'] = np.ones([len(args.ninit)]*2)*float(args.mig[0])
else:
settings['migration'] = ast.literal_eval(args.mig)
def main():
import argparse
import ast
parser = argparse.ArgumentParser(description='simulation of evolution in multiple compartments')
parser.add_argument('-o', type=str,default='HIV',
help='organism settings to use, defaults to HIV')
parser.add_argument('-nc', type=int,default=2,
help='number of compartments to simulate. Defaults to 2')
parser.add_argument('-ng', type=int,default=100,
help='number of generations to simulate. Defaults to 100')
parser.add_argument('-d', type=float,default=0,
help='how different the fitness tables are for each of \
the compartments (0 - all the same, parallel \
evolution, 1 - all different, complete divergent \
evolution). Defaults to 0')
parser.add_argument('-mig',default='[[0,0],[0,0]]',type=str,
help='migration rate matrix, \
or single value (use migration rate between all populations),\
defaults to no migration')
parser.add_argument('-names',nargs='+',default = None,
help='names of the compartments')
parser.add_argument('-ninit',nargs='+',default = None,type=int,
help='number of initial sequences per compartment, defaults to one per compartment')
parser.add_argument('-mut',nargs='+',default = None,type=float,
help='mutation rates per compartment, defaults to the value in the organism settings')
parser.add_argument('-R0',nargs='+',default = None,type=float,
help='R0 per compartment')
parser.add_argument('-maxpop',nargs='+',default = None,type=int,
help='maximum population per compartment')
parser.add_argument('-st',nargs='+',default = None,type=int,
help='sampling times per compartment,defaults to last')
parser.add_argument('-sa', nargs='+',default=10,type=int,
help='sampling amount per compartment,defaults to 10')
args = parser.parse_args()
settings = {}
settings['n_comparments'] = args.nc
settings['diverse_index'] = args.d
settings['n_gen'] = args.ng
if '[' not in args.mig:
settings['migration'] = np.ones([len(args.ninit)]*2)*float(args.mig[0])
else:
settings['migration'] = ast.literal_eval(args.mig)
settings['sampling_amount'] = args.sa
settings['sampling_amount'] = args.sa
if args.st is None:
settings['sampling_times'] = [args.ng]
else:
settings['sampling_times'] = args.st
if args.st is None:
settings['sampling_times'] = [args.ng]
else:
settings['sampling_times'] = args.st
if args.names is not None:
settings['names'] = args.names
if args.names is not None:
settings['names'] = args.names
if args.ninit is not None:
settings['n_seq_init'] = args.ninit
if args.ninit is not None:
settings['n_seq_init'] = args.ninit
if args.mut is not None:
settings['mut_rate'] = args.mut
if args.mut is not None:
settings['mut_rate'] = args.mut
if args.R0 is not None:
settings['R0'] = args.R0
if args.R0 is not None:
settings['R0'] = args.R0
if args.maxpop is not None:
settings['max_pop'] = args.maxpop
if args.maxpop is not None:
settings['max_pop'] = args.maxpop
print(run(settings, args.o))
print(run(settings, args.o))
if __name__ == '__main__':
main()
......@@ -123,7 +123,7 @@ def recreate_dataset(sample_sizes,nr_mutations,apobec,model=None,parameters=None
elif action == 'fasta':
return fasta
if __name__ == '__main__':
def main():
import argparse
#parse command line arguments
......@@ -192,3 +192,6 @@ if __name__ == '__main__':
if (action == 'n_generations') or (action == 'fasta'):
print(simulation)
if __name__ == '__main__':
main()
......@@ -7,7 +7,7 @@ preforms a simple simulation of sequence evolution
from __future__ import print_function
import argparse
import SeqSimEvo as seq_sim
import SeqSimEvo.simulation as seq_sim
def run(scenario_settings, sim_settings):
sim = seq_sim.Simulation(simulation_settings=sim_settings)
......@@ -28,7 +28,7 @@ def run(scenario_settings, sim_settings):
return output
if __name__ == '__main__':
def main():
#parse command line arguments
parser = argparse.ArgumentParser(description='simple simulation of sequence evolution')
parser.add_argument('-n', nargs=1, type=int,
......@@ -63,3 +63,6 @@ if __name__ == '__main__':
#run scenario
print(run(settings, args.o))
if __name__ == '__main__':
main()
from SeqSimEvo.simulation import *
from . import simulation
from . import GUI
from . import Scenarios
from . import binary_fission
......@@ -10,8 +10,9 @@ All other functionalities (calculation of fitness, mutating sequences, etc.) are
as in the original simulation code
'''
import simulation as sim
from simulation import Population, Seq
from __future__ import print_function
from . import simulation as sim
from .simulation import Population, Seq
import random
class Simulation(sim.Simulation):
......@@ -53,7 +54,7 @@ class Simulation(sim.Simulation):
self.current_gen.delete_sequence(to_del)
elif n_seq == 0:
print 'died out'
print('died out')
raise NotImplementedError('population died out')
self.n_seq = len(self.current_gen)
......@@ -65,4 +66,4 @@ if __name__ == '__main__':
sim_test = Simulation(R0 = 2,max_pop=10000,n_seq_init=1000)
for i in tqdm(range(50)):
sim_test.new_generation()
print sim_test.current_gen
print(sim_test.current_gen)
......@@ -4,6 +4,7 @@ Created on Thu Dec 15 13:42:33 2016
@author: eva
"""
from __future__ import print_function
import pkg_resources
import sys
from collections import Counter
import random
......@@ -153,12 +154,15 @@ class Simulation(object):
fitness_table (4xseq_len): fitness table to use for the simulation
n_seq_init (int): initial number of sequences (default 1)
'''
if type(simulation_settings) is list:
simulation_settings = simulation_settings[0]
try:
with open(simulation_settings) as f:
self.settings = yaml.safe_load(f)
except IOError:
path = os.path.dirname(os.path.abspath(inspect.stack()[0][1]))
with open(path+'/simulation_settings/'+simulation_settings) as f:
path = pkg_resources.resource_filename('SeqSimEvo','simulation_settings/')
with open(path+simulation_settings) as f:
self.settings = yaml.safe_load(f)
except TypeError:
self.settings = simulation_settings
......@@ -166,8 +170,6 @@ class Simulation(object):
for key, value in kwargs.items():
self.settings[key] = value
self.settings['subs_matrix'] = np.array(self.settings['subs_matrix'])
#adapt mutation rate for APOBEC increase in G-to-A mutations
......
(c) 2019 Eva Bons
# seq_sim - simulations of viral diversification
## installation
First, make sure you have a working python installation (2.7/3.6), with the following packages installed
* numpy
* scipy
* pyyaml
* Tqdm
* Ete3
* Ipython
* matplotlib
Currently, I have not managed to find an easy way to install/manage packages, sorry!
To install, you'll have to manually put the `seq_sim` folder somewhere in your `PYTHONPATH`
## usage
# SeqSimEvo - simulations of sequence evolution with selection
## Installation
installation requires a working installation of python (v2.7 or higher)
python setup.py install
## Usage
Simulations can be run in several ways:
* run a pre-existing scenario
### initialize the simulation
import seq_sim
......
"""A setuptools based setup module.
See:
https://packaging.python.org/guides/distributing-packages-using-setuptools/
https://github.com/pypa/sampleproject
"""
# Always prefer setuptools over distutils
from setuptools import setup, find_packages
from os import path
......@@ -32,23 +26,25 @@ setup(
author='Eva Bons',
author_email='eva.bons@gmail.com',
packages=find_packages(exclude=['contrib', 'docs', 'tests']),
packages=find_packages(exclude=['contrib', 'docs', 'Tests']),
python_requires='>=2.7',
install_requires=['matplotlib==2.2','appJar','pyyaml','numpy==1.15','tqdm','scipy==1.1'],
install_requires=['matplotlib==2.2','appJar','pyyaml','numpy==1.15.1','tqdm','scipy==1.1'],
package_data={
'Scenarios': ['settings_files/*'],
'SeqSimEvo': ['simulation_settings/*']
'SeqSimEvo': ['simulation_settings/*','Scenarios/settings_files/*']
},
entry_points={
'console_scripts': [
'SeqSimEvo=GUI:gui_run',
'SeqSimEvo_gui=SeqSimEvo.GUI:gui_run',
'SeqSimEvo_multipleCompartments=SeqSimEvo.Scenarios:multiple_compartments.main',
'SeqSimEvo_recreateDataset=SeqSimEvo.Scenarios:recreate_dataset.main',
'SeqSimEvo_simpleSim=SeqSimEvo.Scenarios:simple_sim.main'
],
},
project_urls={ # Optional
project_urls={
'Bug Reports': '',
'Funding': '',
'Source': '',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment