def replicate(self, current_time): #, convenient_id=None):
		"""
		This method replicates the pathogen once. Mutation is guaranteed to be 
		called, but not guaranteed to happen, as it depends on the 
		substitution rate of each of the genomic segments.

		INPUTS:
		-	INT: current_time
				This number will be set to the "creation_time" of the new 
				pathogen.


		OUTPUTS:
		-	OBJECT: new_pathogen
				The replicated pathogen.
		"""
		new_pathogen = copy(self)
		new_pathogen.parent = dict()
		new_pathogen.parent[self] = self.get_segment_numbers()
		new_pathogen.creation_time = current_time
		new_pathogen.id = generate_id()
		new_pathogen.segments = deepcopy(self.segments)
		new_pathogen.mutate()

		# print new_pathogen.parent
		return new_pathogen
Ejemplo n.º 2
0
    def replicate(self, current_time):  #, convenient_id=None):
        """
		This method replicates the pathogen once. Mutation is guaranteed to be 
		called, but not guaranteed to happen, as it depends on the 
		substitution rate of each of the genomic segments.

		INPUTS:
		-	INT: current_time
				This number will be set to the "creation_time" of the new 
				pathogen.


		OUTPUTS:
		-	OBJECT: new_pathogen
				The replicated pathogen.
		"""
        new_pathogen = copy(self)
        new_pathogen.parent = dict()
        new_pathogen.parent[self] = self.get_segment_numbers()
        new_pathogen.creation_time = current_time
        new_pathogen.id = generate_id()
        new_pathogen.segments = deepcopy(self.segments)
        new_pathogen.mutate()

        # print new_pathogen.parent
        return new_pathogen
	def reassort_with(self, other, current_time): 
		"""
		This method takes in another pathogen and returns a progeny with 
		genomic segments that are randomly selected from segments from both
		pathogens. Reassortment with another pathogen is akin to 
		replication, but the step at which segments are added is different.

		INPUTS:
		-	OBJECT: other
				The other pathogen with which to reassort.

		-	INT: current_time
				The time at which the reassortment event happened.


		OUTPUTS:
		-	OBJECT: new_pathogen
				The reassortant progeny from the two pathogens.
		"""

		new_pathogen = copy(self)
		new_pathogen.creation_time = current_time
		new_pathogen.id = generate_id()
		new_pathogen.segments = []
		
		# Assign parent differently from the replicate() function.
		parent = dict()
		parent[self] = []
		parent[other] = []

		# Iterate over all of the segments.
		for segment in self.segments:
			i = choice([0, 1])
			segment_number = segment.segment_number
			segments_to_choose_from = (segment, \
				other.get_segment(segment_number))
			new_pathogen.segments.append(deepcopy(segments_to_choose_from[i]))
			if i == 0:
				parent[self].append(segments_to_choose_from[0].segment_number)
			if i == 1:
				parent[other].append(segments_to_choose_from[1].segment_number)

		# Clean the dictionary if the progeny is entirely derived from one 
		# parent.
		if parent[self] == []:
			del parent[self]
		if parent[other] == []:
			del parent[other]

		new_pathogen.parent = parent

		new_pathogen.mutate()

		# print new_pathogen.parent
		return new_pathogen
Ejemplo n.º 4
0
    def reassort_with(self, other, current_time):
        """
		This method takes in another pathogen and returns a progeny with 
		genomic segments that are randomly selected from segments from both
		pathogens. Reassortment with another pathogen is akin to 
		replication, but the step at which segments are added is different.

		INPUTS:
		-	OBJECT: other
				The other pathogen with which to reassort.

		-	INT: current_time
				The time at which the reassortment event happened.


		OUTPUTS:
		-	OBJECT: new_pathogen
				The reassortant progeny from the two pathogens.
		"""

        new_pathogen = copy(self)
        new_pathogen.creation_time = current_time
        new_pathogen.id = generate_id()
        new_pathogen.segments = []

        # Assign parent differently from the replicate() function.
        parent = dict()
        parent[self] = []
        parent[other] = []

        # Iterate over all of the segments.
        for segment in self.segments:
            i = choice([0, 1])
            segment_number = segment.segment_number
            segments_to_choose_from = (segment, \
             other.get_segment(segment_number))
            new_pathogen.segments.append(deepcopy(segments_to_choose_from[i]))
            if i == 0:
                parent[self].append(segments_to_choose_from[0].segment_number)
            if i == 1:
                parent[other].append(segments_to_choose_from[1].segment_number)

        # Clean the dictionary if the progeny is entirely derived from one
        # parent.
        if parent[self] == []:
            del parent[self]
        if parent[other] == []:
            del parent[other]

        new_pathogen.parent = parent

        new_pathogen.mutate()

        # print new_pathogen.parent
        return new_pathogen
