Ejemplo n.º 1
0
 def decodeFolder(self, packet_len_format: str = "I", crc_len_format: str = "L",
                  number_of_chunks_len_format: str = "I", degree_len_format: str = "I", seed_len_format: str = "I",
                  last_chunk_len_format: str = "I") -> typing.Optional[int]:
     decoded: bool = False
     self.EOF: bool = False
     if self.static_number_of_chunks is not None:
         self.number_of_chunks = self.static_number_of_chunks
         number_of_chunks_len_format = ""  # if we got static number_of_chunks we do not need it in struct string
     for file in os.listdir(self.file):
         if file.endswith(".LT") or file.endswith("DNA"):
             self.EOF = False
             if file.endswith("DNA"):
                 self.f = quat_file_to_bin(self.file + "/" + file)
             else:
                 self.f = open(self.file + "/" + file, "rb")
             new_pack = self.getNextValidPacket(True, packet_len_format=packet_len_format,
                                                crc_len_format=crc_len_format,
                                                number_of_chunks_len_format=number_of_chunks_len_format,
                                                degree_len_format=degree_len_format, seed_len_format=seed_len_format,
                                                last_chunk_len_format=last_chunk_len_format)
             if new_pack is not None:
                 decoded = self.input_new_packet(new_pack)
             if decoded:
                 break
     self.EOF = True
     print("Decoded Packets: " + str(self.correct))
     print("Corrupt Packets : " + str(self.corrupt))
     if self.GEPP.isPotentionallySolvable():
         decoded = self.GEPP.solve()
     if hasattr(self, "f"):
         self.f.close()
     if not decoded and self.EOF:
         print("Unable to retrieve File from Chunks. Too much errors?")
         return -1
Ejemplo n.º 2
0
 def decodeFolder(self,
                  packet_len_format: str = "I",
                  crc_len_format: str = "L",
                  number_of_chunks_len_format: str = "I",
                  quality_len_format: str = "I",
                  epsilon_len_format: str = "f",
                  check_block_number_len_format: str = "I"):
     decoded: bool = False
     self.EOF: bool = False
     if self.static_number_of_chunks is not None:
         self.number_of_chunks = self.static_number_of_chunks
         number_of_chunks_len_format = ""  # if we got static number_of_chunks we do not need it in struct string
     for dir_file in os.listdir(self.file):
         if dir_file.endswith(".ONLINE") or dir_file.endswith("DNA"):
             self.EOF = False
             if dir_file.endswith("DNA"):
                 self.f = quat_file_to_bin(self.file + "/" + dir_file)
             else:
                 self.f = open(self.file + "/" + dir_file, "rb")
             new_pack = self.getNextValidPacket(
                 True,
                 packet_len_format=packet_len_format,
                 crc_len_format=crc_len_format,
                 number_of_chunks_len_format=number_of_chunks_len_format,
                 quality_len_format=quality_len_format,
                 epsilon_len_format=epsilon_len_format,
                 check_block_number_len_format=check_block_number_len_format
             )
             if new_pack is not None:
                 decoded = self.input_new_packet(new_pack)
             if decoded:
                 break
     print("Decoded Packets: " + str(self.correct))
     print("Corrupt Packets : " + str(self.corrupt))
     if self.GEPP is not None and self.GEPP.isPotentionallySolvable():
         decoded = self.GEPP.solve()
     if hasattr(self, "f"):
         self.f.close()
     if not decoded and self.EOF:
         print("Unable to retrieve File from Chunks. Too much errors?")
         return -1
