均匀化读取长度

时间:2015-06-01 14:50:15

标签: python perl bioinformatics dna-sequence

我有一个fastq文件中配对末端读数的数据集,长度范围为300到414 bp(真菌ITS2序列)。 我希望我的所有读数(几百万)都是414长,用Ns填充3'较短的读数结束。因此,如果读取长度为400 bp,我希望通过在序列末尾添加14 Ns来使其长度为414。 有没有人知道能够执行该任务的python / perl脚本?

2 个答案:

答案 0 :(得分:1)

$str .= 'N' x (414 - length($str));

答案 1 :(得分:0)

使用BioPython。如果序列长度超过414 bp,您可能需要更改default_phred_score_for_N值和/或添加行为。

from Bio import SeqIO
from Bio import Seq

path = r'C:\path\to\file.fastq'
default_phred_score_for_N = 60

def pad_sequence(record):
    sequence = str(record.seq)
    if len(sequence) < 414:
        #pad sequence
        padding_length = 414 - len(sequence)
        sequence += 'N' * padding_length

        # pad annotation
        annotation = record.letter_annotations['phred_quality']
        annotation  += [default_phred_score_for_N] * padding_length
        record.letter_annotations = {}

        record.seq = Seq.Seq(sequence)
        record.letter_annotations = {'phred_quality': annotation}
        return record
    return record


padded_sequences = (pad_sequence(record) for record in \
                    SeqIO.parse(path, 'fastq'))

SeqIO.write(padded_sequences, "padded.fastq", 'fastq')