示例#1
0
    def decode(self: object) -> None:
        """The main decoding method of the controller.

        Returns
        -------
        None
            Fills all the properties of an object and writes out the original
            sequence to a file.

        """
        self.bwm = list(BurrosWheeler.reconstruct_bwm(self.seq.read()))
        self.original = BurrosWheeler.decode_bwt(self.bwm[-1])
        Sequence(self.debwt_output).write(self.original)
示例#2
0
    def encode(self: object) -> None:
        """The main encoding method of the controller.

        Returns
        -------
        None
            Fills all the properties of an object and writes out the
            transformed sequence to a file.

        """
        self.rotations = list(BurrosWheeler.string_rotations(self.seq.read()))
        self.bwm = BurrosWheeler.construct_bwm(self.rotations[-1])
        self.bwt = BurrosWheeler.encode_bwt(self.bwm)
        Sequence(self.bwt_output).write(self.bwt)
示例#3
0
 def save_random(self: object) -> None:
     """This method is used to save a randomly generated DNA sequence 
     to a file.
     """
     seq_to_save = self.entry.get()
     if seq_to_save:
         path = filedialog.asksaveasfilename(
             initialdir= os.getcwd(),title="Select File", filetypes=(
                 ("Text Files", "*.txt"), ("all files","*.*")))
         if path:
             Sequence(path).write(seq_to_save)
             messagebox.showinfo("Sequence saved", "The sequence was saved to %s" %(
                 path))
     else:
         messagebox.showerror("No sequence entered", "The sequence box is empty")
示例#4
0
    def encode(self: object) -> None:
        """The main encoding method of the controller.

        Returns
        -------
        None
            Fills all the properties of an object and writes out the
            compressed sequence to a file.

        """
        tree = HuffmanTree(self.seq.read())
        tree.get_codings(tree.root)
        self.binary = tree.seq_to_binstr()
        self.unicode = HuffmanTree.binstr_to_unicode(self.binary)
        self.header = tree.codes_to_header()
        self.compressed = self.header + self.unicode
        Sequence(self.huff_output).write_bytes(self.compressed)
示例#5
0
    def __init__(self: object, path: str) -> None:
        """Class constructor.

        Parameters
        ----------
        path : str
            The path of the file to be read.

        Returns
        -------
        None
            A class instance.

        """
        self.path = os.path.splitext(path)[0]
        self.seq = Sequence(path)
        self.debwt_output = self.path + '_debwt.txt'
        self.bwm = None
        self.original = None
示例#6
0
    def decode(self: object) -> None:
        """The main decoding method of the controller.

        Returns
        -------
        None
            Fills all the properties of an object and writes out the
            decompressed sequence to a file.

        """
        seq = self.seq.read_bytes()
        self.header = seq[:seq.index('\n')]
        self.unicode = seq[seq.index('\n') + 1:]
        re_codes = HuffmanTree.header_to_codes(self.header)
        binary = HuffmanTree.unicode_to_binstr(self.unicode)
        padding = int(re_codes['pad'])
        self.binary = HuffmanTree.remove_padding(binary, padding)
        self.decompressed = HuffmanTree.binstr_to_seq(self.binary, re_codes)
        Sequence(self.dehuffman_output).write(self.decompressed)
示例#7
0
    def __init__(self: object, path: str) -> None:
        """Class constructor.

        Parameters
        ----------
        path : str
            The path of the file to be read.

        Returns
        -------
        None
            A class instance.

        """
        self.path = os.path.splitext(path)[0]
        self.seq = Sequence(path)
        self.huff_output = self.path + '_compressed.txt'
        self.binary = None
        self.header = None
        self.unicode = None
        self.compressed = None
示例#8
0
 def generate_random(self: object) -> None:
     """This method is used to generate random sequences of DNA of length
     50 and show them inside the random text box tkinter entry.
     """
     self.random.set(Sequence.generate(length=50))