Esempio n. 1
0
def test_nodefault(monkeypatch):
    G.create_directory(tmpdir)
    dbpath_tmp = os.path.join(tmpdir, "customdb.fas.nsq")
    with open(dbpath_tmp, "w") as f:
        f.write(">mockDB")
    try:
        monkeypatch.setattr('builtins.input', nodef_input)
        conf_from_file = Config()
        configpath = get_config_from_file(conf_from_file)[0]
        compare_configfiles(reference_dict, configpath, "3")
        if os.path.isfile(configpath):
            os.remove(configpath)
        configpath = get_config_from_file(conf_from_file)[1]
        compare_configfiles(reference_dict, configpath, "4")
        if os.path.isfile(configpath):
            os.remove(configpath)
        monkeypatch.setattr('builtins.input', nodef_input2)
        conf_from_file = Config()
        configpath = get_config_from_file(conf_from_file)[0]
        compare_configfiles(reference_dict, configpath, "8")
        configpath = get_config_from_file(conf_from_file)[1]
        compare_configfiles(reference_dict, configpath, "9")

    finally:
        if os.path.isfile(dbpath_tmp):
            os.remove(dbpath_tmp)
Esempio n. 2
0
def prepare_blastdb(config):
    if os.path.isdir(tmpdir):
        shutil.rmtree(tmpdir)
    G.create_directory(tmpdir)
    config.customdb = os.path.join(tmpdir, "primer_customdb.fas")
    config.blastdbv5 = False

    def dbinputfiles():
        filenames = [
            "GCF_004088235v1_20191001.fna",
            "GCF_002224565.1_ASM222456v1_genomic.fna"
        ]
        dbfile = os.path.join(tmpdir, "primer_customdb.fas")
        with open(dbfile, "w") as f:
            for filename in filenames:
                filepath = os.path.join(testfiles_dir, filename)
                records = SeqIO.parse(filepath, "fasta")
                for record in records:
                    if record.id == record.description:
                        description = (
                            record.id +
                            " Lactobacillus curvatus strain SRCM103465")
                        record.description = description
                    SeqIO.write(record, f, "fasta")
        return dbfile

    def create_customblastdb(config, infile):
        cmd = [
            "makeblastdb", "-in", infile, "-parse_seqids", "-title",
            "mockconservedDB", "-dbtype", "nucl", "-out", config.customdb
        ]
        G.run_subprocess(cmd, printcmd=False, logcmd=False, printoption=False)

    dbfile = dbinputfiles()
    create_customblastdb(config, dbfile)
Esempio n. 3
0
def test_commandline_fail_correct_settings():
    test = os.path.join("/", "primerdesign", "test")
    if os.path.isdir(test):
        shutil.rmtree(test)
    G.create_directory(test)
    G.create_directory(tmpdir)
    os.chdir(test)
    CONFFILE = os.path.join(testfiles_dir, "adconfig", "advanced_config3.json")
    reffile = os.path.join(dict_path, "p3parameters")
    wrong_ext = os.path.join(tmpdir, "p3parameters.txt")
    shutil.copy(reffile, wrong_ext)

    cmd = [
        "speciesprimer.py", "-t", "Lactobacillus_curvatus", "--configfile",
        CONFFILE, "-p", test
    ]

    outputlist = G.read_shelloutput(cmd)

    assert outputlist[-2::] == [
        '/primerdesign/tmp/genus_abbrev.csv',
        'A list containing the settings or a complete settings file'
        ' is required'
    ]

    os.chdir(pipe_dir)
    shutil.rmtree(test)
