Skip to content

Instantly share code, notes, and snippets.

@klmr
Created April 15, 2017 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klmr/81a2b86cd93c706d28611f40bdfe2702 to your computer and use it in GitHub Desktop.
Save klmr/81a2b86cd93c706d28611f40bdfe2702 to your computer and use it in GitHub Desktop.
Remove the read mate number from the end of read IDs in a Fastq file
#!/usr/bin/env perl
use strict;
use warnings;
my $state = 0; # 0 = ID; 1 = sequence; 2 = repeat ID; 3 = quality
my $seqlen = 0;
while (<>) {
chomp;
if ($state == 0) {
s|/[12]$||;
$state = 1;
} elsif ($state == 1) {
if (/^\+/) {
$state = 3; # Skips repeat ID entirely.
} else {
$seqlen += length;
}
} else {
$seqlen -= length;
$state = 0 if $seqlen == 0;
}
print;
print "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment