コード例 #1
0
def info(cs, sequence):
    print_colored('INFO', 'green')
    s = Seq(sequence)
    response = 'Total length: ' + str(Seq.len(s)) + '\n' + str(
        Seq.percentage(s)) + '\n'
    print(response)
    cs.send(response.encode())
コード例 #2
0
def info(cs, argument):
    print_colored("INFO", "yellow")
    seq = Seq(argument)
    list_info = Seq.percentage(seq)
    response = ""
    for e in list_info:
        response += e + "\n"
    cs.send(response.encode())
コード例 #3
0
def info(cs, argument):
    print_coloured("INFO", "green")
    sequence = Seq(argument)
    response = "Sequence: " + str(sequence) + \
               "\nTotal length: " + str(len(str(sequence))) + \
               "\n" + Seq.percentage(sequence)
    print(response)
    cs.send(str(response).encode())
コード例 #4
0
def info(sequence):
    seq = Seq(sequence)
    result = "\nTotal length: " + str(seq.len()) + seq.percentage()
    context = {
        "sequence": seq,
        "operation": info,
        "result": result
    }
    contents = read_template_html_file("./html/operate.html").render(context=context)
    return contents
コード例 #5
0
def info(cs, seq):
    termcolor.cprint("INFO", "yellow")
    seq = Seq(seq)
    len_seq = Seq.len(seq)
    count_seq = Seq.count(seq)

    response = "Sequence: " + str(seq) + "\nTotal length: " + str(len_seq) + seq.percentage()
    print(response)
    cs.send(response.encode())
    cs.close()
コード例 #6
0
def info(argument):
    print_colored("INFO", "yellow")
    seq = Seq(argument)
    length = "Total length: " + str(seq.len())
    percentages = seq.percentage()
    response = [length]
    for e in percentages:
        response.append(e)
    context = {'sequence': argument, 'info_sequence': response}
    contents = read_template_html_file("./html/info.html").render(
        context=context)
    return contents
コード例 #7
0
def info(seq, opt):
    sequence = Seq(seq)
    percentage = Seq.percentage(sequence)
    operation = opt
    context = {
        "sequence": sequence,
        "operation": operation,
        "result": percentage
    }
    contents = read_template_html_file("./html/operation.html").render(
        context=context)
    return contents
コード例 #8
0
def gene_calc(gene):
    ext = "/sequence/id/"
    if gene in DICT_GENES.keys():
        id = DICT_GENES[gene]
        decoded = read_request(ext, id)
        s = decoded["seq"]
        sequence = Seq(s)
        calc_seq = Seq.percentage(sequence)
        context = {"gene_name": gene, "information": calc_seq}
        contents = read_template_html_file("html/geneCalc.html").render(
            context=context)
    else:
        contents = read_template_html_file("./html/Error.html").render()
    return contents
コード例 #9
0
def gene_calc_json(gene_name, id):
    SERVER = "rest.ensembl.org"
    ENDPOINT = "/sequence/id/"
    PARAMETERS = "?content-type=text/plain;species=human"
    connection = http.client.HTTPConnection(SERVER)
    connection.request("GET", ENDPOINT + id + PARAMETERS)
    response = connection.getresponse().read().decode()
    seq = Seq(response)
    contents = {
        "gene_name": gene_name,
        "length": str(seq.len()),
        "percentages": seq.percentage()
    }
    contents_json = json.dumps(contents)
    return contents_json
コード例 #10
0
termcolor.cprint("Length: ", "blue", end=""), print(t_len)
termcolor.cprint("id: ", "blue", end=""), print(id)
termcolor.cprint("Chromosome: ", "blue", end=""), print(description[2])

print()
termcolor.cprint(
    "------------------------------------------------------------------------------------------",
    "yellow")

try:
    conn.request("GET", "/geneCalc?gene=FRAT1" + JSON_PARAM)
except ConnectionRefusedError:
    print("ERROR! Cannot connect to the Server")
    exit()

r6 = conn.getresponse()
print(f"Response received!: {r6.status} {r6.reason}\n")

data6 = r6.read().decode("utf-8")
information = json.loads(data6)
s = information["seq"]
s = Seq(s)
calculations = Seq.percentage(s)

termcolor.cprint("CALCULATIONS:", "yellow")

for l in calculations:
    m = l.split(":")
    termcolor.cprint(m[0] + ":", "blue", end="")
    print(m[1])