Esempio n. 4
0
def prepare_files():
    if os.path.isdir(genomic_dir):
        shutil.rmtree(genomic_dir)
    G.create_directory(genomic_dir)
    G.create_directory(config_dir)
    shutil.copy(conffile, testconfig)
    files = ["GCF_001981925v1_20190923.ffn", "GCF_003410375v1_20190923.ffn"]
    ffn_files_dir = os.path.join(testfiles_dir, "ffn_files")

    for filename in files:
        filepath = os.path.join(ffn_files_dir, filename)
        sequences = []
        with open(filepath) as f:
            records = list(SeqIO.parse(f, "fasta"))
        for record in records:
            seq = str(record.seq)
            sequences.append(seq)
        newfilename = ".".join(
            filename.split(".ffn")[0].split("v")) + "_genomic.fna"
        outpath = os.path.join(genomic_dir, newfilename)
        mockfna = SeqRecord(Seq("".join(sequences)),
                            id="MOCK_" + filename.split("_")[1],
                            name="MOCK_" + filename.split("_")[1],
                            description="Lactobacillus curvatus")
        with open(outpath, "w") as o:
            SeqIO.write(mockfna, o, "fasta")
    maxcontig = os.path.join(genomic_dir, "GCF_007MOCKv1_genomic.fna")
    with open(maxcontig, "w") as f:
        f.write(">GCF_007MOCKv1_file\n")
        for i in range(0, 500):
            f.write(">GCF_007MOCKv1_" + str(i) + "\n")
Esempio n. 5
0
def test_compare_corrupted_md5(delete_config):
    chmdfile = "ref_prok_rep_genomes.05.tar.gz.md5"
    create_mock_archives()
    shutil.rmtree("md5_files")
    G.create_directory("md5_files")
    os.chdir(tmpdir)
    for files in os.listdir(tmpdir):
        if (
            files.startswith("ref_prok_rep_genomes.05")
            and "tar.gz" not in files
        ):
            os.remove(files)
    with open(chmdfile, "r") as f:
        for line in f:
            info = (
                line.strip().split("  ")[0][0:-1] + "q67  " +
                line.strip().split("  ")[1])
    with open(chmdfile, "w") as f:
        f.write(info)

    getblastdb.download_from_ftp([chmdfile], delete_config)
    check_part_five(outcome=True)
    remove_tmp_db()
    os.chdir("..")
    if os.path.isdir(tmpdir):
        shutil.rmtree(tmpdir)
Esempio n. 6
0
def prepare_testfiles():
    def prepare_tmp_db():
        t = os.path.join(BASE_PATH, "testfiles", "tmp_config.json")
        # Docker only
        tmp_path = os.path.join(pipe_dir, "tmp_config.json")
        if os.path.isfile(tmp_path):
            os.remove(tmp_path)
        shutil.copy(t, tmp_path)

    def change_tmp_db():
        tmp_path = os.path.join(pipe_dir, "tmp_config.json")
        with open(tmp_path) as f:
            for line in f:
                tmp_dict = json.loads(line)
        tmp_dict["new_run"].update({'modus': "continue", "targets": None})
        with open(tmp_path, "w") as f:
            f.write(json.dumps(tmp_dict))

    def dbinputfiles():
        filenames = [
            "GCF_004088235v1_20191001.fna",
            "GCF_002224565.1_ASM222456v1_genomic.fna"
        ]
        with open(dbpath, "w") as f:
            for filename in filenames:
                filepath = os.path.join(testfiles_dir, filename)
                records = SeqIO.parse(filepath, "fasta")
                for record in records:
                    if record.id == record.description:
                        description = (
                            record.id +
                            " Lactobacillus curvatus strain SRCM103465")
                        record.description = description
                    SeqIO.write(record, f, "fasta")
            mockseqs = os.path.join(testfiles_dir, "mocktemplate.seqs")
            records = list(SeqIO.parse(mockseqs, "fasta"))
            SeqIO.write(records, f, "fasta")

        return dbpath

    def create_customblastdb():
        cmd = [
            "makeblastdb", "-in", dbpath, "-parse_seqids", "-title",
            "mockconservedDB", "-dbtype", "nucl", "-out", dbpath
        ]
        G.run_subprocess(cmd, printcmd=False, logcmd=False, printoption=False)

    if os.path.isdir(os.path.dirname(dbpath)):
        shutil.rmtree(os.path.dirname(dbpath))
    test = os.path.join("/", "primerdesign", "test")
    if os.path.isdir(test):
        shutil.rmtree(test)

    G.create_directory(os.path.dirname(dbpath))
    dbinputfiles()
    create_customblastdb()
    prepare_tmp_db()
    change_tmp_db()
