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 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 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()