def mask_genes(self):
		for chr in self.get_chrs():
			#fh = open(get_path("reference_sequence." + chr + ".fasta"), "r")
			#line = fh.readline()
			#seq = fh.readline()
			#fh.close
			#print(chr, line, len(seq))
			line, fseq = self.get_header_seq("reference_sequence." + chr + ".fasta")
			rseq = fseq
			print(chr, line, len(fseq))
			out = self.get_stend_pos_genes(chr)
			#print(seq[335517:336000])
			for row in out:
				#print(row['start'], row['end']);
				st = int(row['start']) - 1
				en = int(row['end'])
				xing = "X" * (en - st)
				if row['strand'] == '+':
					fseq = fseq[:st] + xing + fseq[en:]
				if row['strand'] == '-':
					rseq = rseq[:st] + xing + rseq[en:]
				#print(seq[335517:336000])
			fh = open(get_path("reference_sequence." + chr + ".masked.forward.fasta"), "w")
			fh.write(line + fseq)
			fh.close()
			fh = open(get_path("reference_sequence." + chr + ".masked.reverse.fasta"), "w")
			fh.write(line + rseq)
			fh.close()
Example #2
0
def print_value(cbor_data):
    path = helpers.get_path()
    if len(path) == 1:
        return cbor_data
    else:
        path.pop(0)
        return get_value(path, cbor_data)
def a_star(maze, start, goal):
    pq = PriorityQueue()
    # In the A* trace we said that the F value for the initial cell position would be equal to
    # the H value...but we are not required to have to calculate that manually because there's only
    # going to be one item on the queue at this point, it will automatically
    # have the highest priority so we can set it equal to 0
    pq.put(start, 0)
    predecessors = {start: None}
    g_values = {start: 0}
    # In our representation of these mazes, we have cells connected by edges and the weight
    # of each edge is just one. So the new cost is just one more than the previous cost
    # putting it in g values and in predecessors is equivalent to saying *we've discovered this

    while not pq.is_empty():
        current_cell = pq.get()
        if current_cell == goal:
            return get_path(predecessors, start, goal)
        for direction in ["up", "right", "down", "left"]:
            row_offset, col_offset = offsets[direction]
            neighbour = (current_cell[0] + row_offset,
                         current_cell[1] + col_offset)
            if is_legal_pos(maze, neighbour) and neighbour not in g_values:
                new_cost = g_values[current_cell] + 1
                g_values[neighbour] = new_cost
                f_value = new_cost + heuristic(goal, neighbour)
                pq.put(neighbour, f_value)
                predecessors[neighbour] = current_cell
        return None
def dfs(maze, start, goal):
    # We instantiate a new stack
    stack = Stack()
    # We're pushing our start position which is a coordinate/row, column tuples (an immutable list)
    stack.push(start)
    #     predecessors is a dictionary containing the predecessor of the start position, which is none
    predecessors = {start: None}

    while not stack.is_empty():
        # While the stack is not empty, we get the current cell by popping
        current_cell = stack.pop()
        # We check if it's the goal, if it is, the program is finished!
        if current_cell == goal:
            return get_path(predecessors, start, goal)
        # Otherwise, for every direction in this list, we check the offsets (imported from helper
        # file and we assign the i, j values from from that so that we can then check the neighbor
        # The whole point of this is to check the coordinates of the contiguous cells in all four directions
        for direction in ["up", "right", "down", "left"]:
            row_offset, col_offset = offsets[direction]
            # neighbor refers to the cell
            neighbor = (current_cell[0] + row_offset, current_cell[1] + col_offset)
            # now we say, for each of those directions, if it's a legal position and it doesn't already exist in our
            # predecessors list, that means we haven't discovered it yet - so we push it on to our stack.
            if is_legal_pos(maze, neighbor) and neighbor not in predecessors:
                # finally we push the neighbor on the stack and update the predecessors
                stack.push(neighbor)
                predecessors[neighbor] = current_cell
    return None
Example #5
0
def update_value(cbor_data):
    path = helpers.get_path()
    new_data = input(messages.tool_update_request)
    if len(path) == 1:
        return new_data
    else:
        path.pop(0)
        return change_value(path, cbor_data, new_data)
Example #6
0
    def say(self, text):
        from config import USE_TTS_LANGUAGE

        # Fetch the fill path for the tts_result.mp3 in which the TTS results will be saved
        file_name = get_path('/resources/audio/tts_result.mp3')
        if os.path.isfile(file_name) is False:
            debug(str(file_name) + "File does not exists")
        tts = gTTS(text=str(text), lang=USE_TTS_LANGUAGE)
        tts.save(file_name)
        self.play_mp3_file(file_name)