Esempio n. 7
0
def primerBLAST(pqc, config):
    from speciesprimer import BlastPrep
    prepare_QC_testfiles(pqc, config)
    G.create_directory(pqc.primerblast_dir)
    prep = BlastPrep(pqc.primerblast_dir, pqc.primerlist, "primer",
                     pqc.config.blastseqs)
    use_cores, inputseqs = prep.run_blastprep()
    reffile = os.path.join(testfiles_dir, "primer_nontargethits.json")
    tofile = os.path.join(pqc.primerblast_dir, "nontargethits.json")
    shutil.copy(reffile, tofile)
    return inputseqs
Esempio n. 8
0
def test_compare_md5_archive(delete_config):
    chmdfile = "ref_prok_rep_genomes.05.tar.gz.md5"
    create_mock_archives()
    os.chdir(tmpdir)
    for files in os.listdir(tmpdir):
        if (
            files.startswith("ref_prok_rep_genomes.05")
            and "tar.gz" not in files
        ):
            os.remove(files)
    shutil.rmtree("md5_files")
    G.create_directory("md5_files")
    getblastdb.download_from_ftp([chmdfile], delete_config)
    check_part_five(outcome=True)
    remove_tmp_db()
    os.chdir("..")
    if os.path.isdir(tmpdir):
        shutil.rmtree(tmpdir)
Esempio n. 9
0
def test_no_old_md5(keep_config):
    chmdfile = "ref_prok_rep_genomes.05.tar.gz.md5"
    create_mock_archives()
    os.chdir(tmpdir)
    for files in os.listdir(tmpdir):
        if (
            files.startswith("ref_prok_rep_genomes.05")
            and not files.endswith(".md5")
        ):
            os.remove(files)
    shutil.rmtree("md5_files")
    G.create_directory("md5_files")
    getblastdb.download_from_ftp([chmdfile], keep_config)
    check_part_five(outcome=True)
    assert os.path.isfile("ref_prok_rep_genomes.05.tar.gz") is True
    remove_tmp_db()
    os.chdir("..")
    if os.path.isdir(tmpdir):
        shutil.rmtree(tmpdir)
Esempio n. 10
0
def prepare_QC_testfiles(pqc, config):
    targetdir = os.path.join(config.path, config.target)
    fna_dir = os.path.join(targetdir, "fna_files")
    qc_file = os.path.join(testfiles_dir, "Lb_curva_qc_sequences_ignoreqc.csv")
    qc_out = os.path.join(pqc.summ_dir, "Lb_curva_qc_sequences.csv")
    G.create_directory(fna_dir)
    G.create_directory(pqc.primer_qc_dir)
    if os.path.isfile(qc_out):
        os.remove(qc_out)
    if os.path.isdir(pqc.summ_dir):
        shutil.rmtree(pqc.summ_dir)
    G.create_directory(pqc.summ_dir)
    shutil.copy(qc_file, qc_out)
    files = ["GCF_001981925v1_20190923.ffn", "GCF_003410375v1_20190923.ffn"]
    ffn_files_dir = os.path.join(testfiles_dir, "ffn_files")
    for filename in files:
        filepath = os.path.join(ffn_files_dir, filename)
        sequences = []
        with open(filepath) as f:
            records = list(SeqIO.parse(f, "fasta"))
        for record in records:
            seq = str(record.seq)
            sequences.append(seq)
        newfilename = filename.split(".ffn")[0] + ".fna"
        outpath = os.path.join(fna_dir, newfilename)
        mockfna = SeqRecord(Seq("".join(sequences)),
                            id="MOCK_" + filename.split("_")[1],
                            name="MOCK_" + filename.split("_")[1],
                            description="Lactobacillus curvatus")
        with open(outpath, "w") as o:
            SeqIO.write(mockfna, o, "fasta")
Esempio n. 11
0
def test_qc_nottrue():
    from speciesprimer import CLIconf
    confargs["ignore_qc"] = False
    args = AttrDict(confargs)
    nontargetlist = []
    config = CLIconf(args.minsize, args.maxsize, args.mpprimer, args.exception,
                     args.target, args.path, args.intermediate, args.qc_gene,
                     args.mfold, args.skip_download, args.assemblylevel,
                     nontargetlist, args.skip_tree, args.nolist, args.offline,
                     args.ignore_qc, args.mfethreshold, args.customdb,
                     args.blastseqs, args.probe, args.blastdbv5)
    reffile = os.path.join(testfiles_dir, "ref_primer3_summary.json")
    with open(reffile) as f:
        for line in f:
            primer3dict = json.loads(line)
    pqc = PrimerQualityControl(config, primer3dict)
    G.create_directory(pqc.summ_dir)
    qc_file = os.path.join(testfiles_dir, "Lb_curva_qc_sequences_ignoreqc.csv")
    qc_out = os.path.join(pqc.summ_dir, "Lb_curva_qc_sequences.csv")
    shutil.copy(qc_file, qc_out)

    genDB = os.path.join(pqc.primer_qc_dir, "Lb_curva.genomic")
    tempDB = os.path.join(pqc.primer_qc_dir, "template.sequences")
    primer_qc_list = []
    pqc.create_template_db_file(primer_qc_list)
    pqc.create_assembly_db_file()
    assemblyfilepath = os.path.join(pqc.primer_qc_dir,
                                    H.abbrev(pqc.target) + ".genomic")
    templatefilepath = os.path.join(pqc.primer_qc_dir, "template.sequences")
    dblist = [assemblyfilepath, templatefilepath]
    for dbpath in dblist:
        P.index_database(dbpath)
    assert os.path.isfile(genDB) is False
    assert os.path.isfile(tempDB) is False

    os.chdir(pipe_dir)
    shutil.rmtree(config.path)
    if os.path.isdir(pqc.summ_dir):
        shutil.rmtree(pqc.summ_dir)
Esempio n. 12
0
 def write_config_file(self, target):
     path = self.config_dict[target]["path"]
     target_dir = os.path.join(path, target)
     genomic_dir = os.path.join(target_dir, "genomic_fna")
     config_dir = os.path.join(target_dir, "config")
     config_file = os.path.join(config_dir, "config.json")
     G.create_directory(target_dir)
     G.create_directory(config_dir)
     G.create_directory(genomic_dir)
     self.config_paths.append(config_file)
     with open(config_file, "w") as f:
         f.write(json.dumps(self.config_dict[target]))
Esempio n. 13
0
def get_DB(mode=False):
    today = time.strftime("%Y_%m_%d", time.localtime())
    if mode == "auto":
        signal.signal(signal.SIGTERM, exitatsigterm)
        with open(tmp_db_path, 'r') as f:
            for line in f:
                tmp_db = json.loads(line)
        delete = tmp_db['BLAST_DB']['delete']
        db = tmp_db['BLAST_DB']['db']
        try:
            dbdir = tmp_db['BLAST_DB']['path']
            blastdb_dir = dbdir
        except KeyError:
            blastdb_dir = "/blastdb"
        try:
            if tmp_db['BLAST_DB']['test'] is True:
                test = True
        except KeyError:
            test = False

        logging.basicConfig(
            filename=os.path.join(
                "/", "primerdesign",
                "speciesprimer_" + today + ".log"),
            level=logging.DEBUG, format="%(message)s")

    else:
        parser = commandline()
        args = parser.parse_args()
        delete = args.delete
        test = args.test
        if args.dbpath:
            if args.dbpath.endswith("/"):
                blastdb_dir = args.dbpath
            else:
                blastdb_dir = args.dbpath + "/"
        else:
            blastdb_dir = os.getcwd() + "/"

        db = args.database

        logging.basicConfig(
            filename=os.path.join(
                blastdb_dir, "blastdb_download_" + today + ".log"),
            level=logging.DEBUG, format="%(message)s")

    G.create_directory(os.path.join(blastdb_dir, "md5_files"))

    conf = config(db, blastdb_dir, delete, test)

    logger("Start Download of NCBI " + db + " BLAST database")
    get_md5files(conf)
    filelist = get_filelist(conf)
    download_from_ftp(filelist, conf)

    nal_filepath = os.path.join(blastdb_dir, db + ".nal")
    if os.path.isfile(nal_filepath):
        logger("NCBI " + db + " BLAST database is ready")
    else:
        logger(
            "Error nal file for NCBI " + db + " BLAST database is missing")
Esempio n. 14
0
def test_advancedconfig_fromfile():
    CONFFILE = os.path.join(testfiles_dir, "adconfig", "advanced_config.json")
    H.advanced_pipe_config(CONFFILE)
    filenames = [
        "no_blast.gi", "genus_abbrev.csv", "p3parameters", "species_list.txt"]

    for filename in filenames:
        ref = os.path.join(ref_data, "advanced_config", filename)
        newfile = os.path.join(dict_path, filename)
        assert filecmp.cmp(newfile, ref) is True
        deffile =  os.path.join(dict_path, "default", filename)
        os.remove(newfile)
        shutil.copy(deffile, newfile)

    G.create_directory(tmpdir)
    for filename in filenames:
        ref = os.path.join(ref_data, "advanced_config", filename)
        tmp = os.path.join(tmpdir, filename)
        shutil.copy(ref, tmp)
    CONFFILE = os.path.join(testfiles_dir, "adconfig", "advanced_config2.json")
    H.advanced_pipe_config(CONFFILE)
    for filename in filenames:
        ref = os.path.join(ref_data, "advanced_config", filename)
        newfile = os.path.join(dict_path, filename)
        assert filecmp.cmp(newfile, ref) is True
        deffile =  os.path.join(dict_path, "default", filename)
        os.remove(newfile)
        shutil.copy(deffile, newfile)

    CONFFILE = os.path.join(testfiles_dir, "adconfig","advanced_config3.json")
    tmp = os.path.join(tmpdir, "p3parameters")
    wrong_ext = os.path.join(tmpdir, "p3parameters.txt")
    shutil.copy(tmp, wrong_ext)
    exitstat = H.advanced_pipe_config(CONFFILE)
    assert exitstat == 1

    CONFFILE = os.path.join(testfiles_dir, "adconfig", "advanced_config4.json")
    exitstat = H.advanced_pipe_config(CONFFILE)
    assert exitstat == 1
    for filename in filenames:
        ref = os.path.join(ref_data, "advanced_config", filename)
        newfile = os.path.join(dict_path, filename)
        deffile =  os.path.join(dict_path, "default", filename)
        os.remove(newfile)
        shutil.copy(deffile, newfile)

    CERTFILE = os.path.join(testfiles_dir, "adconfig", "mock_certificate.crt")
    CERT_REF = os.path.join(tmpdir, "mock_certificate.crt")
    CONFFILE = os.path.join(tmpdir, "adconfig.json")
    CERT_EXT = os.path.join(tmpdir, "mock_certificate.txt")
    shutil.copy(CERTFILE, CERT_REF)
    shutil.copy(CERT_REF, CERT_EXT)
    conf = {"certificate": CERT_REF}
    with open(CONFFILE, "w") as f:
        f.write(json.dumps(conf))

    exitstat = H.advanced_pipe_config(CONFFILE)
    assert exitstat == 0

    os.remove(CONFFILE)

    conf = {"certificate": CERT_EXT}
    with open(CONFFILE, "w") as f:
        f.write(json.dumps(conf))
    exitstat = H.advanced_pipe_config(CONFFILE)
    assert exitstat == 1

    os.remove(CONFFILE)

    conf = {"certificate": tmpdir}
    with open(CONFFILE, "w") as f:
        f.write(json.dumps(conf))
    exitstat = H.advanced_pipe_config(CONFFILE)
    assert exitstat == 1

    shutil.rmtree(tmpdir)
