コード例 #1
0
def geneCalc(dict_information, gene):

    #Lo primero de todo_ es sacar la secuencia
    sequence = dict_information['seq']

    #Una vez tenemos la secuencia...

    correct_dna = Seq.is_valid_sequence_2(sequence)

    if correct_dna:  # Same as :  if correct_dna == True:
        argument_object = Seq(sequence)
        a, g, c, t = argument_object.count_bases(
        )  # De esta manera solo se ejecuta el bucle una vez cuando hacemos luego el print
        percent = f"""
        A: {a} ({calculate_percentaje(a, sequence)} %) 
        C: {c} ({calculate_percentaje(c, sequence)} %) 
        G: {g} ({calculate_percentaje(g, sequence)} %) 
        T: {t} ({calculate_percentaje(t, sequence)} %)"""  #MANDAMOS EL CÓDIGO SÓLO UNA VEZ, PORQUE SI NO, ConnectionResetError: [WinError 10054]

        length = len(sequence)
        context = {'percent': percent, 'length': length}
        return context

    else:
        percent = 'The percentages can not be calculated. Introduce a correct sequence. '
        length = len(sequence)
        context = {'percent': percent, 'length': length}
        return context
コード例 #2
0
def info(cs, argument):
    print_colored("INFO", "yellow")
    sequence = Seq(argument)
    response = "Total length:" + str(sequence.len()) + "\n" + str(
        sequence.count_bases()) + "\n"
    print(response)
    cs.send(response.encode())
コード例 #3
0
def info(arg, cs): # total length, number of bases and their percentages
    termcolor.cprint('INFO', 'green')
    seq = Seq(arg.replace('"',''))
    sl = Seq.len(seq)
    a, c, g, t = Seq.count_bases(seq)
    p_a = round((100 * a / sl),1)   # p = percentage
    p_c = round((100 * c / sl),1)
    p_g = round((100 * g / sl),1)
    p_t = round((100 * t / sl),1)
    response = 'Sequence: ' + str(seq) + '\nTotal length: ' + str(sl) + '\nA: ' + str(a) + ' (' + str(p_a) + '%)\nC: ' + str(c) + ' (' + str(p_c) + '%)\nG: ' + str(g) + ' (' + str(p_g) + '%)\nT: ' + str(t) + ' (' + str(p_t) + '%)'
    termcolor.cprint(response, 'blue')
    cs.send(response.encode())
コード例 #4
0
def info(sequence):
    s = Seq(sequence)
    response = "Total length:" + str(Seq.len(s)) + "\r" + str(
        Seq.count_bases(s)) + "\r"
    context = {
        'sequence': sequence,
        'information': response,
        'operation': 'info'
    }
    contents = read_template_html_file('./html/operations.html').render(
        context=context)
    return contents
コード例 #5
0
def info(seq):
    s1 = Seq(seq)
    count_bases = s1.count_bases()
    nucleotides = ("A", "C", "G", "T")
    percentage = s1.percentage_base(count_bases, s1.len())
    i = 0
    percentage_bases = ""
    for i in range(0, len(count_bases)):
        percentage_bases += nucleotides[i] + ": " + str(
            count_bases[i]) + " (" + percentage[i] + ")\n"
        i += 1
    context = {"result": [str(s1.len()), percentage_bases]}
    print(context)
    return context
コード例 #6
0
def info(sequence):
    s = Seq(sequence)
    total_len = s.len()
    a, c, g, t = s.count_bases()
    p_a, p_c, p_g, p_t = 0, 0, 0, 0
    if total_len != 0:
        p_a = round(a * 100/ total_len, 1)
        p_c = round(c * 100/ total_len, 1)
        p_g = round(g * 100/ total_len, 1)
        p_t = round(t * 100/ total_len, 1)
    "Total length: " + str(total_len) + "\nA: " + str(a) + " (" + str(p_a) + "%" + ")" + "\nC: " + str(c) + " (" + str(p_c) + "%" + ")" + "\nG: " + str(g) + " (" + str(p_g) + "%" + ")" + "\nT: " + str(t) + " (" + str(p_t) + "%" + ")"
    context = {"gene_contents_len": total_len, "gene_contents": s.strbases, "bases": [a, c, g, t], "percentage_bases": [p_a, p_c, p_g, p_t]}
    content = read_template_html_file("./html/info.html").render(context=context)
    return content