Example #7
0
    def listen(self):
        r = sr.Recognizer()
        with sr.Microphone() as source:
            debug("Say something!")
            audio = r.listen(source)

            # Write audio to a file which we will send to the API
            with open(get_path("/resources/audio/microphone-results.wav"),
                      "wb") as f:
                f.write(audio.get_wav_data())
Example #8
0
def dfs(maze, start, goal, pred={}):
    offs = {
        "down": (1, 0),
        "right": (0, 1),
        "up": (-1, 0),
        "left": (0, -1),
    }
    res_pred = dfs1(maze, start, goal, offs, {}, [False])
    print(res_pred)
    return get_path(res_pred, start, goal)
def brute_force(start, goal, max_reactions, reaction_dict):
    print_list = []
    print_list.append((start, "starting molecule"))
    print_list.append((goal, "goal molecule"))

    counter = 0
    start_node = molecule_path_node(start, 0, 0, "start")
    lst = [start_node]
    returnv = False
    while (lst[counter].reactions < max_reactions
           and (not (test_molecule_isomorphism((lst[counter].molec), goal)))):
        #x = deepcopy(lst[counter].molec)
        for j in reaction_dict:
            # apply every possible reaction
            x = deepcopy(lst[counter].molec)
            products = reaction_dict[j](x)
            product_nodes = []
            for i in products:
                product_nodes.append(
                    molecule_path_node(i, counter, lst[counter].reactions + 1,
                                       j))
            lst = lst + product_nodes
        counter = counter + 1
    if test_molecule_isomorphism(lst[counter].molec, goal):
        print_list = print_list + (get_path(lst, counter))
        print(lst[counter].molec.bonds)  # here
        print(goal)
        returnv = True
    else:
        while counter < len(lst):
            if test_molecule_isomorphism(lst[counter].molec, goal):
                print_list = print_list + (get_path(lst, counter))
                print(lst[counter].molec.bonds)  # here
                print(goal)
                returnv = True
                break
            else:
                counter = counter + 1
    #print(test_molecule_isomorphism(lst[counter].molec, goal))
    print(returnv)
    return print_list
	def split_promoters(self):
		fh = open(get_path('promoters.sql.10000.txt'), 'r')
		fh_5000 = open(get_path('promoters.sql.5000.txt'), 'w')
		fh_2000 = open(get_path('promoters.sql.2000.txt'), 'w')
		fh_1000 = open(get_path('promoters.sql.1000.txt'), 'w')
		fh_500 = open(get_path('promoters.sql.500.txt'), 'w')

		for line in fh:
			line = line.rstrip("\r|\n")
			cols = line.split("\t")
			astring = "\t".join(cols[0:5])
			print(astring)
			fh_5000.write(astring + "\t" + cols[5][0:5001] + "\n")
			fh_2000.write(astring + "\t" + cols[5][0:2001] + "\n")
			fh_1000.write(astring + "\t" + cols[5][0:1001] + "\n")
			fh_500.write(astring + "\t" + cols[5][0:501] + "\n")
		fh_5000.close()
		fh_2000.close()
		fh_1000.close()
		fh_500.close()
		fh.close()
Example #11
0
    def get_intent(self, audio_path):
        # Create the API client
        client = Wit(api_key)

        # Send the .wav file we've created earlier to the API
        try:
            with open(get_path('/resources/audio/microphone-results.wav'),
                      'rb') as f:
                resp = client.speech(f, None, {'Content-Type': 'audio/wav'})
                return resp
        except:
            debug("Microphone-results failed to open")
Example #12
0
def bfs(start,goal):
    # dimension of the square puzzle
    n = len(start)
    
    # offsets for movements in the list
    offsets = {
    "right": 1,
    "left": -1,
    "up": -n,
    "down": n
    }

    # converting matrix to string
    start_state = "".join(matrix_to_lst(start))
    goal_state = "".join(matrix_to_lst(goal))
    
    queue = Queue()
    queue.enqueue(start_state)
    predecessors = {start_state: None}
    
    
    while not queue.is_empty():
        
        # pop off first state in the queue
        current_state = queue.dequeue()
        
        # check if it is the goal itself
        if current_state == goal_state:
            return get_path(predecessors, start_state, goal_state)
    
        
        current_state_lst = list(current_state)  # convert string to list, because swap is not possible on strings(immutable)
        blank_pos = current_state_lst.index('A') # find position of blank tile
        
        
        for direction in ["up", "right", "down", "left"]:
            current_copy = copy.deepcopy(current_state_lst) # deepcopy to protect current_state_lst itself from modification
            new_blank_pos = blank_pos + offsets[direction]
            
            if new_blank_pos >= 0 and new_blank_pos < n**2 : # check for valid location before swapping tile
                current_copy[blank_pos], current_copy[new_blank_pos] = current_copy[new_blank_pos], current_copy[blank_pos] # swap operation
                neighbour = "".join(current_copy) # convert to string
                            
            else: 
                continue # if invalid location, continue to next direction
            
            
            if neighbour not in predecessors: 
                queue.enqueue(neighbour) # add neighbour to exploration queue
                predecessors[neighbour] = current_state # add neighbour to the parent-child dictionary for backtracking

    return None
