in reply to A program to extract the reads and modify the seq ID
Hello Teju,
Welcome to Perlmonks! There are several problems in your program/data:
So, if you fix all of those things - you should be on your way (to glory or otherwise!).
Here's my program fixed up mostly for clarity/readability:
use strict; use warnings; my $idsfile = "sample_IDs.txt"; my $seqfile = "sample_reads.fasta"; my %ids = (); open (my $idfh, "<", $idsfile) or die "Can't open $idsfile - ", $!, "\ +n"; while(my $line = <$idfh>) { chomp $line; next unless $line; my @contents = split /\s/, $line; $ids{$contents[0]} += 1; } close $idfh; local $/ = "\n>"; # read by FASTA record open (my $fastafh, "<", $seqfile) or die "Can't open $seqfile - ", $!, + "\n"; while (my $line = <$fastafh>) { chomp $line; next unless $line; my ($id) = $line =~ /^(\S+)/; # parse ID as first word in FASTA h +eader next unless $id; if ($ids{">" . $id}) { $line =~ s/^>*.+\n//; # remove FASTA header $line =~ s/\n//g; # remove endlines print "$line\n"; } } close $fastafh;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A program to extract the reads and modify the seq ID
by Kenosis (Priest) on Feb 25, 2014 at 18:08 UTC | |
by robby_dobby (Hermit) on Feb 26, 2014 at 04:02 UTC | |
by Kenosis (Priest) on Feb 26, 2014 at 05:29 UTC | |
by robby_dobby (Hermit) on Feb 26, 2014 at 06:02 UTC | |
by Kenosis (Priest) on Feb 26, 2014 at 06:17 UTC |