コード例 #7
0
def info(cs, argument):
    #print_colored("INFO", "yellow)
    print("INFO")
    sequence = Seq(argument)
    total_length = str(sequence.len())
    response_2 = total_length
    count_diff_bases = sequence.count_bases()
    sum = count_diff_bases[0] + count_diff_bases[1] + count_diff_bases[2] + count_diff_bases[3]
    percen_a = "(" + str(round((count_diff_bases[0] / sum) * 100,2)) + "%" + ")"
    percen_c = "(" + str(round((count_diff_bases[1] / sum) * 100,2)) + "%" + ")"
    percen_g = "(" + str(round((count_diff_bases[3] / sum) * 100,2)) + "%" + ")"
    percen_t = "(" + str(round((count_diff_bases[2] / sum) * 100,2)) + "%" + ")"
    response_3 = "A: " + str(count_diff_bases[0]) + percen_a + "\n" + "C: " + str(count_diff_bases[1]) + percen_c + "\n" + "G: " + str(count_diff_bases[3]) + percen_g + "\n" + "T: " + str(count_diff_bases[2]) + percen_t + "\n"
    cs.send(("Sequence: " + argument + "\n" + "Total length: " + response_2 + "\n" + response_3).encode())
    print("Sequence: " + argument + "\n" + "Total length: " + response_2 + "\n" + response_3)
コード例 #8
0
def info(argument):
    print_colored("INFO", "yellow")
    sequence = Seq(argument)
    total_length = str(sequence.len())
    response_2 = total_length
    count_diff_bases = sequence.count_bases()
    sum = count_diff_bases[0] + count_diff_bases[1] + count_diff_bases[2] + count_diff_bases[3]
    percen_a = "(" + str(round((count_diff_bases[0] / sum) * 100,2)) + "%" + ")"
    percen_c = "(" + str(round((count_diff_bases[1] / sum) * 100,2)) + "%" + ")"
    percen_g = "(" + str(round((count_diff_bases[3] / sum) * 100,2)) + "%" + ")"
    percen_t = "(" + str(round((count_diff_bases[2] / sum) * 100,2)) + "%" + ")"
    response_3 = "A: " + str(count_diff_bases[0]) + percen_a + "\n" + "C: " + str(count_diff_bases[1]) + percen_c + "\n" + "G: " + str(count_diff_bases[3]) + percen_g + "\n" + "T: " + str(count_diff_bases[2]) + percen_t + "\n"
    context = {"Sequence: " + argument + "\n" + "Total length: " + response_2 + "\n" + response_3}
    contents = read_template_html_file("./html/info.html").render(context=context)
    return contents
コード例 #9
0
def info(seq): # total length, number of bases and their percentages
    seq = Seq(seq)
    a, c, g, t = seq.count_bases()
    sl = seq.len()
    pa = round((100 * a / sl),1)   # p = percentage
    pc = round((100 * c / sl),1)
    pg = round((100 * g / sl),1)
    pt = round((100 * t / sl),1)
    result = ['Total length: ' + str(sl), 'A: ' + str(a) + ' (' + str(pa) + '%)', 'C: ' + str(c) + ' (' + str(pc) + '%)', 'T: ' + str(t) + ' (' + str(pt) + '%)', 'G: ' + str(g) + ' (' + str(pg) + '%)']
    context = {
        'operation': 'info',
        'sequence': seq,
        'result': result,
        'len_r': len(result)
    }
    contents = read_template_html_file('./html/operation.html').render(context=context)
    return contents
コード例 #10
0
def info(cs, seq):
    print_colored("INFO", "yellow")
    s1 = Seq(seq)
    count_bases = s1.count_bases()
    nucleotides = ("A", "C", "G", "T")
    percentage = s1.percentage_base(count_bases, s1.len())
    response1 = "Sequence: " + str(s1) + "\nTotal length: " + str(
        s1.len()) + "\n"
    print(response1)
    i = 0
    response2 = ""
    for i in range(0, len(count_bases)):
        response2 += nucleotides[i] + ": " + str(
            count_bases[i]) + " (" + percentage[i] + ")\n"
        i += 1
    print(response2)
    cs.send((response1 + response2).encode())
コード例 #11
0
def info(cs, sequence):
    print_colored("INFO", "yellow")
    s = Seq(sequence)
    total_len = s.len()
    a, c, g, t = s.count_bases()
    p_a, p_c, p_g, p_t = 0, 0, 0, 0
    if total_len != 0:
        p_a = round(a * 100 / total_len, 1)
        p_c = round(c * 100 / total_len, 1)
        p_g = round(g * 100 / total_len, 1)
        p_t = round(t * 100 / total_len, 1)
    response = "Sequence: " + sequence + "\nTotal length: " + str(
        total_len
    ) + "\nA: " + str(a) + " (" + str(p_a) + "%" + ")" + "\nC: " + str(
        c) + " (" + str(p_c) + "%" + ")" + "\nG: " + str(g) + " (" + str(
            p_g) + "%" + ")" + "\nT: " + str(t) + " (" + str(p_t) + "%" + ")"
    print(response)
    cs.send(response.encode())
