コード例 #1
0
from P1.Seq1 import Seq


GENE_FOLDER = "./PROJECT/"
gene_list = ["U5", "ADA", "FRAT1", "FXN", "RNU6_269P"]

print("-----| Practice 1, Exercise 10 |------")
for gene in gene_list:
    sequence = Seq()
    sequence.read_fasta(GENE_FOLDER + gene + ".txt")
    print("Gene", gene, "Most frequent Base: ", sequence.frequent_base())
コード例 #2
0
    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
コード例 #3
0
def gene(name):
    s = Seq()
    s.read_fasta(FOLDER + FILENAMES)
    return s
コード例 #4
0
from P1.Seq1 import Seq
from Client0 import Client

PRACTICE = 2
EXERCISE = 6

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

IP = "127.0.0.1"
PORT = 8081
c = Client(IP, PORT)
s = Seq()
s.read_fasta('../P2/FRAT1.txt')
count = 0
i = 0
while i < len(s.strbases) and count < 5:
    fragment = s.strbases[i:i + 10]
    count += 1
    i += 10
    print(c.talk(fragment))
コード例 #5
0
from P1.Seq1 import Seq


def print_result(i, sequence):
    print("Sequence" + str(i) + ": (Length: " + str(sequence.len()),
          ")" + str(sequence))
    print("Bases:", sequence.count())
    print("Rev:", sequence.reverse())
    print("Comp:", sequence.complement())


PROJECT_PATH = "../P1/PROJECT/"
print("-----| Practice 1, Exercise 9 |------")
s1 = Seq()
s1.read_fasta(PROJECT_PATH + "ADA.txt")
print_result("", s1)
コード例 #6
0
print(f"-----| Practice {PRACTICE}, Exercise {EXERCISE} |------")

FOLDER = "../Session-04/"
FILENAME = "FRAT1"
# -- Parameters of the server to talk to
IP = "127.0.0.1"
PORT = 58788

c1 = Client(IP, PORT)
c2 = Client(IP, PORT + 1)

print(c1)
print(c2)

s = Seq()
s.read_fasta(FOLDER + FILENAME)
bases = str(s)

length = 10

print(f"Gene {FILENAME}: {bases}")

c1.talk(f"Sending {FILENAME} Gene to the server, in fragments of {length} bases...")
c2.talk(f"Sending {FILENAME} Gene to the server, in fragments of {length} bases...")

for index in range(0,10):
    fragment = bases[index * length:(index + 1) * length]
    print(f"Fragment {index + 1}: {fragment}")

    if index % 2:
        c2.talk(f"Fragment {index + 1}: {fragment}")
コード例 #7
0
from P1.Seq1 import Seq

FOLDER = "../Session-04/"
Filename = ["U5", "ADA", "FRAT1", "FXN", "RNU6_269P"]
TypeDOC = '.txt'
bases = ['A', 'C', 'G', 'T']

print('----| Practice 1, Exercise 10| ----')
i = 0

for element in Filename:
    seq = Seq()
    seq.read_fasta(FOLDER + element + TypeDOC)
    Dictionary_bases = seq.seq_count()
    Amount_bases = list(Dictionary_bases.values())
    Most_freq = max(Amount_bases)
    print('Gene ', element, ': Most frequent base: ',
          bases[Amount_bases.index(Most_freq)])
コード例 #8
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())
コード例 #9
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
コード例 #10
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()
コード例 #11
0
from P1.Seq1 import Seq

folder = "../Session-04/"
filenames = ["U5", "ADA", "FRAT1", "FXN", "RNU6_269P"]
all_bases = ["A", "C", "G", "T"]

print("-----|Practice 1 , Exercise 10 |------")
for filename in filenames:
    s0 = Seq()
    s0.read_fasta(folder + filename)
    dictionary = s0.count()
    list_values = list(dictionary.values())
    maximum = max(list_values)
    print(
        f"Gene {filename}: Most frequent Base: {all_bases[list_values.index(maximum)]}"
    )
コード例 #12
0
from P1.Seq1 import Seq
def print_result(i, sequence):
    print("Sequence" + str(i) + ": (Lenght: " + str(sequence.len()) + ") " + str(sequence))
    print("Bases:", sequence.count())
    print("Rev:", sequence.reverse())
    print("Comp:", sequence.complement())

PROJECT_PATH = "../P1/PROJECT/"
print("----- | Practice 1, Exercise 9 | ------")
s1 = Seq()
s1.read_fasta(PROJECT_PATH + "U5.txt")
print_result("", s1)