Ejemplo n.º 5
0
def send_code():
    id = generate_id()

    params = {
        'email': request.form['email'],
        'sms': request.form['sms'],
        'phone': request.form['phone'],
        'emailAddress': request.form['emailAddress'],
        'captcha': request.form['captcha']
    }

    captcha_response = req.post(
        "https://www.google.com/recaptcha/api/siteverify",
        data={
            'secret': os.environ.get("recaptcha_id_pro"),
            'response': params['captcha']
        })

    if not json.loads(captcha_response.text)['success']:
        abort(403)

    if params['sms'] == "true" and params['email'] == "true":
        if verify_phone_not_present(
                params['phone']) and verify_email_not_present(
                    params['emailAddress']):
            insert_id(id, params['emailAddress'], params['phone'])
            send_message(params['phone'], id)
            send_email(params['emailAddress'], id)
        else:
            if not verify_email_not_present(params['emailAddress']):
                send_recovery_email(params['emailAddress'],
                                    get_id_by_email(params['emailAddress']))
            if not verify_phone_not_present(params['phone']):
                send_recovery_message(params['phone'],
                                      get_id_by_phone(params['phone']))
    elif params['sms'] == "true":
        if verify_phone_not_present(params['phone']):
            insert_id(id, "-", params['phone'])
            send_message(params['phone'], id)
        else:
            send_recovery_message(params['phone'],
                                  get_id_by_phone(params['phone']))
    elif params['email'] == "true":
        if verify_email_not_present(params['emailAddress']):
            insert_id(id, params['emailAddress'], "-")
            send_email(params['emailAddress'], id)
        else:
            send_recovery_email(params['emailAddress'],
                                get_id_by_email(params['emailAddress']))
    else:
        abort(400)

    return json.dumps(params)
Ejemplo n.º 6
0
def generate():
    if request.method == 'POST':
        id_number = generate_id(
            request.data.get('first_name', ''),
            request.data.get('father_name', ''),
            request.data.get('last_name', ''),
            request.data.get('mother_name', ''),
            request.data.get('gender', ''),
            request.data.get('birthday_day', ''),
            request.data.get('birthday_month', ''),
            request.data.get('birthday_year', '')
        )
        return {'hash': id_number}, status.HTTP_201_CREATED
    else:
        return {'message': 'Please use POST'}
	def __init__(self, segments, creation_time, progeny_size, \
		parent=dict(), convenient_id=None):
		"""
		Initialize the pathogen.

		ATTRIBUTES:
		-	LIST: segments
				a list of Segment objects that specify the genomic segments 
				that are present in the pathogen.

		-	INT: creation_time
				an integer number that specifies the time within the 
				simulation that the pathogen was created.

		- 	DICTIONARY: parent
				A dictionary that specifies the parent of the pathogen. 
				The (key, value) pairs are (parent, segments transmitted).
					-	If the dictionary is empty, then the pathogen is a seed pathogen.
					-	If the dictionary has one (key, value) pair, then the pathogen was replicated from one other pathogen.
					-	If the dictionary has two (key, value) pairs, then the pathogen was a reassortant of two parental pathogens.

		-	STRING: id
				a string generated form the generate_id function that uniquely 
				identifies the pathogen.

		-	TUPLE: progeny_size
				a two-tuple that describes the (mean, var) of the burst size 
				per pathogen. These are the Normal distribution parameters. In 
				practice, while a floating point number is drawn from the 
				Normal distribution, it will be rounded to an integer number.
		"""
		super(Pathogen, self).__init__()

		self.segments = segments

		self.creation_time = creation_time

		self.parent = parent

		self.id = generate_id()

		# self.convenient_id = self.id[0:5]

		self.progeny_size = progeny_size