Ejemplo n.º 3
0
 def decodeFolder(self,
                  packet_len_format: str = "I",
                  crc_len_format: str = "I",
                  number_of_chunks_len_format: str = "I",
                  id_len_format: str = "I"):
     """
     Decodes the information from a folder if self.file represents a folder and the packets were saved
     in multiple files and prints the number of decoded and corrupted packets.
     :param packet_len_format: Format of the packet length
     :param crc_len_format:  Format of the crc length
     :param number_of_chunks_len_format: Format of the number of chunks length
     :param id_len_format: Format of the ID length
     :return: -1 if the decoding wasn't successful
     """
     decoded = False
     self.EOF = False
     if self.static_number_of_chunks is not None:
         self.number_of_chunks = self.static_number_of_chunks
         number_of_chunks_len_format = ""  # if we got static number_of_chunks we do not need it in struct string
     for file in os.listdir(self.file):
         if file.endswith(".RU10") or file.endswith("DNA"):
             self.EOF = False
             if file.endswith("DNA"):
                 if self.error_correction.__name__ == 'dna_reed_solomon_decode':
                     try:
                         self.f = quad_file_to_bytes(self.file + "/" + file)
                     except TypeError:
                         print(
                             "skipping CORRUPT file - contains illegal character(s)"
                         )
                         self.corrupt += 1
                         continue
                 else:
                     try:
                         self.f = quat_file_to_bin(self.file + "/" + file)
                     except TypeError:
                         print(
                             "skipping CORRUPT file - contains illegal character(s)"
                         )
                         self.corrupt += 1
                         continue
             else:
                 self.f = open(self.file + "/" + file, "rb")
             new_pack = self.getNextValidPacket(
                 True,
                 packet_len_format=packet_len_format,
                 crc_len_format=crc_len_format,
                 number_of_chunks_len_format=number_of_chunks_len_format,
                 id_len_format=id_len_format)
             if new_pack is not None:
                 # koennte durch input_new_packet ersetzt werden:
                 # self.addPacket(new_pack)
                 decoded = self.input_new_packet(new_pack)
             if decoded:
                 break
             ##
     print("Decoded Packets: " + str(self.correct))
     print("Corrupt Packets: " + str(self.corrupt))
     if hasattr(self, "f"):
         self.f.close()
     if not decoded and self.EOF:
         print("Unable to retrieve File from Chunks. Too many errors?")
         return -1
Ejemplo n.º 4
0
 def decodeFile(self,
                packet_len_format: str = "I",
                crc_len_format: str = "L",
                number_of_chunks_len_format: str = "I",
                id_len_format: str = "I"):
     """
     Decodes the information from a file if self.file represents a file and the packets were saved in a single file.
     :param packet_len_format: Format of the packet length
     :param crc_len_format:  Format of the crc length
     :param number_of_chunks_len_format: Format of the number of chunks length
     :param id_len_format: Format of the ID length
     :return: -1 if the decoding wasn't successful
     """
     decoded = False
     self.EOF = False
     if self.file.lower().endswith("dna"):
         try:
             self.f.close()
             self.f = quat_file_to_bin(self.file)
         except TypeError:
             print("skipping CORRUPT file - contains illegal character(s)")
             self.corrupt += 1
     if self.static_number_of_chunks is not None:
         self.number_of_chunks = self.static_number_of_chunks
         number_of_chunks_len_format = ""  # if we got static number_of_chunks we do not need it in struct string
     if self.file.lower().endswith("fasta"):
         self.f.close()
         self.f = open(self.file, "r")
         raw_packet_list = []
         while not (decoded or self.EOF):
             line = self.f.readline()
             if not line:
                 self.EOF = True
                 break
             try:
                 error_prob, seed = line[1:].replace("\n", "").split("_")
             except:
                 error_prob, seed = "0", "0"
             line = self.f.readline()
             if not line:
                 self.EOF = True
                 break
             dna_str = line.replace("\n", "")
             raw_packet_list.append((error_prob, seed, dna_str))
             new_pack = self.parse_raw_packet(
                 BytesIO(tranlate_quat_to_byte(dna_str)).read(),
                 crc_len_format=crc_len_format,
                 number_of_chunks_len_format=number_of_chunks_len_format,
                 packet_len_format=packet_len_format,
                 id_len_format=id_len_format)
             decoded = self.input_new_packet(new_pack)
     else:
         while not (decoded or self.EOF):
             new_pack = self.getNextValidPacket(
                 False,
                 packet_len_format=packet_len_format,
                 crc_len_format=crc_len_format,
                 number_of_chunks_len_format=number_of_chunks_len_format,
                 id_len_format=id_len_format)
             if new_pack is None:
                 break
             decoded = self.input_new_packet(new_pack)
     print("Decoded Packets: " + str(self.correct))
     print("Corrupt Packets : " + str(self.corrupt))
     if not decoded and self.EOF:
         print("Unable to retrieve File from Chunks. Too much errors?")
         return -1