Beispiel #1
0
def rev(seq):
    s = Seq(seq)
    return s.reverse()
Beispiel #2
0
from P1.Seq1 import Seq

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

s0 = Seq()
s1 = Seq("AGTGCA")
s2 = Seq("AGSHDT")

print(f"Sequence 0: (Length ,{s0.len()}{s0}")
print(f" Bases: {s0.count()}")
print("Rev :", s0.reverse())

print(f"Sequence 0: (Length ,{s1.len()}{s1}")
print(f" Bases: {s1.count()}")
print("Rev :", s1.reverse())

print(f"Sequence 0: (Length ,{s2.len()}{s0}")
print(f" Bases: {s2.count()}")
print("Rev :", s2.reverse())
    def do_GET(self):
        """This method is called whenever the client invokes the GET method
        in the HTTP protocol request"""

        # Define the type of content returned by the server
        content_type = "text/html"

        # Define the sequences that we are going to use in "get" and the bases for exercise 4
        sequence = ["GTAGCA", "ACGTTA", "CGTAGG", "ATTGTC"]
        all_bases = ["A", "C", "G", "T"]

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

        # Processing the request line
        req = self.requestline.split(" ")

        # Path will be: "/"
        path = req[1]

        # We will need to split the "?" in order to leave the msg alone
        argument = path.split("?")

        # We define our first argument to determine if we could continue or an error in thrown
        arg0 = argument[0]

        # All the information appears in "form-4.html"
        if arg0 == "/":
            contents = Path("form-4.html").read_text()
            status = 200
        elif arg0 == "/ping":
            contents = """
            <!DOCTYPE html>
            <html lang = "en">
            <head>
            <meta charset = "utf-8" >
              <title> ping </title >
            </head >
            <body>
            <h2> PING ok!</h2>
            <p> The SEQ2 Server in running... </p>
            <a href="/">Main page</a>
            </body>
            </html>
            """
            status = 200
        elif arg0 == "/get":

            # We define our second argument, the one after the "?" that we have split.
            arg1 = argument[1]

            # To split the "&" that is after the value
            args = arg1.split("&")

            # Is necessary to split the "=" after our name ("msg")
            name, value = args[0].split("=")

            # We define the argument n
            n = int(value)
            seq = sequence[n - 1]
            contents = f"""
            <!DOCTYPE html>
            <html lang = "en">
            <head>
            <meta charset = "utf-8" >
              <title> get </title >
            </head >
            <body>
            <h2>Sequence number {n}</h2>
            <p> {seq}</p>
            <a href="/">Main page</a>
            </body>
            </html>
            """
            status = 200
        elif arg0 == "/gene":
            # We define our second argument, the one after the "?" that we have split.
            arg1 = argument[1]

            # To split the "&" that is after the value
            args = arg1.split("&")

            # Is necessary to split the "=" after our name ("msg")
            name, gene_name = args[0].split("=")

            # Sequence of the gene
            s = Seq()
            s_string = str(s.read_fasta(FOLDER + gene_name))
            contents = f"""
            <!DOCTYPE html>
            <html lang = "en">
            <head>
            <meta charset = "utf-8" >
              <title> gene </title >
            </head >
            <body>
            <h2>Gene {gene_name}</h2>
            <textarea readonly rows="20" cols="80"> {s_string} </textarea>
            <a href="/">Main page</a>
            </body>
            </html>
            """
            status = 200

        elif arg0 == "/operation":
            # We define our second argument, the one after the "?" that we have split.
            arg1 = argument[1]

            # To split the "&" that is after the value
            args = arg1.split("&")

            # Name and values (=arguments)
            #seq in order to create the sequence
            name, seq = args[0].split("=")
            #op are the different options that can be chosen after the sequence is written
            name, op = args[1].split("=")

            #Introduce the sequence
            s = Seq(seq)

            if "info" in op:
                s = Seq(seq)
                s_length = s.len()
                list1 = []
                list2 = []

                for b in all_bases:

                    count_b = s.count_base(b)
                    p = round(count_b * (100 / s_length),
                              1)  # percentage calculation with just 1 decimal
                    list1.append(
                        count_b)  # list 1: where we put the total bases
                    list2.append(
                        p
                    )  # list2 : where we put the percentage of all the bases

                response = f"""
                Total length: {s_length}
                <p>A: {list1[0]} ({list2[0]}%)</p>
                <p>C: {list1[1]} ({list2[1]}%)</p>
                <p>G: {list1[2]} ({list2[2]}%)</p>
                <p>G: {list1[3]} ({list2[3]}%)</p>
                
                """

            elif "comp" in op:
                response = s.complement()

            elif "rev" in op:
                response = s.reverse()

            contents = f"""
            <!DOCTYPE html>
            <html lang = "en">
            <head>
            <meta charset = "utf-8" >
              <title> operation </title >
            </head >
            <body>
            <h2>Sequence :</h2>
            <p>{seq}</p>
            <h2>Operation :</h2>
            <p>{op}</p>
            <h2>Result :</h2>
            <p>{response}</p>
            <a href="/">Main page</a>
            </body>
            </html>
            """
            status = 200

        else:
            # Error.html file
            contents = Path("Error.html").read_text()
            status = 404

        # Generating the response message
        self.send_response(status)

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

        # The header is finished
        self.end_headers()

        # Send the response message
        self.wfile.write(contents.encode())

        return
