def gene(cs, argument): print_colored("GENE", "yellow") gene = Seq() folder = "../P0/Sequences/" gene.read_fasta(folder + argument + ".txt") cs.send(str(gene).encode()) return gene
def rev(argument, cs): print_colored("REV", "yellow") argument = Seq(argument.replace('"', "")) rev_seq = str(Seq.seq_reverse(argument)) response = f"""Initial sequence: {argument} Reverse sequence: {rev_seq}""" cs.send(response.encode()) print(response)
def comp(argument, cs): print_colored("COMP", "yellow") argument = Seq(argument.replace('"', "")) comp_seq = str(Seq.seq_complement(argument)) response = f"""Initial sequence: {argument} Complement sequence: {comp_seq}""" cs.send(response.encode()) print(response)
def gene(seq_name): PATH = "./Sequences/" + seq_name + ".txt" s1 = Seq() # s1.read_fasta(PATH) context = {"gene_name": seq_name, "gene_contents": s1.read_fasta(PATH)} contents = read_template_html_file("./html/gene.html").render( context=context) return contents
def gene(argument, cs): print_colored("GENE", "yellow") sequence = Seq(Seq.seq_read_fasta_2("./Sequences/" + argument.replace('"', "") + ".txt")) comp_seq = str(Seq.seq_complement(sequence)) rev_seq = str(Seq.seq_reverse(sequence)) colored_response = f"""Initial sequence: {termcolor.colored(sequence, "red")} Complement sequence: {termcolor.colored(comp_seq, "green")} Reverse sequence: {termcolor.colored(rev_seq, "blue")}""" response = f"""Initial sequence: {sequence} Complement sequence: {comp_seq} Reverse sequence: {rev_seq}""" cs.send(response.encode()) print(response)
def info(argument, cs): print_colored("INFO", "yellow") list_bases = ["A", "C", "T", "G"] argument = Seq(argument.replace('"', "")) t_l = Seq.len(argument) count_list = [] percentage_list = [] for base in list_bases: count_list.append(argument.count_base_1(base)) for i in range(0, len(count_list)): percentage_list.append(count_list[i] * 100 / t_l) response = f"""Sequence: {argument} Total length: {t_l} A: {count_list[0]} ({percentage_list[0]}%) C: {count_list[1]} ({percentage_list[0]}%) G: {count_list[2]} ({percentage_list[0]}%) T: {count_list[3]} ({percentage_list[0]}%)""" cs.send(response.encode()) print(response)
def info(argument): sequence = Seq(argument) seq_len = sequence.len() bases_count = list(sequence.count().values()) bases_percent = list(sequence.base_percentage().values()) bases = list(sequence.count().keys()) msg = f"Sequence: {sequence}\n" \ f"Total length: {seq_len}\n" for i in range(len(bases)): msg += f"{bases[i]}: {bases_count[i]} ({bases_percent[i]}%)\n" return msg
def info(cs, argument): print_colored("INFO", "yellow") sequence = Seq(argument) seq_len = sequence.len() bases_count = list(sequence.count().values()) bases_percent = list(sequence.base_percentage().values()) bases = list(sequence.count().keys()) msg = f"Sequence: {sequence}\n" \ f"Total length: {seq_len}\n" for i in range(len(bases)): msg += f"{bases[i]}: {bases_count[i]} ({bases_percent[i]}%)\n" cs.send(str(msg).encode()) return msg
def rev(cs, argument): print_colored("REV", "yellow") sequence = Seq(argument) rev = sequence.reverse() cs.send(str(rev).encode()) return rev
def comp(cs, argument): print_colored("COMP", "yellow") sequence = Seq(argument) comp = sequence.complement() cs.send(str(comp).encode()) return comp
def process_client(cs): # reading the message from the client msg = cs.recv(2048).decode("utf-8") msg = msg.split('\n') se = Seq(msg[0]) response = "" ac = "ACTG" if msg[0] == "asdf": response += "EMPTY" cs.send(str.encode(response)) nmbr = 0 for n in msg[0].upper(): if n in ac: nmbr += 1 if nmbr == len(msg[0]): response += "OK!" response += "\n" elif nmbr != len(msg[0]): response += "ERROR" cs.send(str.encode(response)) for i in msg[1:]: if i == 'len': response += se.len() elif i == 'complement': response += se.complement().strbases elif i == 'reverse': response += se.reversed().strbases elif i == 'countA': response += se.counting('A') elif i == 'countC': response += se.counting('C') elif i == 'countT': response += se.counting('T') elif i == 'countG': response += se.counting('G') elif i == 'percA': response += se.percentage('A') elif i == 'percC': response += se.percentage('C') elif i == 'percT': response += se.percentage('T') elif i == 'percG': response += se.percentage('G') # Sending the message back to the client # because we are an eco server cs.send(str.encode(response)) cs.close()
def rev(argument): sequence = Seq(argument) rev = sequence.reverse() return rev
def comp(argument): sequence = Seq(argument) comp = sequence.complement() return comp