コード例 #12
0
def seq_info(sequence):
    object = Seq(sequence)
    variable = object.count_bases()
    lenght = object.len()
    p_one = (variable[0] * 100) / lenght
    p_two = (variable[1] * 100) / lenght
    p_three = (variable[2] * 100) / lenght
    p_four = (variable[3] * 100) / lenght
    response = "Sequences: " + sequence + "\n" + "Total length: " + str(
        lenght) + "\n" + "A: " + str(
            variable[0]) + " (" + str(p_one) + "%)" + "\n" + "C: " + str(
                variable[1]) + " (" + str(p_two) + "%)" + "\n" + "G: " + str(
                    variable[2]) + " (" + str(
                        p_three) + "%)" + "\n" + "T: " + str(
                            variable[3]) + " (" + str(p_four) + "%)" + "\n"
    context = {"sequence": sequence, "info": response}
    contents = read_template_html_file("./html/info.html").render(
        context=context)
    return contents
コード例 #13
0
def info(cs, argument):
    print_colored('INFO', 'yellow')
    print('Sequence:', argument)
    correct_dna = Seq.is_valid_sequence_2(argument)
    if correct_dna:  # Same as :  if correct_dna == True:
        argument_object = Seq(argument)
        a, g, c, t = argument_object.count_bases(
        )  # De esta manera solo se ejecuta el bucle una vez cuando hacemos luego el print
        response = f""" Sequence: {argument}
        Total length: {len(argument)} 
        A: {a} {calculate_percentaje(a, argument)} %
        C: {c} {calculate_percentaje(c, argument)} %
        G: {g} {calculate_percentaje(g, argument)} %
        T: {t} {calculate_percentaje(t, argument)} %"""  #MANDAMOS EL CÓDIGO SÓLO UNA VEZ, PORQUE SI NO, ConnectionResetError: [WinError 10054]
        print(response)
        cs.send(response.encode())

    else:
        print('The seq_dna is not correct. Please introduce another one.')
コード例 #14
0
def info(cs, argument):
    termcolor.cprint("INFO", "yellow")
    s = Seq(argument)
    length = Seq.len(s)
    a, c, g, t = s.count_bases()
    # a = dict_count['A'][0]
    pa = (a * 100) / length
    # c = dict_count['C'][0]
    pc = (c * 100) / length
    # g = dict_count['G'][0]
    pg = (g * 100) / length
    # t = dict_count['T'][0]
    pt = (t * 100) / length
    first = 'Total length: ' + str(len(argument)) + '\n'
    second = 'A: ' + str(a) + ' ' + str(pa) + '%' + '\n'
    third = 'C: ' + str(c) + ' ' + str(pc) + '%' + '\n'
    fourth = 'G: ' + str(g) + ' ' + str(pg) + '%' + '\n'
    fifth = 'T: ' + str(t) + ' ' + str(pt) + '%' + '\n'
    print(first, second, third, fourth, fifth)
コード例 #15
0
def info(
    sequence, operation
):  #Esto es lo que se envía desde el server: contents = su.info(sequence, operation)

    correct_dna = Seq.is_valid_sequence_2(sequence)

    if correct_dna:  # Same as :  if correct_dna == True:
        argument_object = Seq(sequence)
        a, g, c, t = argument_object.count_bases(
        )  # De esta manera solo se ejecuta el bucle una vez cuando hacemos luego el print
        result = f""" Sequence: {sequence}
        Total length: {len(sequence)} 
        A: {a} ({calculate_percentaje(a, sequence)} %) 
        C: {c} ({calculate_percentaje(c, sequence)} %) 
        G: {g} ({calculate_percentaje(g, sequence)} %) 
        T: {t} ({calculate_percentaje(t, sequence)} %)"""  #MANDAMOS EL CÓDIGO SÓLO UNA VEZ, PORQUE SI NO, ConnectionResetError: [WinError 10054]

        context = {
            'sequence': sequence,
            'operation': operation,
            'result': result
        }
        contents = read_template_html_file('./html/operation.html').render(
            context=context)
        return contents

    else:
        result = 'The result can not be calculated. Introduce a correct sequence. '
        context = {
            'sequence': sequence,
            'operation': operation,
            'result': result
        }
        contents = read_template_html_file('./html/operation.html').render(
            context=context)
        return contents
コード例 #16
0
connection = http.client.HTTPConnection(SERVER)
for g in GENES_LIST:
    try:
        ID = DICT_GENES[g]
        connection.request("GET", ENDPOINT + ID + PARAMETERS)
        response = connection.getresponse()
        print("\nSERVER: ", SERVER)
        print("URL: ", SERVER + ENDPOINT + ID + PARAMETERS)
        print("Response received:", response.status, response.reason, "\n")
        if response.status == 200:
            response_dict = json.loads(response.read().decode())
            # print(json.dumps(response_dict, indent=4, sort_keys=True))
            print_colored("GENE: ", g, "yellow")
            print_colored("Description: ", response_dict["desc"], "yellow")
            sequence = Seq(response_dict["seq"])
            seq_length = sequence.len()
            count_dict = sequence.count_bases()
            # most_frequent_base = sequence.most_frequent_base(count_dict)
            info_dict = sequence.info_seq()
            A = info_dict['A']
            G = info_dict['G']
            C = info_dict['C']
            T = info_dict['T']
            bases_dict = {'G': G[0], 'A': A[0], 'C': C[0], 'T': T[0]}
            max_value = max(bases_dict, key=bases_dict.get)
            print(colored("Total length:", "yellow"), seq_length, "\n", colored(f"""A: {A[0]} ({round(A[1], 1)}%)
     C: {C[0]} ({round(C[1], 1)}%)
     G: {G[0]} ({round(G[1], 1)}%)
     T: {T[0]} ({round(T[1], 1)}%)""", "blue"), "\n", colored("Most frequent base:", "yellow"), max_value)
    except KeyError:
        print("The gene is not inside our database. Choose one of the following", list(DICT_GENES.keys()))
コード例 #17
0
        if len(formatted_message) == 1:
            command = formatted_message[0]
        else:
            command = formatted_message[0]
            argument = formatted_message[1]
        if command == "PING":
            server_utiles.ping(cs)

        elif command == "GET":
            response = list_sequences[int(argument)] + "\n"
            cs.send(response.encode())

        elif command == "INFO":
            s = Seq(argument)
            response = str(s.len()) + "\n" + str(s.count_bases()) + "\n"
            cs.send(response.encode())

        elif command == "COMP":
            s = Seq(argument)
            response = str(s.seq_complement()) + "\n"
            cs.send(response.encode())

        elif command == "REV":
            s = Seq(argument)
            response = str(s.seq_reverse()) + "\n"
            cs.send(response.encode())

        elif command == "GENE":
            s = Seq(argument)
            response = str(s.read_fasta("P3/" + argument + ".txt"))
コード例 #18
0
from Seq1 import Seq, generate_series
print("-----| Practice 1, Exercise 5 |------")

s1 = Seq()
s2 = Seq("ACTGA")
s3 = Seq("Invalid sequence")

print(f"Sequence 1 (Length:{Seq.len(s1)}): {s1} ")
Seq.count_bases(s1)
print(f"Sequence 1 (Length:{Seq.len(s2)}): {s2} ")
s2.count_bases()
print(f"Sequence 1 (Length:{Seq.len(s3)}): {s3} ")
Seq.count_bases(s3)
コード例 #19
0
from Seq1 import Seq

GENE_FOLDER = "../P0/Sequences/"
gene_list = ["U5", "ADA", "FRAT1", "FXN", "RNU6_269P"]
base_list = ["A", "C", "T", "G" ]

print("-----| Practice 1, Exercise 10 |-----")

for gene in gene_list:
    sequence = Seq()
    sequence.read_fasta(GENE_FOLDER + gene + ".txt")
    appearance = Seq.count_bases(sequence)
    count = 0
    for e in range(0, len(appearance)):
         if appearance[e] > count:
            count = appearance[e]
            higher_base = base_list[e]
    print("Gene", gene, ": Most Frequent Base:", higher_base)



コード例 #20
0
ファイル: Ex10.py プロジェクト: Nataliap24/PINE-Practices
from Seq1 import Seq

GENE_FOLDER = "../P0/Sequences/"
gene_list = ["U5", "ADA", "FRAT1", "FXN"]
base_list = ["A", "C", "G", "T"]

for gene in gene_list:
    sequence = Seq()
    sequence.read_fasta(GENE_FOLDER + gene + ".txt")
    count_tuple = Seq.count_bases(sequence)
    c = 0
    for i in range(0, len(count_tuple)):
        if count_tuple[i] > c:
            c = count_tuple[i]
            base = base_list[i]
    print("Gene", gene, ": Most frequent base:", base)