extern_extremity_size=primer_size+overhang_size+bsaI_size+buffer_size# size of non-payload dna part at the extern extremities (start of first block and end of last block)
intern_extremity_size=overhang_size+bsaI_size+buffer_size# size of non-payload dna part at the extremities between blocks
max_total_block_size=1000# maximum allowed size for a complete block
min_total_block_size=1000# minimum allowed size for a complete block
max_total_block_size=500# maximum allowed size for a complete block
min_total_block_size=500# minimum allowed size for a complete block
n_block_max=10# maximum assembled number of blocks
max_payload_dna_len=max_total_dna_len-2*extern_extremity_size-2*(n_block_max-1)*intern_extremity_size# without the assembly stuff
max_binary_len=bdc.size_binary_from_dna_len_baa(max_payload_dna_len)-CHECK_SUM_SIZE# convert the remaining bases to binary and remove the checksum bits
max_binary_len=bdc.size_binary_from_dna_len_abaab(max_payload_dna_len)-CHECK_SUM_SIZE# convert the remaining bases to binary and remove the checksum bits
# fill with '0' at the beginning of the binary # not the end because some zip can end with octets of 0, which makes difficult to remove only the non coding '0'
# apply the same filter used in the encoding to the binary string to remove it
binary_string=apply_binary_filter(binary_string)
binary_string=binary_string[::-1]# reverse the binary string to get the original
# case binaries length is not multiple of 8 -> remove the excess bits at the beginning that have been added in the encoding to get a round number of blocks
rest=len(binary_string)%8
ifrest!=0:
binary_string=binary_string[rest:]
# remove octets of zeros at the beginning (the start of the sequence can be filled with zeros to get a round number of blocks)
whilebinary_string.startswith(8*"0"):# 1/256 (2**8) chance to remove actual data ! but 8*0 is ascii char NULL
binary_string=binary_string[8:]
#return binary_string #TODO REMOVE
# convert binaries into bytes
n=int(binary_string,2)
bytes=n.to_bytes((n.bit_length()+7)//8,'big')
ifnotbinary_from_dna_string:
print("warning file conversion, decoding an empty sequence",seq_name,"in",input_path)
continue
# write the bytes into the file
withopen(output_path,"wb")asf:
f.write(bytes)
# test if the check_sum corresponds to the binary string
print("Invalid check sum for",seq_name,"in",input_path)
continue
# apply the same filter used in the encoding to the binary string to remove it
binary_string=apply_binary_filter(binary_string)
binary_string=binary_string[::-1]# reverse the binary string to get the original
# case binaries length is not multiple of 8 -> remove the excess bits at the beginning that have been added in the encoding to get a round number of blocks
rest=len(binary_string)%8
ifrest!=0:
binary_string=binary_string[rest:]
# remove octets of zeros at the beginning (the start of the sequence can be filled with zeros to get a round number of blocks)
whilebinary_string.startswith(8*"0"):# 1/256 (2**8) chance to remove actual data ! but 8*0 is ascii char NULL
binary_string=binary_string[8:]
# convert binaries into bytes
n=int(binary_string,2)
bytes=n.to_bytes((n.bit_length()+7)//8,'big')
# write the bytes into the file
withopen(output_path,"wb")asf:
f.write(bytes)
return# end the decoding, since the sequence passed the checksum
# =================== main ======================= #