Entering edit mode
10.2 years ago
cara78
▴
10
Hi
I have a perl script that gets every 40th sequence out of a big fasta file. But now I need it to stop after getting 300,000 sequences to the subset file.
I have a while loop and tried other loops but I cant seem to get it.
use strict;
use warnings;
#extracts sequences to create subset.
open (my $fh,"$ARGV[0]") or die "Failed to open file: $!\n";
open (my $out_fh, ">$ARGV[0]_subset.fasta");
my $count = 0;
while(<$fh>) {
while($count < 300000){
$count ++;
#$. holds the number of the last read line
next if $. % 160 != 1;
my $header_line = $_;
my $seq = <$fh>;
print $out_fh "$header_line$seq";
}
}
close $fh;
close $out_fh;
Could anyone please advise how to fix the loop
Thanks