生物信息序列格式的批量修改與生物信息序列文件格式的轉(zhuǎn)換

序列格式轉(zhuǎn)化推薦看看SeqKit,TBtools等已有軟件,能用則用。

fasta格式轉(zhuǎn)fastq格式

  • 比對(duì)軟件比如bowtie并不支持比對(duì)fasta格式的文件,所以需要把fasta轉(zhuǎn)為fastq格式,但是fasta和fastq相比缺少質(zhì)量值,所以只能偽造一個(gè)加上去,這里用到seqtk來(lái)偽造,從而把fasta格式轉(zhuǎn)fastq格式。作者:今天沒(méi)回家
    seqtk seq test.fa -F "J" > test.fq

參考文章

批量修改fasta文件的序列名

轉(zhuǎn)載自BioInfo Voyager的博客,感謝他的分享!

    1. 準(zhǔn)備輸入的fasta序列文件input_file(要求序列名中不包含第二步輸入序列集的分隔符)
    1. 準(zhǔn)備輸入的替換集replace_file, 兩列,/t分隔(分隔符可以在腳本里修改)
    1. 使用以下python腳本,保存腳本為change_fa_name.py(腳本名稱(chēng)可以自定義)。
from sys import argv
import sys
 
input_file = argv[1]
replace_file = argv[2]
output_file = argv[3]
 
with open(input_file, 'r') as f:
    fasta_lines = f.readlines()
 
replacements = {}
with open(replace_file, 'r') as f:
    for line in f:
        (old_str, new_str) = line.strip().split('\t')
        replacements[old_str] = new_str
 
with open(output_file, 'w') as f:
    for line in fasta_lines:
        if line.startswith('>'):
            seq_id = line.split('>')[1].strip()
            if seq_id in replacements: 
                new_seq_id = replacements[seq_id]
                line = line.replace(seq_id, new_seq_id)
                f.write(line)
            else:
                print(seq_id + ' is not in the replacement set, the program exits running, please check your replacement set!')
                sys.exit()
        else:
            f.write(line)

保存腳本并運(yùn)行

python change_fa_name.py input_file replace_file output_file
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容