コード例 #11
0
    def do_GET(self):
        """This method is called whenever the client invokes the GET method
        in the HTTP protocol request"""
        connection = http.client.HTTPConnection(SERVER)
        # We just print a message
        print("GET received! Request line:")

        # Print the request line
        termcolor.cprint("  " + self.requestline, 'green')

        # Print the command received (should be GET)
        print("  Command: " + self.command)

        # Print the resource requested (the path)
        termcolor.cprint("  Path: " + self.path, "blue")

        # we are creating a parse object (easier way to work with the elements of the path
        o = urlparse(self.path)
        path_name = o.path
        arguments = parse_qs(o.query)
        print("Resource requested: ", path_name)
        print("Parameters: ", arguments)
        context = {}
        try:
            if path_name == "/":
                contents = su.read_template_html_file(
                    "./html/INDEX.html").render(context=context)
            elif path_name == "/listSpecies":
                ENDPOINT = "/info/species"
                connection.request("GET", ENDPOINT + Parameters)
                response = connection.getresponse()
                response_dict = json.loads(response.read().decode())
                species_list = []
                amount_species = len(response_dict["species"])
                context["amount_species"] = amount_species
                limit = int(arguments["limit"][0])
                context["limit"] = limit
                for n in range(0, limit):
                    species_list.append(
                        response_dict["species"][n]["common_name"])
                context["names"] = species_list
                contents = su.read_template_html_file(
                    "html/LISTSPECIES.html").render(context=context)
            elif path_name == "/karyotype":
                ENDPOINT = "info/assembly/"
                specie = arguments["species"][0]
                connection.request("GET", ENDPOINT + specie + Parameters)
                response = connection.getresponse()
                response_dict = json.loads(response.read().decode())
                karyotype = response_dict["karyotype"]
                context["species"] = arguments["species"][0]
                context["karyotype"] = karyotype
                contents = su.read_template_html_file(
                    "./html/KARYOTYPE.html").render(context=context)
            elif path_name == "/chromosomeLength":
                ENDPOINT = "info/assembly/"
                specie = arguments["species"][0]
                connection.request("GET", ENDPOINT + specie + Parameters)
                response = connection.getresponse()
                response_dict = json.loads(response.read().decode())
                chromosome = arguments["chromosome"][0]
                for n in range(0, len(response_dict["top_level_region"])):
                    if chromosome == response_dict["top_level_region"][n][
                            "name"]:
                        length = response_dict["top_level_region"][n]["length"]
                context["length"] = length
                contents = su.read_template_html_file(
                    "./html/CHROMOSOMELENGTH.html").render(context=context)
            elif path_name == "/geneSeq":
                ENDPOINT = "/sequence/id/"
                gene = arguments["gene"][0]
                id = DICT_GENES[gene]
                connection.request("GET", ENDPOINT + id + Parameters)
                response = connection.getresponse()
                response_dict = json.loads(response.read().decode())
                context["seq"] = response_dict["seq"]
                contents = su.read_template_html_file(
                    "./html/SEQGENE.html").render(context=context)
            elif path_name == "/geneInfo":
                ENDPOINT = "/sequence/id/"
                gene = arguments["gene"][0]
                id = DICT_GENES[gene]
                connection.request("GET", ENDPOINT + id + Parameters)
                response = connection.getresponse()
                response_dict = json.loads(response.read().decode())
                info = response_dict["desc"].split(":")
                context["dict_info"] = {
                    "Name": info[1],
                    "ID": id,
                    "Start": info[3],
                    "End": info[4],
                    "Length": (int(info[4]) - int(info[3]) + 1)
                }
                contents = su.read_template_html_file(
                    "./html/INFOGENE.html").render(context=context)
            elif path_name == "/geneCalc":
                ENDPOINT = "/sequence/id/"
                gene = arguments["gene"][0]
                id = DICT_GENES[gene]
                connection.request("GET", ENDPOINT + id + Parameters)
                response = connection.getresponse()
                response_dict = json.loads(response.read().decode())
                sequence = Seq(response_dict["seq"])
                dict_bases = Seq.count(sequence)
                percentage = Seq.percentage(sequence)
                context["length"] = Seq.len(sequence)
                context["bases"] = {
                    "A":
                    str(dict_bases["A"]) + " (" + str(percentage[0]) + "%)",
                    "C":
                    str(dict_bases["C"]) + " (" + str(percentage[1]) + "%)",
                    "T":
                    str(dict_bases["T"]) + " (" + str(percentage[2]) + "%)",
                    "G":
                    str(dict_bases["G"]) + " (" + str(percentage[3]) + "%)"
                }
                contents = su.read_template_html_file(
                    "./html/CALCGENE.html").render(context=context)
            else:
                contents = su.read_template_html_file(
                    "./html/ERROR.html").render()
        except KeyError:
            contents = su.read_template_html_file("./html/ERROR.html").render()
        except IndexError:
            contents = su.read_template_html_file("./html/ERROR.html").render()
        # Generating the response message
        self.send_response(200)  # -- Status line: OK!

        # Define the content-type header:
        self.send_header('Content-Type', 'text/html')
        self.send_header('Content-Length', len(contents.encode()))

        # The header is finished
        self.end_headers(
        )  # we always need to call the end headers method which forces to create an empty line of the HTTP message

        # Send the response message
        self.wfile.write(contents.encode(
        ))  # wfile acts like a socket, its just something that we can write on

        # IN this simple server version:
        # We are NOT processing the client's request
        return