def comp(cs, argument): #print_colored("COMP", "yellow") print("COMP") sequence = Seq(argument) response = sequence.complement() cs.send(response.encode()) print(response)
def comp_send(cs, argument): termcolor.cprint('COMP', 'green') s = Seq(argument) complement = s.complement() response = complement + '\n' cs.send(response.encode()) print(response)
def complementary(client_socket, sequence): print(Fore.GREEN + "COMP") useful_seq = Seq(sequence) complementary_seq = useful_seq.complement() print(complementary_seq) client_socket.send(complementary_seq.encode())
def complement_seq(sequence): s = Seq(sequence) if s.complement() != Seq.ERROR_MSG: context = { 'sequence': sequence, 'result': s.complement(), 'operation': 'Complement' } contents = read_template_htm_file('./html/complement.html').render( context=context) else: context = {'sequence': sequence, 'message_error': Seq.ERROR_MSG} contents = read_template_htm_file('./html/invalid_seqs.html').render( context=context) return contents
def comp(sequence): s1 = Seq(sequence) response = s1.complement() context = {"gene_contents_comp": response, "gene_contents": s1.strbases} content = read_template_html_file("./html/comp.html").render( context=context) return content
def comp(argument): print_colored("COMP", "yellow") sequence = Seq(argument) response = sequence.complement() context = {"sequence": argument, "comp_sequence": response} contents = read_template_html_file("./html/comp.html").render(context=context) return contents
def comp(cs, seq): termcolor.cprint("COMP", "yellow") seq = Seq(seq) complement = Seq.complement(seq) termcolor.cprint(complement, "white") cs.send(complement.encode()) cs.close()
def comp(sequence): seq1 = Seq(sequence) context = { "sequence": sequence, "calculation": seq1.complement() } contents = read_template_html_file("./html/option.html").render(context=context) return contents
def comp(sequence): comp_seq = Seq(sequence) context = { "operation_contents": sequence, "operation_name": "Comp", "operation_result": comp_seq.complement() } contents = read_template_html_file("./html/operation.html").render(context=context) return contents
def comp(seq): seq = Seq(seq) c_seq = Seq.complement(seq) context = { 'operation': 'comp', 'sequence': seq, 'result': c_seq } contents = read_template_html_file('./html/operation.html').render(context=context) return contents
def comp(sequence): seq = Seq(sequence) context = { "sequence": seq, "operation": "comp", "result": seq.complement() } contents = read_template_html_file("./html/operation.html").render( context=context) return contents
def comp(sequence): seq = Seq(sequence) context = { 'gene_name': seq, 'gene_comp': seq.complement(), 'operation': "Comp" } contents = read_template_html_file('./html/comp.html').render( context=context) return contents
def complement(sequence): print_color("COMP", "yellow") seq = Seq(sequence) context = { "sequence": sequence, "operation": "Comp", "result": seq.complement() } contents = read_template_html_file("./html/operations.html").render( context=context) return contents
def complementary(sequence): useful_seq = Seq(sequence) complementary_seq = useful_seq.complement() context = { "operation": "COMP", "sequence": sequence, "sequence_modified": complementary_seq } contents = read_template_html_file("./HTML_FILES/operation.html").render( context=context) return contents
def comp(sequence): s = Seq(sequence) complement = s.complement() response = complement + '\n' context = { 'sequence': sequence, 'information': response, 'operation': 'Comp' } contents = read_template_html_file('operation.html').render( context=context) return contents
def comp(seq, opt): sequence = Seq(seq) new_sequence = Seq.complement(sequence) operation = opt context = { "sequence": sequence, "operation": operation, "result": new_sequence } contents = read_template_html_file("./html/operation.html").render( context=context) return contents
def comp(sequence): termcolor.cprint('COMP', 'green') s = Seq(sequence) complement = s.complement() response = complement + '\n' context = { 'sequence': sequence, 'information': response, 'operation':'comp' } contents = read_template_html_file('./html/form-4.html').render(context=context) return contents
from Seq1 import Seq print('-----Exercise 8------') s1 = Seq('ACTGA') s2 = Seq() s3 = Seq('Invalid Sequence') bases = ['A', 'C', 'T', 'G'] print(f'Sequence 1 : Length : {s1.len()} {s1}') print('\tBases ;', s1.count()) print('\tRev :', s1.reverse()) print('\tComp:', s1.complement()) print(f'\nSequence 2 : Length : {s2.len()} {s2}') print('\tBases ;', s2.count()) print('\tRev :', s2.reverse()) print('\tComp:', s2.complement()) print(f'\nSequence 3 : Length : {s3.len()} {s3}') print('\tBases ;', s3.count()) print('\tRev :', s3.reverse()) print('\tComp:', s3.complement())
def complement(cs, argument): print_color("COMP", "yellow") seq = Seq(argument) print(seq.complement()) response = seq.complement() cs.send(str(response).encode())
def do_GET(self): """This method is called whenever the client invokes the GET method in the HTTP protocol request""" termcolor.cprint(self.requestline, "green") req_line = self.requestline.split(' ') path = req_line[1] arguments = path.split('?') option = arguments[0] content = Path('error.html').read_text() cod = 404 if option == "/": content = Path('form-4.html').read_text() cod = 200 elif option == "/ping": content = """<!DOCTYPE html><html lang = "en"><head><meta charset = "utf-8" ><title> Ping </title ></head > <body><h2> PING OK!</h2><p> The SEQ2 server in running.... </p><a href="/">Main page</a></body></html>""" cod = 200 elif option == "/get": get_seq = arguments[1] seq = get_seq.split('?') name, seq_index = seq[0].split("=") seq_index = int(seq_index) seq = LIST_SEQ[seq_index] content = f"""<!DOCTYPE html><html lang = "en"><head><meta charset = "utf-8" ><title> Get </title ></head > <body><h2> Sequence number {seq_index}</h2><p> {seq} </p><a href="/">Main page</a></body></html>""" cod = 200 elif option == "/gene": get_gene = arguments[1] couple = get_gene.split('?') name, gene = couple[0].split("=") seq = Seq() filename = FOLDER + gene + TXT seq = Seq(seq.read_fasta(filename)) gene = str(seq) content = f"""<!DOCTYPE html><html lang = "en"><head><meta charset = "utf-8" ><title> Gene </title ></head> <body><h2> Gene: {gene}</h2><textarea readonly rows="20" cols="80"> {gene_seq} </textarea><br><br> <a href="/">Main page</a></body></html>""" cod = 200 elif option == "/operation": operation = arguments[1] couple = operation.split('&') name_s, seq = couple[0].split("=") name_o, op = couple[1].split("=") seq = Seq(seq) if op == "comp": result = seq.complement() elif op == "rev": result = seq.reverse() else: l = seq.len() A_COUNTER = seq.count_base('A') C_COUNTER = seq.count_base('C') G_COUNTER = seq.count_base('G') T_COUNTER = seq.count_base('T') A_PER = 100 * A_COUNTER / l C_PER = 100 * C_COUNTER / l G_PER = 100 * G_COUNTER / l T_PER = 100 * T_COUNTER / l result = f"""<p>Total length: {l}</p><p>A: {A_COUNTER} ({A_PER}%)</p><p>G: {C_COUNTER} ({C_PER}%) </p><p>C: {G_COUNTER} ({G_PER}%)</p><p>T: {T_COUNTER} ({T_PER}%)</p>""" content = f"""<!DOCTYPE html><html lang = "en"><head><meta charset = "utf-8" ><title> Operation </title > </head ><body><h2> Sequence </h2><p>{seq}</p><h2> Operation: </h2><p>{op}</p><h2> Result: </h2><p>{result} </p><br><br><a href="/">Main page</a></body></html>""" cod = 200 # Generating the response message self.send_response(cod) # -- Status line: OK! # Define the content-type header: self.send_header('Content-Type', 'text/html') self.send_header('Content-Length', len(str.encode(content))) # The header is finished self.end_headers() # Send the response message self.wfile.write(str.encode(content)) return
from Seq1 import Seq # Import our Seq class print("-----| Practice 1, Exercise 9 |------") folder = "../Session-04/" filename = folder + 'U5.txt' s = Seq() # Create a Seq object s.read_fasta(filename) print(f"Sequence : (Length: {s.len()}) {s}") print("\tBases: ", s.count()) print("\tRev: ", s.reverse()) print("\tComp:", s.complement())
elif msg.startswith("INFO"): termcolor.cprint("INFO", "green") sequence = Seq(msg[5:]) print(f"sequence: {sequence}") cs.send(str(sequence).encode()) print(f"total length: {sequence.len()}") for base in list_bases: print( f"{base}: {sequence.count_base(base)} ({round(sequence.count_base(base) / sequence.len() * 100, 2)} %)" ) # respond = ("Sequence: " + str(sequence) + "\n" + "Total length: " + str(sequence.len()) + "\n" + sequence.count_base(base)) # cs.send(respond.encode()) elif msg.startswith("COMP"): sequence = Seq(msg[5:]) print(sequence.complement() + "\n") cs.send(str(sequence.complement()).encode()) elif msg.startswith("REV"): sequence = Seq(msg[4:]) print(sequence.reverse() + "\n") cs.send(str(sequence.reverse()).encode()) elif msg.startswith("GENE"): termcolor.cprint("GENE", "green") sequence = msg[5:] gene = s1.read_fasta(folder + sequence + ".txt") print(gene) cs.send(str(gene).encode()) cs.close()
def do_GET(self): termcolor.cprint(self.requestline, 'green') request = self.requestline.split(' ') raw_arg = request[1] clean_arg = raw_arg.split('?') argument = clean_arg[0] if argument == '/': contents = Path('form-4.html').read_text() elif argument == '/ping': contents = f""" <!DOCTYPE html> <html lang = "en"> <head> <meta charset = "utf-8" > <title> PING </title > </head > <body> <h2> PING OK!</h2> <p> The SEQ2 server is running </p> <a href="/">Main page</a> </body> </html> """ elif argument == '/get': argument1 = clean_arg[1].split('&') name, value = argument1[0].split('=') value = int(value) sequence = Sequences[value] contents = f""" <!DOCTYPE html> <html lang = "en"> <head> <meta charset = "utf-8" > <title> GET </title > </head > <body> <h2> Sequence number {value}</h2> <p> {sequence} </p> <a href="/">Main page</a> </body> </html> """ elif argument == '/gene': argument1 = clean_arg[1].split('&') name, gene = argument1[0].split('=') sequence = Seq() sequence.read_fasta(FOLDER + gene + EXT) gene_str = str(sequence) contents = f""" <!DOCTYPE html> <html lang = "en"> <head> <meta charset = "utf-8" > <title> GENE </title > </head > <body> <h2> Gene: {gene}</h2> <textarea readonly rows="20" cols="80"> {gene_str} </textarea> <br> <br> <a href="/">Main page</a> </body> </html>""" elif argument == '/operation': argument1 = clean_arg[1].split('&') name, sequence = argument1[0].split("=") name, operation = argument1[1].split("=") seq = Seq(sequence) if operation == 'comp': result = seq.complement() elif operation == 'rev': result = seq.reverse() else: length = seq.len() num_bases = [] perc_bases = [] for element in bases: counter_bases = seq.count_base(element) percentage = round((seq.count_base(element) * 100 / seq.len()), 2) num_bases.append(counter_bases) perc_bases.append(percentage) result = f""" <p>Total length: {length}</p> <p>A: {num_bases[0]} ({perc_bases[0]}%)</p> <p>C: {num_bases[1]} ({perc_bases[1]}%)</p> <p>G: {num_bases[2]} ({perc_bases[2]}%)</p> <p>T: {num_bases[3]} ({perc_bases[3]}%)</p>""" contents = f""" <!DOCTYPE html> <html lang = "en"> <head> <meta charset = "utf-8" > <title> OPERATION </title > </head > <body> <h2>Sequence</h2> <p>{seq}</p> <h2>Operation</h2> <p>{operation}</p> <h2>Result</h2> <p>{result}</p> <br> <br> <a href="/">Main page</a> </body> </html>""" else: contents = Path('Error.html').read_text() self.send_response(200) self.send_header('Content-Type', 'text/html') self.send_header('Content-Length', len(str.encode(contents))) self.end_headers() self.wfile.write(str.encode(contents)) return
def comp(seq): s = Seq(seq) return Seq.complement(s)
from Seq1 import Seq print('-----Exercise 9------') folder = "../Session-04 folder/" filename = folder + "U5" s = Seq() s.read_fasta(filename) print(f'Sequence 1 : Length : {s.len()} {s}') print('\tBases ;', s.count()) print('\tRev :', s.reverse()) print('\tComp:', s.complement())
def do_GET(self): """This method is called whenever the client invokes the GET method in the HTTP protocol request""" # Print the request line termcolor.cprint(self.requestline, 'green') # Analize the request line req_line = self.requestline.split(' ') # Take the path info path = req_line[1] # Separate the path from the rest of the request line arguments = path.split('?') # we take the service names from the path action = arguments[0] # -- Content type header # -- Both, the error and the main page are in HTML contents = Path('Error.html').read_text() error_code = 404 if action == "/": # Open the form1.html file # Read the index from the file contents = Path('form-4.html').read_text() error_code = 200 elif action == "/ping": contents = """ <!DOCTYPE html> <html lang = "en"> <head> <meta charset = "utf-8" > <title> PING </title > </head > <body> <h2> PING OK!</h2> <p> The SEQ2 server in running... </p> <a href="/">Main page</a> </body> </html> """ error_code = 200 elif action == "/get": # -- Get the argument to the right of the ? symbol pair = arguments[1] # -- Get all the pairs name = value pairs = pair.split('&') # -- Get the two elements: name and value name, value = pairs[0].split("=") n = int(value) # -- Get the sequence seq = SEQ_GET[n] # -- Generate the html code contents = f""" <!DOCTYPE html> <html lang = "en"> <head> <meta charset = "utf-8" > <title> GET </title > </head > <body> <h2> Sequence number {n}</h2> <p> {seq} </p> <a href="/">Main page</a> </body> </html> """ error_code = 200 elif action == "/gene": # -- Get the argument to the right of the ? symbol pair = arguments[1] # -- Get all the pairs name = value pairs = pair.split('&') # -- Get the two elements: name and value name, gene = pairs[0].split("=") s = Seq() s.read_fasta(FOLDER + gene + EXT) gene_str = str(s) # -- Generate the html code contents = f""" <!DOCTYPE html> <html lang = "en"> <head> <meta charset = "utf-8" > <title> GENE </title > </head > <body> <h2> Gene: {gene}</h2> <textarea readonly rows="20" cols="80"> {gene_str} </textarea> <br> <br> <a href="/">Main page</a> </body> </html> """ error_code = 200 elif action == "/operation": # -- Get the argument to the right of the ? symbol pair = arguments[1] # -- Get all the pairs name = value pairs = pair.split('&') # -- Get the two elements: name and value name, seq = pairs[0].split("=") # -- Get the two elements of the operation name, op = pairs[1].split("=") # -- Create the sequence s = Seq(seq) if op == "comp": result = s.complement() elif op == "rev": result = s.reverse() else: sl = s.len() ca = s.count_base('A') pa = "{:.1f}".format(100 * ca / sl) cc = s.count_base('C') pc = "{:.1f}".format(100 * cc / sl) cg = s.count_base('G') pg = "{:.1f}".format(100 * cg / sl) ct = s.count_base('T') pt = "{:.1f}".format(100 * ct / sl) result = f""" <p>Total length: {sl}</p> <p>A: {ca} ({pa}%)</p> <p>C: {cc} ({pc}%)</p> <p>G: {cg} ({pg}%)</p> <p>T: {ct} ({pt}%)</p>""" contents = f""" <!DOCTYPE html> <html lang = "en"> <head> <meta charset = "utf-8" > <title> OPERATION </title > </head > <body> <h2> Sequence </h2> <p>{seq}</p> <h2> Operation: </h2> <p>{op}</p> <h2> Result: </h2> <p>{result}</p> <br> <br> <a href="/">Main page</a> </body> </html> """ error_code = 200 # Generating the response message self.send_response(error_code) # -- Status line: OK! # Define the content-type header: self.send_header('Content-Type', 'text/html') self.send_header('Content-Length', len(str.encode(contents))) # The header is finished self.end_headers() # Send the response message self.wfile.write(str.encode(contents)) return
def comp(cs, seq): print_colored("COMP", "green") s1 = Seq(seq) response = "Complement: " + s1.complement() + "\n" print(response.replace("\n", "")) cs.send(response.encode())
elif "INFO" == service: seq_info = Seq(seq1) # seq1 is the sequence count_bases_string = "" for base, count in seq_info.count().items(): s_base = str(base) + ": " + str(count) + " (" + str( round(count / seq_info.len() * 100, 2)) + "%)" + "\n" count_bases_string += s_base response = ("Sequence: " + str(seq_info) + "\n" + "Total length: " + str(seq_info.len()) + "\n" + count_bases_string) elif "COMP" == service: complementary = Seq(seq1) response = complementary.complement() + "\n" elif "REV" == service: reverse = Seq(seq1) response = reverse.reverse() + "\n" elif "GENE" == service: gene = seq1 s = Seq() s.read_fasta("../Session-04/" + gene + ".txt") response = str(s) + "\n" # Server Console termcolor.cprint(f'{service}', "green") print(response)
def do_GET(self): """This method is called whenever the client invokes the GET method in the HTTP protocol request""" # Print the request line termcolor.cprint(self.requestline, 'green') if self.path == "/": file = "form-4.html" contents = Path(file).read_text() error = 200 elif "/ping" in self.path: html = "<h1>PING OK!</h1><p>The SEQ2 server is running...</p>" contents = html_response( "PING", html, 'orange') # En title va PING y en body el resto error = 200 elif "/get" in self.path: seq_list = [ "TGTGAACATTCTGCACAGGTCTCTGGCTGCGCCTGGGCGGGTTTCTT", "CAGGAGGGGACTGTCTGTGTTCTCCCTCCCTCCGAGCTCCAGCCTTC", "CTCCCAGCTCCCTGGAGTCTCTCACGTAGAATGTCCTCTCCACCCC", "GAACTCCTGCAGGTTCTGCAGGCCACGGCTGGCCCCCCTCGAAAGT", "CTGCAGGGGGACGCTTGAAAGTTGCTGGAGGAGCCGGGGGGAA" ] sequence_number = int(argument_command(self.path)) sequence = seq_list[sequence_number] html = "<h1>Sequence number " + str( sequence_number) + "</h1> <p>" + sequence + "</p>" contents = html_response("GET", html, 'pink') error = 200 # -- Status line: OK! elif "/gene" in self.path: gene = argument_command(self.path) s = Seq() s.read_fasta("../Session-04/" + gene + ".txt") html = "<h1>Gene Sequence: " + gene + '</h1> <textarea readonly rows = "20" cols = "80">' + str( s) + '</textarea>' contents = html_response("GENE", html, 'yellow') error = 200 elif "/operation" in self.path: requests = self.path.split("&") sequence = argument_command(requests[0]) op = argument_command(requests[1]) seq = Seq(sequence) bases = ['A', 'C', 'T', 'G'] for b in sequence: if b in bases: if "info" == op: count_bases_string = "" for base, count in seq.count().items(): s_base = str(base) + ": " + str( count) + " (" + str( round(count / seq.len() * 100, 2)) + "%)" + "<br>" count_bases_string += s_base response_info = ("Sequence: " + str(seq) + " <br>" + "Total length: " + str(seq.len()) + "<br>" + count_bases_string) html_operation = "<h1>Operation:</h1><p>Information</p>" html_result = "<h1>Result:</h1>" + "<p>" + response_info + "</p>" color = 'lightblue' elif "comp" == op: response_comp = seq.complement() + "\n" html_operation = "<h1>Operation:</h1><p>Complementary sequence</p>" html_result = "<h1>Result:</h1>" + "<p>" + response_comp + "</p>" color = 'lightgrey' elif "rev" == op: response_rev = seq.reverse() + "\n" html_operation = "<h1>Operation:</h1><p>Reverse sequence</p>" html_result = "<h1>Result:</h1>" + "<p>" + response_rev + "</p>" color = 'lightgreen' html_sequence = "<h1>Sequence:</h1>" + "<p>" + sequence + "</p>" html = html_sequence + html_operation + html_result contents = html_response("OPERATION", html, color) error = 200 else: file = "Error-1.html" contents = Path(file).read_text() error = 404 else: file = "Error-1.html" contents = Path(file).read_text() error = 404 # -- Status line: ERROR NOT FOUND self.send_response(error) # Generating the response message # Define the content-type header: self.send_header('Content-Type', 'text/html') self.send_header('Content-Length', len(str.encode(contents))) # The header is finished self.end_headers() # Send the response message self.wfile.write(str.encode(contents)) return
from Seq1 import Seq # Null sequence s1 = Seq() # valid sequence s2 = Seq("ACTGA") # invalid sequence s3 = Seq("Invalid sequence") print("Sequence 1: (Length: " + str(Seq.len(s1)) + ") ", s1) print("\tBases:", Seq.count(s1)) print("\tRev: ", Seq.reverse(s1)) print("\tComp: ", Seq.complement(s1)) print("Sequence 2: (Length: " + str(Seq.len(s2)) + ") ", s2) print("\tBases:", Seq.count(s2)) print("\tRev: ", Seq.reverse(s2)) print("\tComp: ", Seq.complement(s2)) print("Sequence 3: (Length: " + str(Seq.len(s3)) + ") ", s3) print("\tBases:", Seq.count(s3)) print("\tRev: ", Seq.reverse(s3)) print("\tComp: ", Seq.complement(s3))