<jupyter_start><jupyter_text>import data<jupyter_code>ori = SeqIO.read("/mnt/d/Lab/VC_SiLab/data/wt.fasta", "fasta")
ori = ori.upper()
ori
len(ori)
ori.seq[0:889]
ori.seq[0:888]
str(ori.seq)
mrna = ori.seq.transcribe()
prot = mrna.translate()
prot<jupyter_output><empty_output><jupyter_text>mutation<jupyter_code>len(ori.seq)
len(ori.seq)/3
mutable_seq = ori.seq.tomutable()
def SimNNK():
    nnkList = []
    protList = []
    for n1 in ["A", "C", "G", "T"]:
        for n2 in ["A", "C", "G", "T"]:
            for k in ["G", "T"]:
                nnk = n1+n2+k
                seq = Seq(nnk)
                mrna = seq.transcribe()
                prot = mrna.translate()
                nnkList.append(nnk)
                protList.append(str(prot))
    return nnkList, protList
nnkList, protList = SimNNK()
nnkList
protList
seq
ori.seq
seq_list = []
for i in range(int(len(mutable_seq)/3)):
    mutable_seq = ori.seq.tomutable()
    for nnk, prot in zip(nnkList, protList):
        mutable_seq[i*3:i*3+3] = nnk
        #print(mutable_seq)
        seq = mutable_seq.toseq()
        Seq = SeqRecord(seq)
        Seq.id = str(i+1) + "_" + str(i*3+1) + ":" + str(i*3+3) + "_" + nnk + "_" + prot
        Seq.name = ""
        Seq.description = ""
        seq_list.append(Seq)
len(ori.seq)/3 * 32
len(seq_list)<jupyter_output><empty_output><jupyter_text>只有seq,不算是record！<jupyter_code>seq_list[0:5]
SeqIO.write(seq_list, "mutate_sim.fasta", "fasta")
seq_list[0]
type(seq_list[0])<jupyter_output><empty_output><jupyter_text>position+nnk+prot 1_i*3:i*3+3_AAT_K   seq mapping<jupyter_code>demo = "/mnt/d/Lab/VC_SiLab/result/A3/fastp/A3_S3_L001.fastq"
for seq in SeqIO.parse(demo, fastq):  
from Bio.Blast.Applications import NcbiblastxCommandline
help(NcbiblastxCommandline)
!blastn -h
makeblastdb -in mutate_sim.fasta -parse_seqids -dbtype nucl
import os
import subprocess
db = "/mnt/d/Lab/VC_SiLab/data/mutate_sim.fasta"
def RunBlastnParallel(fastaList, db, jobs, threads, OutDir):
    pool = Pool(processes=jobs)
    pool.starmap(RunBlastn, zip(fastaList, repeat(db), repeat(threads), repeat(OutDir)))
    pool.close()
    pool.join()
    pool.terminate()
def RunBlastn(fasta, db, threads, OutDir):
    blastDir = os.path.join(OutDir, "blast")
    if os.path.exists(blastDir) == 0:
        os.makedirs(blastDir, 0o777, True)
    OutFile = os.path.join(blastDir, os.path.split(fasta)[1].replace(".fasta", "") + "_blast.tsv")
    cmd = "blastn -query " + fasta  + " -out " + OutFile + " -evalue 1.0 -max_target_seqs 1 -outfmt 6 -db " + db + " -num_threads " + str(threads) 
    print(cmd)
    subprocess.call(cmd, shell=True)
fasta = "/mnt/d/Lab/VC_SiLab/result/A3/fastp/A3_S3_L001.fastq"
OutDir = "/mnt/d/Lab/VC_SiLab/result/A3"
SeqIO.convert("/mnt/d/Lab/VC_SiLab/result/A3/fastp/A3_S3_L001.fastq", "fastq", "/mnt/d/Lab/VC_SiLab/result/A3/fastp/A3_S3_L001.fasta", "fasta")
fasta = "/mnt/d/Lab/VC_SiLab/result/A3/fastp/A3_S3_L001.fasta"
RunBlastn(fasta, db, 8, OutDir)<jupyter_output>blastn -query /mnt/d/Lab/VC_SiLab/result/A3/fastp/A3_S3_L001.fasta -out /mnt/d/Lab/VC_SiLab/result/A3/blast/A3_S3_L001_blast.tsv -evalue 1.0 -max_target_seqs 1 -outfmt 6 -db /mnt/d/Lab/VC_SiLab/data/mutate_sim.fasta -num_threads 8
{'fraction_non_alphanumeric': 0.16547210969149267, 'fraction_numerical': 0.028669367404175757, 'mean_word_length': 3.6120689655172415, 'pattern_counts': {'":': 1, '<': 16, '<?xml version=': 0, '>': 16, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '253923', 'license': 'Apache-2.0', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1391, 'n_words': 208, 'path': 'Variant_Calling.ipynb', 'repo_name': 'Junyu25/Variant_Calling', 'size': '3209'}