#!/usr/bin/python3
'''
gbkToPkl is a simple script which instanciates a gumpy.Genome object from a specified
genbank file, and saves it as a pickle. Due to the security implications of 
pickle, use at your own risk!!

Designed to be run once on the host to provide significant speed up for containerised
workflows. Resultant pickles should not be sent/recieved!!
'''
import sys
import pickle
import gzip
import gumpy

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: gbkToPkl <genbank path> [--compress]")
    else:
        g = gumpy.Genome(sys.argv[1], show_progress_bar=True)
        if len(sys.argv) == 3 and sys.argv[2] == '--compress':
            #Save as gzipped version
            print("Compressing with gzip...")
            f = gzip.open(sys.argv[1]+".pkl", 'wb', compresslevel=2)
        else:
            #Save without gzip
            f = open(sys.argv[1]+".pkl", 'wb')
        pickle.dump(g, f)
        f.close()

