def deserialize(file_path): """ This method re-rendered that serialized, compressed data found in the gzipped file located via the given file path, into a fully restored object of the ClusterPacket class. :param file_path: The locatation of the gzipped file containing the serialized object. """ cluster_lines = [] clusters = [] cluster_packet_id = 0 sample = None with gzip.open(file_path, 'rb') as obj_file: for line_number, line in enumerate(obj_file): line = line.rstrip() if line_number == 0: cluster_packet_id = int(line[1:].decode()) elif line_number == 1: sample = Sample.deserialize(line.decode()) else: if line.decode() == '-': if cluster_lines: clusters.append(Cluster.deserialize("\n".join(cluster_lines))) cluster_lines = [] else: cluster_lines.append(line.decode()) return ClusterPacket(cluster_packet_id, sample, clusters)
def deserialize(file_path): molecules = [] with open(file_path, 'rb') as obj_file: for line_number, line in enumerate(obj_file): line = line.rstrip() if line_number == 0: molecule_packet_id = int(line[1:].decode(encoding="ascii")) elif line_number == 1: sample = Sample.deserialize(line.decode(encoding="ascii")) else: molecules.append( Molecule.deserialize(line.decode(encoding="ascii"))) return MoleculePacket(molecule_packet_id, sample, molecules)