Esempio n. 15
0
def test_rollback():
    testdir = os.path.join("/", "primerdesign", "test")
    target_dir = os.path.join(testdir, "Lactobacillus_curvatus")
    pangenome_dir = os.path.join(target_dir, "Pangenome")
    results_dir = os.path.join(pangenome_dir, "results")
    alignments_dir = os.path.join(results_dir, "alignments")
    consensus_dir = os.path.join(results_dir, "consensus")
    primer_dir = os.path.join(results_dir, "primer")
    primer_qc_dir = os.path.join(primer_dir, "primer_QC")
    blast_dir = os.path.join(results_dir, "blast")
    primerblast_dir = os.path.join(primer_dir, "primerblast")
    G.create_directory(primerblast_dir)
    G.create_directory(alignments_dir)
    G.create_directory(consensus_dir)
    G.create_directory(blast_dir)
    G.create_directory(primer_qc_dir)

    # annotation
    annotdir = "GCF_902362325v1_20191114"
    G.create_directory(os.path.join(target_dir, annotdir))
    outdir = annotdir
    assert os.path.isdir(os.path.join(target_dir, annotdir)) is True
    G.keyexit_rollback("annotation", dp=os.path.join(target_dir, outdir))
    assert os.path.isdir(os.path.join(target_dir, annotdir)) is False
    # p3
    p3_file = os.path.join(primer_dir, "primer3_output")
    output_file = p3_file
    with open(p3_file, "w") as f:
        f.write("PRIMER3MOCK")
    assert os.path.isfile(p3_file) is True
    G.keyexit_rollback("primer3 run", fp=output_file)
    assert os.path.isfile(p3_file) is False
    # alignments
    run_file = os.path.join(results_dir, "run_prank")
    with open(run_file, "w") as f:
        f.write("PRANK MSA MOCK")
    assert os.path.isfile(run_file) is True
    G.keyexit_rollback("Prank MSA run", dp=alignments_dir, fp=run_file)
    assert os.path.isfile(run_file) is False
    assert os.path.isdir(alignments_dir) is False
    # consensus
    run_file = os.path.join(results_dir, "run_consensus")
    with open(run_file, "w") as f:
        f.write("CONSAMBIG MOCK")
    assert os.path.isfile(run_file) is True
    G.keyexit_rollback("consensus run", dp=consensus_dir, fp=run_file)
    assert os.path.isfile(run_file) is False
    assert os.path.isdir(consensus_dir) is False
    # dp only
    run_file = os.path.join(results_dir, "run_consensus")
    G.create_directory(consensus_dir)
    assert os.path.isfile(run_file) is False
    G.keyexit_rollback("consensus run", dp=consensus_dir, fp=run_file)
    assert os.path.isfile(run_file) is False
    assert os.path.isdir(consensus_dir) is False
    # fp only
    run_file = os.path.join(results_dir, "run_consensus")
    with open(run_file, "w") as f:
        f.write("CONSAMBIG MOCK")
    G.keyexit_rollback("consensus run", dp=consensus_dir, fp=run_file)
    assert os.path.isfile(run_file) is False
    assert os.path.isdir(consensus_dir) is False
    # DB extraction
    filename = "BLASTnontarget0.sequences"
    filepath = os.path.join(primer_qc_dir, filename)
    with open(filepath, "w") as f:
        f.write("DB extract Mock")
    assert os.path.isfile(filepath) is True
    G.keyexit_rollback("DB extraction", fp=filepath)
    assert os.path.isfile(filepath) is False
    # blast
    directory = blast_dir
    blastfile = "conserved_0_results.xml"
    filepath = os.path.join(blast_dir, blastfile)
    with open(filepath, "w") as f:
        f.write("BLAST MOCK")
    filename = blastfile
    assert os.path.isfile(filepath) is True
    G.keyexit_rollback("BLAST search", dp=directory, fn=filename)
    assert os.path.isfile(filepath) is False
    # primerblast
    directory = primerblast_dir
    primerblastfile = "primer_0_results.xml"
    filepath = os.path.join(primerblast_dir, primerblastfile)
    with open(filepath, "w") as f:
        f.write("PRIMERBLAST MOCK")
    filename = primerblastfile
    assert os.path.isfile(filepath) is True
    G.keyexit_rollback("BLAST search", dp=directory, fn=filename)
    assert os.path.isfile(filepath) is False
    # DB indexing
    dbfiles = [
        "Lb_curva.genomic", "Lb_curva.genomic.sqlite3.db",
        "Lb_curva.genomic.uni", "Lb_curva.genomic.2bit"]
    for files in dbfiles:
        filepath = os.path.join(primer_qc_dir, files)
        with open(filepath, "w") as f:
            f.write(files + " Mock")
        assert os.path.isfile(filepath) is True
    db_name = "Lb_curva.genomic"
    G.keyexit_rollback("DB indexing", dp=primer_qc_dir, search=db_name)
    for files in dbfiles:
        filepath = os.path.join(primer_qc_dir, files)
        assert os.path.isfile(filepath) is False
    # pangenome
    assert os.path.isdir(pangenome_dir) is True
    G.keyexit_rollback("pan-genome analysis", dp=pangenome_dir)
    assert os.path.isdir(pangenome_dir) is False
    shutil.rmtree(testdir)
