7 die "Usage: $0 <mode(pe,se,total)> <input> <output>\n" if @ARGV != 3 or $ARGV[0] !~ /pe|se|total/;
9 my ($Mode,$Infile,$Outfile)=@ARGV;
10 warn "Mode=[$Mode], [$Infile]->[$Outfile]\n";
12 if ($Infile=~/.bz2$/) {
13 open( IN
,"-|","bzip2 -dc $Infile") or die "Error opening $Infile: $!\n";
14 } elsif ($Infile=~/.gz$/) {
15 open( IN
,"-|","gzip -dc $Infile") or die "Error opening $Infile: $!\n";
16 } else {open( IN
,"<",$Infile) or die "Error opening $Infile: $!\n";}
20 my @lineItem=split /\t/,$line;
21 my @Head=split /:/,$lineItem[0];
23 pop @Head; pop @Head; # >FCC01P5ACXX:8:1101:10000:187253#CGATGTAT/1:rep1:+:len68:W
25 $rep =~ s/^rep// or die "[x]ID format error.\n";
26 my $ID=join ':',@Head;
30 return [$ID,$CW,$rep,\
@lineItem];
35 die "[x]PE lines missing.\n" if scalar @Items % 2;
36 my $Paires = (scalar @Items) / 2;
38 for (my $i=0;$i<$Paires;$i++) {
40 @b=@
{$Items[$i + $Paires]};
41 die "[x]PE data error.\n" if ($a[1] ne $b[1]) or ($a[2] ne $b[2]);
42 push @OutItem,[@a,$b[3]];
50 my ($lastID,$id,$line,@Items,@dat)=('','');
52 if (defined $lastLine) {
57 return [] unless defined $line;
60 ($id,@dat)=@
{&splitLine
($line,$isPE)};
62 push @Items,[$id,@dat];
64 while ($lastID eq $id) {
66 last unless defined $line;
68 ($id,@dat)=@
{&splitLine
($line,$isPE)};
70 push @Items,[$id,@dat];
76 my $ref=mergePEitems
(\
@Items);
77 return $ref; # [] of [$ID,$CW,$rep,\@lineItem1,\@lineItem2]
79 return \
@Items; # [] of [$ID,$CW,$rep,\@lineItem]
85 my @lineItem=split /\t/,$line;
86 my $ID=$lineItem[0]; # >FCC01P5ACXX:8:1101:10000:15797#CGATGTAT/
89 return [$ID,1,\
@lineItem];
90 } elsif ($t == 12) { # SE
91 return [$ID,0,\
@lineItem];
93 die "[x]Line format error.\n";
97 my ($lastID,$id,$hasPE,$line,@Items,@dat,$isPE)=('','',0);
99 if (defined $lastLine) {
104 return [] unless defined $line;
107 ($id,$isPE,@dat)=@
{&splitTLine
($line)};
110 push @Items,[$id,$isPE,@dat];
112 while ($lastID eq $id) {
114 last unless defined $line;
116 ($id,$isPE,@dat)=@
{&splitTLine
($line)};
117 if ($lastID eq $id) {
119 push @Items,[$id,$isPE,@dat];
124 return [$hasPE,\
@Items]; # \@Items => [] of [$ID,$isPE,\@lineItem]
127 open OUT
,'>',$Outfile or die "Error opening $Outfile: $!\n";
132 while(@dat=@
{&ReadItems
(0)}) {
134 print Dumper
(\
@dat),'-' x
75,"$count\n";
136 warn "\nTotal Groups: $count\n";
141 while(@dat=@
{&ReadItems
(1)}) {
143 print Dumper
(\
@dat),'-' x
75,"$count\n"
145 warn "\nTotal Groups: $count\n";
148 my (@dat,$hasPE,$datref);
150 while(($hasPE,$datref)=@
{&LoadTItems
()}) {
153 print Dumper
(\
@dat),'-' x
75,"$count\n";
156 print OUT
join("\t",@
{$$_[2]}),"\n";
161 print OUT
join("\t",@
{$$_[2]}),"\n";
167 warn "\nTotal Groups: $count\n";
172 } elsif ($Mode eq 'se') {
174 } elsif ($Mode eq 'total') {