The problem is earlier where $id is set for the > lines but then cleared on the subsequent sequence lines
while(<$fh>){ my $id = ''; chomp; if ($_ =~ /^>(.+)/){ $id = $1; } else { $id2seq{$id} .= $_; } }
Try
poj#!/usr/bin/perl use strict; use warnings; my $id; my %id2seq; my $infile = 'human_hg19_circRNAs_putative_spliced_sequence.fa'; open my $fh,'<',$infile or die "Could not open $infile : $!"; while (<$fh>){ if ( /^>(.+)/ ){ $id = (split /\|/, $1)[0]; } $id2seq{$id} .= $_; } foreach my $id (keys %id2seq){ my $filename = $id.'.fa'; print "Creating $filename\n"; open my $out_fh,'>', $filename or die "Could not open $filename : $!"; print $out_fh $id2seq{$id}; close $out_fh; } close $fh;
In reply to Re^5: An overlapping regex capture
by poj
in thread An overlapping regex capture
by Peter Keystrokes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |