Exemple #1
0
def gene(cs, argument):
    GENE_FOLDER = "./SEQUENCES/"
    print_colored("GENE", "green")
    seq = Seq()
    response = seq.read_fasta(GENE_FOLDER + argument + ".txt")
    print(response)
    cs.send(str(response).encode())
Exemple #2
0
def comp(cs, list_sequences, argument):
    print_colored("COMP", "green")
    seq = Seq(list_sequences[int(argument)])
    response = seq.complement()
    response = "COMP " + str(seq) + "\n" + response
    print(response)
    cs.send(response.encode())
Exemple #3
0
def rev(cs, list_sequences, argument):
    print_colored("REV", "green")
    seq = Seq(list_sequences[int(argument)])
    response = seq.reverse()
    response = "REV " + str(seq) + "\n" + response
    print(response)
    cs.send(response.encode())
Exemple #4
0
def info(cs, list_sequences, argument):
    print_colored("INFO", "green")
    seq = Seq(list_sequences[int(argument)])
    print(seq)
    number_dict = seq.count()
    len1 = len(str(seq))
    percentage_dict = seq.percentage(seq.count_bases(), len1)
    response = "Sequence: " + list_sequences[int(
        argument)] + "\nTotal length: " + str(len1) + "\n"
    for key in number_dict:
        response += (str(key) + ": " + str(number_dict[key]) + " (" +
                     str(percentage_dict[key], ) + "%)\n")
    print(response)
    cs.send(response.encode())
Exemple #5
0
def lengthSeq(gene, genes_dict):
    SERVER = "rest.ensembl.org"
    ENDPOINT = "/sequence/id/"
    PARAMS = "?content-type=application/json"

    ID = genes_dict[gene]
    connection = http.client.HTTPConnection(SERVER)
    connection.request("GET", ENDPOINT + ID + PARAMS)

    response = connection.getresponse()
    print(response.status, response.reason)

    answer_decoded = response.read().decode()
    dict_response = json.loads(answer_decoded)
    sequence = Seq(dict_response["seq"])
    length = sequence.len()

    context = {"length": length, "gene": gene}
    content = su.read_template_html_file("HTML/lengthCalc.html").render(
        context=context)
    return content
Exemple #6
0
def percentageSeq(gene, genes_dict):
    SERVER = "rest.ensembl.org"
    ENDPOINT = "/sequence/id/"
    PARAMS = "?content-type=application/json"

    ID = genes_dict[gene]
    connection = http.client.HTTPConnection(SERVER)
    connection.request("GET", ENDPOINT + ID + PARAMS)

    response = connection.getresponse()
    print(response.status, response.reason)

    answer_decoded = response.read().decode()
    dict_response = json.loads(answer_decoded)
    sequence = Seq(dict_response["seq"])
    lenght = sequence.len()
    a, c, g, t = sequence.percentage(sequence.count_bases(), lenght)

    context = {"A": a, "C": c, "G": g, "T": t, "gene": gene}
    content = su.read_template_html_file("HTML/percentageCalc.html").render(
        context=context)
    return content
Exemple #7
0
from client0 import Client
from pathlib import Path
from Seq02 import Seq

PRACTICE = 2
EXERCISE = 6

print(f"-----| Practice {PRACTICE}, Exercise {EXERCISE} |------")

# -- Parameters of the server to talk to
IP = "192.168.1.12"
PORT = 12000

# -- Create a client object
c = Client(IP, PORT)
s = Seq()
s.read_fasta("FRAT1.txt")
count = 0
for i in range(0, len(s.strbases), 10):
    fragment = s.strbases[i:i + 10]
    print(fragment)
    count = count + 1
    if count == 5:
        break
    print("Fragment", count, ":", fragment)
    print(c.talk(fragment))
Exemple #8
0
    "FGFR3": "ENSG00000068078",
    "KDR": "ENSG00000128052",
    "ANK2": "ENSG00000145362"
}

SERVER = "rest.ensembl.org"
ENDPOINT = "/sequence/id/"
PARAMETERS = "?content-type=application/json"

connection = http.client.HTTPConnection(SERVER)
try:
    for key, ID in genes_dict.items():
        connection.request("GET", ENDPOINT + ID + PARAMETERS)
        response = connection.getresponse()
        if response.status == 200:
            response_dict = json.loads(response.read().decode())
            #response = json.dumps(response_dict, indent=4, sort_keys=True
            sequence = Seq(response_dict["seq"])
            s_length = sequence.len()
            percentages = sequence.percentage()
            most_frequent_base = sequence.frequent_base(sequence.count())
            print_colored("Gene: ", key, "yellow")
            print_colored("Description: ", response_dict['desc'], "yellow")
            print_colored("Total length: ", s_length, "yellow")
            for key, value in percentages.items():
                print_colored(key, value, "blue")
            print_colored("Most frequent base: ", most_frequent_base, "yellow")
except KeyError:
    print(
        "The gene is not inside our dictionary. Choose one of the following: ",
        list(genes_dict.keys()))
Exemple #9
0
from Seq02 import Seq
print('-----| Exercise 1 |------')
seq_list = Seq('ACTGA')
print('Sequence: 1 , (Lenght : ' + str(seq_list.len()) + " ) " + str(seq_list))
Exemple #10
0
from Seq02 import Seq

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


s1 = Seq('NULL')


s2 = Seq("ACTGA")


s3 = Seq("ERROR")

print("Sequence 1: (Length : ", s1.len(), ")", s1)
print("Sequence 1: (Length : ", s2.len(), ")", s2)
print("Sequence 1: (Length : ", s3.len(), ")", s3)
Exemple #11
0
from client0 import Client
from pathlib import Path
from Seq02 import Seq

PRACTICE = 2
EXERCISE = 1

print(f"-----| Practice {2}, Exercise {7} |------")

IP = "192.168.1.12"
PORT = 12000
PORT_2 = 12002
c = Client(IP, PORT)
c_2 = Client(IP, PORT_2)

s = Seq()
s.read_fasta('../P0/FRAT1.txt')
i = 0
count = 0
while i < len(s.strbases) and count < 10:
    fragment = s.strbases[i:i + 10]
    count += 1
    i += 10
    fragment_text = "Fragment " + str(count) + ": " + fragment
    print(fragment_text)
    if count % 2 == 0:
        print(c_2.debug_talk(fragment_text))
    else:
        print(c.debug_talk(fragment_text))
Exemple #12
0
from Seq02 import Seq
print('-----| Practice 1, Exercise 10 |------')
bases = ["A", "C", "T", "G"]
list_of_genes = ["U5", "ADA", "FRAT1", "FXN", "RNU6_269P" ]
txt = ".txt"
FOLDER = "../SEQUENCES/"


for e in list_of_genes:
    s0 = Seq('')
    val = 0
    base = ''
    s0 = s0.read_fasta(FOLDER+e+txt)
    dict1 = s0.count()
    for i, t in dict1.items():
        while t > val:
            val = t
            base = i
    print("Gene ", e, " : Most frequent base: ", base)
Exemple #13
0
from Seq02 import Seq

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

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

print("Sequence 1: (Length : ", s1.len(), ")", s1)
print("Bases:", s1.count())

print("Sequence 2: (Length : ", s2.len(), ")", s2)
print("Bases:", s2.count())

print("Sequence 3: (Length : ", s3.len(), ")", s3)
print("Bases:", s3.count())
Exemple #14
0
}

SERVER = "rest.ensembl.org"
ENDPOINT = "/sequence/id/"
PARAMETERS = "?content-type=application/json"

connection = http.client.HTTPConnection(SERVER)
try:
    user_gene = input("Enter the gene you want to analise: ")
    ID = genes_dict[user_gene]
    connection.request("GET", ENDPOINT + ID + PARAMETERS)
    response = connection.getresponse()
    if response.status == 200:
        response_dict = json.loads(response.read().decode())
        #print(json.dumps(response_dict, indent=4, sort_keys=True))
        sequence = Seq(response_dict["seq"])
        s_length = sequence.len()
        a, c, g, t = sequence.percentage(sequence.count_bases(), s_length)
        most_frequent_base = sequence.frequent_base(sequence.count())
        print_colored("Gene: ", user_gene, "yellow")
        print_colored("Total length: ", s_length, "yellow")
        print(a)
        print(c)
        print(t)
        print(g)
        print(most_frequent_base)
except KeyError:
    print("The gene is not inside our dictionary. Choose one of the following: ", list(genes_dict.keys()))


Exemple #15
0
from Seq02 import Seq

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

s1 = Seq('NULL')

s2 = Seq("ACTGA")

s3 = Seq("ERROR")

print("Sequence 1: ", s1)
print("Sequence 2: ", s2)
print("Sequence 3: ", s3)
Exemple #16
0
from Seq02 import Seq
print('-----| Practice 1, Exercise 9 |------')
FOLDER = "../SEQUENCES/"
file_name = FOLDER + "U5.txt"
s0 = Seq('')
s0 = s0.read_fasta(file_name)

print(f"Sequence : (Length: {s0.len()}) {s0}")
print(f"Bases: {s0.count()}")
print(f"Rev: {s0.reverse(s0)}")
print(f"Comp: {s0.complement(s0)}")
Exemple #17
0
from Seq02 import Seq

print("-----| Practice 1, Exercise 8 |------")
s1 = Seq('NULL')

s2 = Seq("ACTGA")

s3 = Seq("Invalid sequence")

print("Sequence", 1, ": (Length:", s1.len(), ")", s1)
print(f"Bases: {s1.count()}")
print(f"Rev: {s1.reverse(s1)}")
print(f"Comp: {s1.complement(s1)}")
print("Sequence", 2, ": (Length:", s2.len(), ")", s2)
print(f"Bases: {s2.count()}")
print(f"Rev: {s2.reverse(s2)}")
print(f"Comp: {s2.complement(s2)}")
print("Sequence", 3, ": (Length:", s3.len(), ")", s3)
print(f"Bases: {s3.count()}")
print(f"Rev: {s3.reverse(s3)}")
print(f"Comp: {s3.complement(s3)}")
Exemple #18
0
from Seq02 import Seq
print('-----| Practice 1, Exercise 2 |------')

s1 =Seq('NULL')
s2 =Seq("ACTGA")
print('Sequence 1', s1)
print('Sequence 2', s2)