Ejemplo n.º 8
0
    def __init__(self, segments, creation_time, progeny_size, \
     parent=dict(), convenient_id=None):
        """
		Initialize the pathogen.

		ATTRIBUTES:
		-	LIST: segments
				a list of Segment objects that specify the genomic segments 
				that are present in the pathogen.

		-	INT: creation_time
				an integer number that specifies the time within the 
				simulation that the pathogen was created.

		- 	DICTIONARY: parent
				A dictionary that specifies the parent of the pathogen. 
				The (key, value) pairs are (parent, segments transmitted).
					-	If the dictionary is empty, then the pathogen is a seed pathogen.
					-	If the dictionary has one (key, value) pair, then the pathogen was replicated from one other pathogen.
					-	If the dictionary has two (key, value) pairs, then the pathogen was a reassortant of two parental pathogens.

		-	STRING: id
				a string generated form the generate_id function that uniquely 
				identifies the pathogen.

		-	TUPLE: progeny_size
				a two-tuple that describes the (mean, var) of the burst size 
				per pathogen. These are the Normal distribution parameters. In 
				practice, while a floating point number is drawn from the 
				Normal distribution, it will be rounded to an integer number.
		"""
        super(Pathogen, self).__init__()

        self.segments = segments

        self.creation_time = creation_time

        self.parent = parent

        self.id = generate_id()

        # self.convenient_id = self.id[0:5]

        self.progeny_size = progeny_size
Ejemplo n.º 9
0
	def __init__(self, length=1000, sequence=None, id=None):
		"""
		Initialize the sequence with a random sequence of length 1000 if 
		sequence is not specified.

		Otherwise, initialize sequence with a sequence that is specified. 
		"""
		super(Sequence, self).__init__()

		self.sequence = None

		if sequence == None:
			self.sequence = self.generate_sequence(length)
		else:
			self.sequence = sequence

		if id == None:
			self.id = generate_id()
		else:
			self.id = id
Ejemplo n.º 10
0
def index(request):
    if request.method == 'POST':
        if 'RDS_HOSTNAME' in os.environ:
            DATABASES = {
                'default': {
                    'ENGINE': 'django.db.backends.mysql',
                    'NAME': os.environ['RDS_DB_NAME'],
                    'USER': os.environ['RDS_USERNAME'],
                    'PASSWORD': os.environ['RDS_PASSWORD'],
                    'HOST': os.environ['RDS_HOSTNAME'],
                    'PORT': os.environ['RDS_PORT'],
                }
            }

            cnx = mysql.connector.connect(
                user=DATABASES['default']['USER'],
                password=DATABASES['default']['PASSWORD'],
                database=DATABASES['default']['NAME'],
                host=DATABASES['default']['HOST'],
                port=DATABASES['default']['PORT'])
            cursor = cnx.cursor()

            #Begin Database Work
            try:  #this is to make a table
                cursor.execute('DROP TABLE jobs')
                cursor.execute(
                    'CREATE TABLE IF NOT EXISTS joblist (email VARCHAR(100), id VARCHAR(200), submit_time VARCHAR(200), jobstarted BOOLEAN, finish_time VARCHAR(200), jobfinished BOOLEAN);'
                )
                cnx.commit()
            except:
                pass
            #End Database Work

            uid = str(generate_id())

            cursor.execute(
                "INSERT INTO joblist (email,id,submit_time,jobstarted,finish_time,jobfinished) VALUES ('"
                + request.POST.get('email', '') + "','" + uid + "','" +
                str(time.time()) + "',FALSE,null,FALSE);")
            cnx.commit()

            cursor.execute("SELECT * FROM joblist")

            res = ''
            for entry in cursor:
                res += str(entry) + '<br>'

            cursor.close()
            cnx.close()

            sigma_cfg = make_cfg(request.POST, request.FILES, uid)

            if (request.POST.get("read_type", "ERROR") == "single"):
                f = default_storage.open(
                    uid + '/' + request.FILES["single_file"].name, 'wb')
                f.write(request.FILES["single_file"].read())
                f.close()
            else:
                f = default_storage.open(
                    uid + '/' + request.FILES["paired_file1"].name, 'wb')
                f.write(request.FILES["paired_file1"].read())
                f.close()

                f = default_storage.open(
                    uid + '/' + request.FILES["paired_file2"].name, 'wb')
                f.write(request.FILES["paired_file2"].read())
                f.close()

            f = default_storage.open(uid + '/sigma_config.cfg', 'w')
            f.write(sigma_cfg)
            f.close()

            #Thread(target=debug_call, args=(uid,)).start()

            #subprocess.Popen(['sh','/opt/python/current/app/run_job.sh', uid], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

            return HttpResponse(
                'Your job is now in the queue.<br><br>Your unique id for this job is: '
                + str(uid) +
                '<br><br>If you did not enter your email SAVE THIS LINK: YOUR SITE DOMAIN/results/'
                + str(uid))

        return HttpResponse('DB Error!')

    else:
        return render(request, 'sigma.html')