标签:
#!/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的, 还好都是脚本语言, 理解起来也比较轻松。
标签:
原文地址:http://www.cnblogs.com/xudongliang/p/5009635.html