-close(INPUT);
-
-my $n = scalar(@header);
-if ($n > 0) {
- my %hash = ();
- my @ktable = ();
-
- my $tid = 0;
-
- for (my $i = 0; $i < $n; $i++) {
- my @arr = split(/\t/, $header[$i]);
- if ($arr[0] ne "\@SQ") { push(@ktable, ""); next; }
- my $hasSN = 0;
- foreach my $key (@arr) {
- if (substr($key, 0, 3) eq "SN:") {
- $hash{$key} = $i;
- $hasSN = 1;
- last;
- }
- }
- if (!$hasSN) { print STDERR "\"$header[$i]\" does not have a SN tag!\n"; exit(-1); }
- push(@ktable, $fields[$tid++]);
- }
-
- if ($tid != $M) { print STDERR "Number of \@SQ lines is not correct!\n"; exit(-1); }
-
- open(OUTPUT, ">$out_file");
- for (my $i = 0; $i < $n; $i++) {
- if ($ktable[$i] eq "") { print OUTPUT $header[$i]; }
- else { print OUTPUT $header[$hash{$ktable[$i]}]; }
- print OUTPUT "\n";
- }
- close(OUTPUT);