Skip to content

Instantly share code, notes, and snippets.

@klmr

klmr/remove-mate.pl

Created Apr 15, 2017
Embed
What would you like to do?
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