<jupyter_start><jupyter_text>Fastq to fasta<jupyter_code>import os
from Bio import SeqIO
InDir = "/mnt/d/Lab/16S-Taxa-Phlyo/result/M15/merge"
def parseFastqPairs(InDir, OutDir):
    allSeq = []
    fastaFileList = []
    fastaDir = os.path.join(OutDir, "fasta")
    if os.path.exists(fastaDir) == 0:
        os.makedirs(fastaDir, 0o777, True)
    for file in os.listdir(InDir):
        if file.endswith(".fastq") and os.path.getsize(os.path.join(InDir, file)) > 0:
            for seq in SeqIO.parse(os.path.join(InDir, file), "fastq"):
                seq.id = file.replace(".fastq", "")
                seq.name = ""
                seq.description = seq.description.split(" ")[1]
                fastaFile = os.path.join(fastaDir, file.replace(".fastq", ".fasta"))
                fastaFileList.append(fastaFile)
                SeqIO.write(seq, fastaFile, "fasta")
                allSeq.append(seq)
    SeqIO.write(allSeq, os.path.join(OutDir, "pairsMerge.fasta"), "fasta")
    return fastaFileList
allSeq = parseFastqPairs(InDir, OutDir)
allSeq
indexPath = "/mnt/d/Lab/16S-Taxa-Phlyo/database/silva-138-99-index.tsv"
def parseIndex(blastDir, OutDir):
    taxaList = []
    df = pd.DataFrame()
    out = pd.DataFrame()
    for file in os.listdir(blastDir):
        #print(file)
        if file.endswith(".tsv") and os.path.getsize(os.path.join(blastDir, file)) > 0:
            df1 = pd.read_table(os.path.join(blastDir, file), header = None)
            df1.columns = ["qseqid", "sseqid", "pident", "length", "mismatch", "gapopen", "qstart", "qend", "sstart", "send", "evalue", "bitscore"]
            df = df.append(df1)
    df = df.reset_index()
    df2 = pd.read_table(indexPath)
    index = dict(zip(df2["ID"], df2["Taxa"]))
    for i in range(len(df)):
        taxa = index[df["sseqid"][i]]
        taxaList.append(taxa)
    out["taxa"] = taxaList
    out["qseqid"] = df["qseqid"]
    out["pident"] = df["pident"]
    out["length"] = df["length"]
    return out
df1[0:1]
OutDir
pairsOut = parseIndex(os.path.join(OutDir, "blast"), OutDir)
pairsOut<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16810344827586207, 'fraction_numerical': 0.013409961685823755, 'mean_word_length': 2.9193245778611634, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '579974', 'license': 'Apache-2.0', 'n_tokens_mistral': 815, 'n_tokens_neox': 783, 'n_words': 137, 'path': 'process/mainifest.ipynb', 'repo_name': 'LD-Lab/16S-Taxa-Phlyo', 'size': '2088'}