in reply to Re^2: An overlapping regex capture
in thread An overlapping regex capture
since you have two loops you can or integrate when you grab $id or just before opening the filehandle:
But, looking more closer to your code, you have many wrong things:
my %id2seq = (); # this is the verbose form of my %id2seq; my $id = ''; # this is the wrong place to declare this var! declar +e it when you need it ie # inside the while(<File>){ block # missing the mode: put always even if it defaults to '<' open File,"human_hg19_circRNAs_putative_spliced_sequence.fa",or die $! +; # better use lexical filehandle like in open my $fh, '<', $fi +lepath or die # bareword is still accepted but by onvention is UPPERCASE so + no open File... while(<File>){ chomp; # here you are capturing something: if you want just +the part before | you # have here the possibility to get it: /^>([\w\d]+\| +)/ as starting option? if($_ =~ /^>(.+)/){ # or here: $id = $1; # cutting $1 like in: $id = (split /\|/, $1)[0] ... # AHHH! this is error! are your use strict; use warnings ju +st make-up? # it must be foreach my $id .. # (or really does not raise a warn for the scope you given +to $id ??? if so is even # worst!!) # in short: pay attention to the scope of your variables foreach $id (keys %id2seq){ # here the last good possibility to cut $id: # $id = (split /\|/, $id)[0]; if (-f $id){ # this is a lie.. print $id." Already exists, about to override it","\n" } # .. because you are going to append, not to + overwrite open my $out_fh, '>>', "$id.fa" or die $!; # here parens are unneeded and probably nasty print $out_fh (">".$id."\n",$id2seq{$id}, "\n");
L*
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: An overlapping regex capture
by Peter Keystrokes (Beadle) on Jun 22, 2017 at 11:52 UTC | |
by poj (Abbot) on Jun 22, 2017 at 15:33 UTC | |
by 1nickt (Canon) on Jun 22, 2017 at 12:01 UTC | |
by Peter Keystrokes (Beadle) on Jun 22, 2017 at 18:17 UTC | |
by 1nickt (Canon) on Jun 22, 2017 at 21:24 UTC | |
Re^4: An overlapping regex capture
by Peter Keystrokes (Beadle) on Jun 21, 2017 at 21:11 UTC | |
by Discipulus (Canon) on Jun 21, 2017 at 21:21 UTC | |
Re^4: An overlapping regex capture
by Peter Keystrokes (Beadle) on Jun 22, 2017 at 09:54 UTC | |
Re^4: An overlapping regex capture
by Peter Keystrokes (Beadle) on Jun 21, 2017 at 21:47 UTC | |
by 1nickt (Canon) on Jun 21, 2017 at 22:11 UTC | |
by hexcoder (Curate) on Jun 22, 2017 at 11:22 UTC | |
by haukex (Archbishop) on Jun 22, 2017 at 12:40 UTC |