<jupyter_start><jupyter_text>Filter contigs<jupyter_code>!pwd
import os
from Bio import SeqIO
dlen = 10000

OutDir = "/home/junyuchen/Lab/Phage-SOP/Result/Filter"

for contigs in SeqIO.parse("/home/junyuchen/Lab/Phage-SOP/Result/Meta-spades-test/BT_FDSW202399939-1r/scaffolds.fasta", "fasta"):
    if len(contigs) > dlen:
        print(contigs.id)
        print(contigs)
        contigsOutDir = os.path.join(OutDir, contigs.name)
        contigsOutPath = os.path.join(contigsOutDir, contigs.name+".fasta")
        os.makedirs(contigsOutDir, 0o777, True)
        SeqIO.write(contigs, contigsOutPath, "fasta")
def AnnotatePhage(Dir):
    for subdir, dirs, files in os.walk(Dir):
        contigsOutDir = ""
        contigsOutPath = ""
        #SpadesFilePath = ""
        prefixList = []
        contigsFileList = []
        contigsOutDirList = []
        for file in files:
            if file == "scaffolds.fasta":
                #SpadesFilePath = os.path.join(subdir, "scaffolds.fasta")
                for contigs in SeqIO.parse(contigs, "fasta"):
                    if len(contigs) > dlen:
                        print(contigs.id)
                        print(contigs)
                        contigsOutDir = os.path.join(subdir, contigs.name) #OutDir is the sub dir of run
                        contigsOutPath = os.path.join(contigsOutDir, contigs.name+".fasta")
                        contigsOutDirList.append(contigsOutDir)
                        contigsFileList.append(contigsOutPath)
                        prefixList.append(contigs.name)
                        os.makedirs(contigsOutDir, 0o777, True)
                        SeqIO.write(contigs, contigsOutPath, "fasta")
        #RunProkkaParallel(contigsFileList, contigsOutDirList, prefixList)<jupyter_output><empty_output><jupyter_text>prokka in parallel<jupyter_code>def RunProkka(fasta, outDir, prefix):
    cmd = "prokka --kingdom Viruses --hmms VOGs --addgenes --prefix " + prefix + "--outdir " + outDir + fasta
    subprocess.call(cmd, shell=True)
prokka --outdir mydir --prefix Phage contigs.fa
prokka --kingdom Viruses --prefix Phage --addgenes --outdir prokka/CD1382_spades ./Quast-spades-kmer/CD1382_metaspades.fasta
--hmms VOGs<jupyter_output><empty_output><jupyter_text>set up the database<jupyter_code>def RunProkkaParallel(fileList, outFileList, prefixList):
    #numOfprocess = len(R1List)
    #pool = Pool(processes=numOfprocess)
    pool = Pool(processes=20)
    pool.starmap(RunProkka, zip(fileList, outFileList, prefixList))
    pool.close()
    pool.join()
    pool.terminate()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1124374278013092, 'fraction_numerical': 0.013092029264536002, 'mean_word_length': 2.679886685552408, 'pattern_counts': {'":': 1, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '583730', 'license': 'Apache-2.0', 'n_tokens_mistral': 921, 'n_tokens_neox': 882, 'n_words': 148, 'path': 'Anno/Utility_PostProcess-Filter.ipynb', 'repo_name': 'Junyu25/Bacteriophage-helper', 'size': '2597'}