modified: Makefile
[GalaxyCodeBases.git] / perl / etc / fqlenpad.pl
blob68a7e140a66adb4ff822a9f86828ea3a2a77472b
1 #!/usr/bin/env perl
2 =pod
3 Author: Hu Xuesong @ BIOPIC <galaxy001@gmail.com>
4 Version: 1.0.0 @ 20120720
5 =cut
6 use strict;
7 use warnings;
8 use Galaxy::IO;
10 die "Usage: $0 <pad to len> <fq.gz> [out midfix]\n" if @ARGV<2;
11 my $padto=shift;
12 my $inf=shift;
13 my $outf=shift;
15 my $main = $inf;
16 $main =~ s/\.fq(\.gz)$//;
17 if ($outf) {
18 $main .= ".$outf"
20 $main .= ".$padto.fq.gz";
21 warn "\@$padto. From [$inf] to [$main]\n";
23 my $infh = openfile($inf);
24 open OUT,'|-',"gzip -9c > $main" or die "Error opening $main: $!\n";
25 my ($a,$b,$c,$d);
26 while (<$infh>) {
27 $a=$_;
28 chomp($b=<$infh>);
29 $c=<$infh>;
30 chomp($d=<$infh>);
31 if (length($b) < $padto) {
32 my $t = $padto - length($b);
33 $b .= 'N' x $t;
34 $d .= '#' x $t;
35 } elsif (length($b) == $padto) {
37 } else {die;}
38 print OUT "$a$b\n$c$d\n";
41 close $infh;
42 close OUT;