コード例 #1
0
def info_func(s):
    s = Seq(s)
    l = s.length()
    ac = s.count_base("A")
    tc = s.count_base("T")
    cc = s.count_base("C")
    gc = s.count_base("G")
    resp = f"""Sequence: {s}
    Total length: {l}
    A: {ac} ({round((ac/l)*100)})%  
    C: {cc} ({round((cc/l)*100)})%     
    T: {tc} ({round((tc/l)*100)})%     
    G: {gc} ({round((gc/l)*100)})%"""
    return resp
コード例 #2
0
    r1 = conn.getresponse()
    print(f"Response received!: {r1.status} {r1.reason}\n")
    data1 = r1.read().decode()

    gene = json.loads(data1)

    termcolor.cprint(f"Gene: ", "yellow", end="")
    print(f"{namegene}")
    termcolor.cprint("Description: ", "yellow", end="")
    print(f"{gene['desc']}"
          )  #see esembl page for desc and seq (especial functions)

    sequence = gene['seq']
    s = Seq(sequence)
    l = s.length()
    ac = s.count_base("A")
    tc = s.count_base("T")
    cc = s.count_base("C")
    gc = s.count_base("G")
    termcolor.cprint("Total length: ", "yellow", end="")
    print(l)
    resp = f"""
    A: {ac} ({round((ac / l) * 100)})%
    C: {cc} ({round((cc / l) * 100)})%
    T: {tc} ({round((tc / l) * 100)})% 
    G: {gc} ({round((gc / l) * 100)})%"""
    print(resp)

    dictionary = s.count()
    listvalues = list(dictionary.values())
コード例 #3
0
    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(' ')

        # Get the path. It always start with the / symbol
        path = req_line[1]

        # Read the arguments
        arguments = path.split('?')

        # Get the verb. It is the first argument
        verb = 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 verb == "/":
            # Open the form1.html file
            # Read the index from the file
            contents = Path('form-4.html').read_text()
            error_code = 200
        elif verb == "/ping":
            contents ="""
            <!DOCTYPE html>
            <html lang="en">
            <head>
            <meta charset="utf-8">
                <title>PING</title>
            </head>
            <body style="background-color: lightblue;">
            <h1> PING OK! </h1>
            <p> The SEQ 2 server is running </p>
            <hr>
            <a href="/">MAIN PAGE</a>
            </body>
            </html>
            """
            error_code = 200
        elif verb == "/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_v = int(value)
            seq = sequences[n_v]
            # -- Generate the html code
            contents = f"""
            <!DOCTYPE html>
            <html lang="en">
            <head>
                <meta charset="utf-8">
                <title>GET</title>
            </head>
            <body style="background-color: lightyellow;">
            <h2>Sequence number {n_v}</h2>
            <p> {seq} </p>
            <a href="/">Main page</a>
            </body>
            </html>
            """
            error_code = 200
        elif verb == "/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()
            s1 = Seq(s.read_fasta(folder + gene + txt))
            gene_info = str(s1)
            # -- Generate the html code
            contents = f"""
            <!DOCTYPE html>
            <html lang="en">
            <head>
                <meta charset="utf-8">
                <title>GENE</title>
            </head>
            <body style="background-color: magenta;">
            <h2>Gene: {gene}</h2>
            <textarea readdonly rows = "20" cols = "60"> {gene_info}</textarea>
            <br>
            <a href="/">Main page</a>
            </body>
            </html>
            """
            error_code = 200
        elif verb == "/operate":
            # -- 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, sequence = pairs[0].split("=")
            name, operation = pairs[1].split("=")
            s = Seq(sequence)
            if operation == "info":
                l = s.length()
                ac = s.count_base("A")
                tc = s.count_base("T")
                cc = s.count_base("C")
                gc = s.count_base("G")
                resp = f"""
                    <p>Total length: {l}</p>
                    <p>A: {ac} ({round((ac / l) * 100)})%</p>  
                    <p>C: {cc} ({round((cc / l) * 100)})%</p>    
                    <p>T: {tc} ({round((tc / l) * 100)})%</p>     
                    <p>G: {gc} ({round((gc / l) * 100)})%</p>"""
            elif operation == "rev":
                resp = s.seq_reverse()
            else:
                resp = s.seq_complement()
            contents = f"""
            <!DOCTYPE html>
            <html lang="en">
            <head>
                <meta charset="utf-8">
                <title>OPERATION</title>
            </head>
            <body style="background-color: lightgreen;">
            <h2>Sequence:</h2>
            <p> {sequence} </p>
            <h2> Operation: </h2>
            <p> {operation}</p>
            <h2> Result: </h2>
            <p> {resp} </p>
            <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