Beispiel #4
0
from P1.Seq1 import Seq

print("-----| Practice 1, Exercise 9 |------")
FOLDER = "../Session-04/"
TypeDoc = '.txt'

seq = Seq(FOLDER + 'U5' + TypeDoc)
seq.read_fasta(FOLDER + 'U5' + TypeDoc)

print("Sequence ", seq, ':', "(Length: ", seq.len(), ')', seq)
print("  Bases:", seq.seq_count())
print('  Rev:  ', seq.reverse(), '\n  Comp: ', seq.complement())
Beispiel #5
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')
        request = self.requestline.split(' ')
        raw_arg = request[1]
        clean_arg = raw_arg.split('?')
        argument = clean_arg[0]

        if argument == '/':
            contents = Path('form-4.html').read_text()

        elif argument == '/ping':
            contents = f"""
                        <!DOCTYPE html>
                        <html lang = "en">
                        <head>
                        <meta charset = "utf-8" >
                          <title> PING </title >
                        </head >
                        <body>
                        <h2> PING OK!</h2>
                        <p> The SEQ2 server is running </p>
                        <a href="/">Main page</a>
                        </body>
                        </html> """

        elif argument == '/get':
            argument1 = clean_arg[1].split('&')
            name, value = argument1[0].split('=')
            value = int(value)
            sequence = Sequences[value]
            contents = f"""
                        <!DOCTYPE html>
                        <html lang = "en">
                        <head>
                        <meta charset = "utf-8" >
                          <title> GET </title >
                        </head >
                        <body>
                        <h2> Sequence number {value}</h2>
                        <p> {sequence} </p>
                        <a href="/">Main page</a>
                        </body>
                        </html> """

        elif argument == '/gene':
            argument1 = clean_arg[1].split('&')
            name, gene = argument1[0].split('=')
            sequence = Seq()
            sequence.read_fasta(FOLDER + gene + TypeDoc)
            gene_str = str(sequence)
            contents = f"""
                       <!DOCTYPE html>
                       <html lang = "en">
                       <head>
                       <meta charset = "utf-8" >
                         <title> GENE </title >
                       </head >
                       <body>
                       <h2> Gene: {gene}</h2>
                       <textarea readonly rows="20" cols="80"> {gene_str} </textarea>
                       <br>
                       <br>
                       <a href="/">Main page</a>
                       </body>
                       </html>"""

        elif argument == '/operation':
            argument1 = clean_arg[1].split('&')
            name, sequence = argument1[0].split("=")
            name, operation = argument1[1].split("=")
            seq = Seq(sequence)
            if operation == 'comp':
                result = seq.complement()
            elif operation == 'rev':
                result = seq.reverse()
            else:
                length = seq.len()
                num_bases = []
                perc_bases = []
                for element in bases:
                    counter_bases = seq.count_base(element)
                    percentage = round(
                        (seq.count_base(element) * 100 / seq.len()), 2)
                    num_bases.append(counter_bases)
                    perc_bases.append(percentage)

                result = f"""
                        <p>Total length: {length}</p>
                        <p>A: {num_bases[0]} ({perc_bases[0]}%)</p>
                        <p>C: {num_bases[1]} ({perc_bases[1]}%)</p>
                        <p>G: {num_bases[2]} ({perc_bases[2]}%)</p>
                        <p>T: {num_bases[3]} ({perc_bases[3]}%)</p>"""

            contents = f"""
                    <!DOCTYPE html>
                    <html lang = "en">
                    <head>
                    <meta charset = "utf-8" >
                      <title> OPERATION </title >
                    </head >
                    <body>
                    <h2>Sequence</h2>
                    <p>{seq}</p>
                     <h2>Operation</h2>
                    <p>{operation}</p>
                     <h2>Result</h2>
                    <p>{result}</p>
                    <br>
                    <br>
                    <a href="/">Main page</a>
                    </body>
                    </html>"""

        else:
            contents = Path('error.html').read_text()

        # 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(str.encode(contents)))

        # The header is finished
        self.end_headers()

        # Send the response message
        self.wfile.write(str.encode(contents))

        return
Beispiel #6
0
        elif cmd1 == "INFO":
            seq0 = Seq(cmd2)
            response = ""
            termcolor.cprint("INFO", 'green')
            response += f'Sequence: {cmd2}'
            response += f"Total length: {seq0.len()}"
            for element in bases:
                resp = round(seq0.count_base(element) * (100 / seq0.len()), 2)
                response += f'{element}: {seq0.count_base(element)} ( {resp}% ) \n'

        elif cmd1 == "COMP":
            seq0 = Seq(cmd2)
            termcolor.cprint("COMP", 'green')
            response = seq0.complement()

        elif cmd1 == "REV":
            seq0 = Seq(cmd2)
            termcolor.cprint("REV", 'green')
            response = seq0.reverse()

        elif cmd1 == "GENE":
            seq0 = Seq("")
            seq0 = seq0.read_fasta(folder + cmd2 + '.txt')
            termcolor.cprint("GENE", 'green')
            response = seq0.reverse()

        print(response)
        cs.send(response.encode())
        cs.close()