perl 截取 fastq文件

#!/usr/bin/perl -w
use warnings;
use strict;

my $usage = qq{$0 input_fastq trim_length};
die "$usage\n" if scalar @ARGV != 2;
my ($fastq, $trim_length) = @ARGV;

open(FASTQ, $fastq) or die "Can't open $fastq\n";
while (my $readid = <FASTQ>) {
        chomp $readid;
        chomp (my $sequence  = <FASTQ>);
        chomp (my $comment   = <FASTQ>);
        chomp (my $quality   = <FASTQ>);

        my $sub_seq      = length $sequence < $trim_length ? $sequence : substr $sequence, 0, $trim_length;
        my $sub_quality  = length $sequence < $trim_length ? $quality  : substr $quality,  0, $trim_length;
        print qq{$readid\n$sub_seq\n$comment\n$sub_quality\n};

}
close FASTQ;

fastq 文件每4行代表一条序列, 利用一个循环,每次读取4行,然后处理;

当读到文件结尾时,$readid 为空,循环终止,

基本思路是看defuse (检测融合基因的工具)的源代码看到的, 里面有一个trim_fastq.pl  脚本,自己稍微修改了下;

以前都是用python的, 新的公司都是用perl的, 还好都是脚本语言, 理解起来也比较轻松。

posted on 2015-12-01 12:33  庐州月光  阅读(1795)  评论(0编辑  收藏  举报