Esempio n. 16
0
def create_mock_archives():
    G.create_directory(tmpdir)
    G.create_directory(downdir)
    refhtml = os.path.join(testfiles_dir, "download.html")
    htmlfile = os.path.join(tmpdir, "mockfiles","download.html")
    shutil.copy(refhtml, htmlfile)
    with open(os.path.join(tmpdir, "ref_prok_rep_genomes.html.tmp"), "w") as f:
        f.write("mock")
    for i in range(0, 6):
        num = "{:02d}".format(i)
        filestart = "ref_prok_rep_genomes." + num
        mockends = [
            ".nhr", ".nni",
            ".nsi", ".nin",
            ".nog", ".nsq",
            ".nnd", ".nsd"]
        archive = "ref_prok_rep_genomes." + num + ".tar.gz"
        os.chdir(tmpdir)
        with tarfile.open(archive, "w:gz") as tar:
            for ending in mockends:
                filepath = filestart + ending
                with open(filepath, "w") as f:
                    f.write("")
                tar.add(filepath)

        with open(archive + ".md5", "w") as f:
            archmd5 = md5Checksum(archive)
            f.write(archmd5 + "  " + archive)

        archfile = "ref_prok_rep_genomes.03.tar.gz"
        tmpfile = os.path.join(downdir, "ref_prok_rep_genomes.03.tar.gz")
        if os.path.isfile(archfile):
            shutil.move(archfile, tmpfile)

        archfile = "ref_prok_rep_genomes.05.tar.gz"
        tmpfile = os.path.join(downdir, "ref_prok_rep_genomes.05.tar.gz")
        if os.path.isfile(archfile):
            shutil.copy(archfile, tmpfile)

        for files in os.listdir(tmpdir):
            if (
                files.startswith("ref_prok_rep_genomes.03")
                and not files.endswith(".md5")
            ):
                os.remove(files)

    md5_dir = os.path.join(tmpdir, "md5_files")
    G.create_directory(md5_dir)
    for files in os.listdir(tmpdir):
        if files.endswith("tar.gz.md5"):
            fromfile = os.path.join(tmpdir, files)
            tofilepath = os.path.join(md5_dir, files)
            downfiles = os.path.join(downdir, files)
            shutil.copy(fromfile, tofilepath)
            shutil.copy(fromfile, downfiles)

    chmdfile = os.path.join(md5_dir, "ref_prok_rep_genomes.05.tar.gz.md5")
    with open(chmdfile, "r") as f:
        for line in f:
            info = (
                line.strip().split("  ")[0][0:-1] + "k  " +
                line.strip().split("  ")[1])
    with open(chmdfile, "w") as f:
        f.write(info)
    nalfile = os.path.join(tmpdir, "ref_prok_rep_genomes.nal")
    with open(nalfile, "w") as f:
        f.write("")
    os.remove("ref_prok_rep_genomes.04.tar.gz")