Example #13
0
def bfs(maze, start, goal):
    q = Queue()
    q.enqueue(start)
    pred = {start: None}

    while (not q.is_empty()):
        cc = q.dequeue()
        if cc == goal:
            return get_path(pred, start, goal)
        else:
            for key, value in offsets.items():
                newpos = tuple(cc[i] + value[i] for i in range(len(cc)))
                if is_legal_pos(maze, newpos) and newpos not in pred:
                    q.enqueue(newpos)
                    pred[newpos] = cc
def bfs(maze, start, goal):
    queue = Queue()
    queue.enqueue(start)
    predecessors = {start: None}

    while not queue.is_empty():
        current_cell = queue.dequeue()
        if current_cell == goal:
            return get_path(predecessors, start, goal)
        for direction in ["up", "right", "down", "left"]:
            row_offset, col_offset = offsets[direction]
            neighbor = (current_cell[0] + row_offset, current_cell[1] + col_offset)
            if is_legal_pos(maze, neighbor) and neighbor not in predecessors:
                queue.enqueue(neighbor)
                predecessors[neighbor] = current_cell
    return None
Example #15
0
def dfs(maze, start, goal):
    stack = Stack()
    stack.push(start)
    predecessors = {start: None}

    while not stack.is_empty():
        current_cell = stack.pop()
        if current_cell == goal:
            return get_path(predecessors, start, goal)
        for direction in ["up", "right", "down", "left"]:
            row_offset, col_offset = offsets[direction]
            neighbour = (current_cell[0] + row_offset, current_cell[1] + col_offset)
            if is_legal_pos(maze, neighbour) and neighbour not in predecessors:
                stack.push(neighbour)
                predecessors[neighbour] = current_cell
    return None
Example #16
0
def a_star(maze, start, goal):
    def fval(cur):
        return fval1(cur, start, goal)

    prq = PriorityQueue()
    prq.put(start, fval(start))
    pred = {start: None}

    while not prq.is_empty():
        cc = prq.get()
        if cc == goal:
            return get_path(pred, start, goal)
        for key, value in offsets.items():
            newpos = tuple(cc[i] + value[i] for i in range(len(cc)))
            if is_legal_pos(maze, newpos) and newpos not in pred:
                prq.put(newpos, fval(newpos))
                pred[newpos] = cc
	def get_promoters(self):
		fh = open(get_path("promoters.sql.10000.txt"), "w")
		for dir in ["forward", "reverse"]:
			for chr in self.get_chrs():
				print(chr)
				line, seq = self.get_header_seq("reference_sequence." + chr + ".masked."+dir+".fasta")
				out = self.get_stend_pos_genes(chr)
				for row in out:
					if row['strand'] == '+' and dir == "forward":
						st, en, pro = self.toleft(seq, row['start'], 10000)
						fh.write(row['gene_id'] +"\t"+ chr +"\t"+ st +"\t"+ en +"\tupstream\t"+ pro +"\n")
						st, en, pro = self.toright(seq, row['end'], 10000)
						fh.write(row['gene_id'] +"\t"+ chr +"\t"+ st +"\t"+ en +"\tdownstream\t"+ pro +"\n")
					if row['strand'] == '-' and dir == "reverse":
						st, en, pro = self.toright(seq, row['end'], 10000)
						fh.write(row['gene_id'] +"\t"+ chr +"\t"+ st +"\t"+ en +"\tdownstream\t"+ pro +"\n")
						st, en, pro = self.toleft(seq, row['start'], 10000)
						fh.write(row['gene_id'] +"\t"+ chr +"\t"+ st +"\t"+ en +"\tupstream\t"+ pro +"\n")
		fh.close()
	def split_fasta_file(self):
		fh = open(get_path(self.filename), "r")
		pre = ''
		seq = ''
		for line in fh:
			line = line.rstrip("\r|\n")
			if ">" in line:
				chr = re.search('>chr([0-9A-Za-z]*) ', line).group(1)
				#print(pre, chr, line)
				if seq != '' and pre != chr:
					#print(">", pre, "\n", seq, "\n")
					self.save_chromosome(pre, seq)
					pre = chr
					seq = ''
				else:
					pre = chr
			else:
				seq += line
		#print(">", pre, "\n", seq, "\n")
		self.save_chromosome(pre, seq)
Example #19
0
def a_star(maze, start, goal):
    pq = PriorityQueue()
    # technically, the 0 should have the heuristic distance, but this is not necessary
    pq.put(start, 0)
    predecessors = {start: None}
    g_values = {start: 0}

    while not pq.is_empty():
        current_cell = pq.get()
        if current_cell = goal:
            return get_path(predecessors, start, goal)
        for direction in ["up","right","down","left"]:
            row_offset, col_offset = offsets[direction]
            neighbor = (current_cell[0] + row_offset, current_cell[1] + col_offset)
            if is_legal_pos(maze, neighbor) and neighbor not in g_values:
                new_cost = g_values[current_cell] + 1
                g_values[neighbor] = new_cost
                f_value = new_cost + heuristic(goal, neighbor)
                pq.put(neighbor, f_value)
                predecessors[neighbor] = current_cell
Example #20
0
def custom_generator(num_docs, batch_size, set='tr'):
    path = helpers.get_path(num_docs, set)
    counter = 0
    curr_pos = 0
    num_batches = num_docs // batch_size
    while True:
        x_batch, y_batch, curr_pos = data_operations.read_dumps_in_batches(path, batch_size, curr_pos)
        avg_doc_len = helpers.find_avg_doc_length_in_batch(x_batch)
        x_batch = pad_sequences(x_batch, avg_doc_len, padding='post', truncating='post', dtype=np.float32)    # (batch_size, doc_len, sen_len)
        y_batch = pad_sequences(y_batch, avg_doc_len, padding='post', truncating='post', dtype=np.float32)    # (batch_size, doc_len)
        print(f'AVG DOC LEN: {avg_doc_len}')
        counter += 1

        # converting from np.array to tensor because of https://github.com/tensorflow/tensorflow/issues/44705#issuecomment-725803328
        yield tf.convert_to_tensor(x_batch), tf.convert_to_tensor(np.reshape(y_batch, (y_batch.shape[0], y_batch.shape[1], 1)))

        # restart counter to yield data in the next epoch as well
        if counter >= num_batches:
            counter = 0
            curr_pos = 0
Example #21
0
def dfs(maze, start, goal):
    stack = Stack()
    stack.push(start)
    predecessors = {start: None}

    while not stack.is_empty():
        # getting the top item from the stack (far most right item)
        current_cell = stack.pop()
        if current_cell == goal:
            return get_path(predecessors, start, goal)
        for direction in ["up", "right", "down", "left"]:
            # unpacking the tuple
            row_offset, col_offset = offsets[direction]
            neighbor = (current_cell[0] + row_offset,
                        current_cell[1] + col_offset)
            if is_legal_pos(maze, neighbor) and neighbor not in predecessors:
                stack.push(neighbor)
                predecessors[neighbor] = current_cell
    return None

    # pass only prevents the code from returning an error if you run it
    pass
	def get_header_seq(self, filename):
		fh = open(get_path(filename), "r")
		line = fh.readline()
		seq = fh.readline()
		fh.close
		return line, seq
Example #23
0
from config import USE_NLP_LANGUAGE
from helpers import get_path
import configparser

config = configparser.ConfigParser()
config_path = get_path("NLP/nlp.config")
config.read(config_path)
_api_key_name = 'nlp_api_' + USE_NLP_LANGUAGE
api_key = config.get(_api_key_name, 'wit')
Example #24
0
import pyowm
from helpers import debug, get_path
import configparser
from config import USE_TTS_LANGUAGE

config = configparser.ConfigParser()
config_path = get_path("Weather/weather.config")
config.read(config_path)


class UsesApiKey:
    api_key = None


class BaseWeatherProvider:
    location = None

    def get_current_weather(self):
        raise NotImplementedError()

    def set_location(self, location):
        self.location = location


class OpenWeatherMap(UsesApiKey, BaseWeatherProvider):

    client = None

    weather = None

    def __init__(self):
Example #25
0
from App.App import App
import gettext
from config import USE_POPPY_LANGUAGE
from helpers import get_path
import locale

locale_path = get_path('/locale')
print("Locale path: " + locale_path)

lang = gettext.translation('poppy',
                           localedir=locale_path,
                           languages=[USE_POPPY_LANGUAGE])
lang.install()
locale.setlocale(locale.LC_ALL, USE_POPPY_LANGUAGE)

app = App()