By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,542 Members | 1,434 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,542 IT Pros & Developers. It's quick & easy.

need help with extract info using regular expression from input line

P: 3
I want to extract some info from the following input line using perl regular expression. I will appreciate any help in doing so.

input line:
hg19_ensGene_ENST00000237247 range=chr1:67208779-67210057 5'pad=0 3'pad=0 strand=+ repeatMasking=none

info to be extracted:
chr1:67208779-67210057:+

The perl code i use till now that works successfully is:
Expand|Select|Wrap|Line Numbers
  1. while(<LOC>){
  2.         chomp;
  3.      if(/^>(\w+)\s\w+\=(chr\w+)\:(\d+)\-(\d+)/)    
  4.                $loc{$1} = "$2:$3:$4:$5"; 
  5.         print $loc{$1}."\n";
  6.         }
  7. }
  8.  
extracts the following info:chr1:67208779-67210057
however i am unable to extract + info from the input line above.
Mar 18 '10 #1
Share this Question
Share on Google+
3 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
The reason you aren't extracting the "+" is because you aren't telling it to. The "+" seems to be after "strand=" and I don't see you matching that anywhere. You may want to rework your regex a bit.

Regards,

Jeff
Mar 19 '10 #2

Expert Mod 100+
P: 589
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Data::Dumper;
  6.  
  7. my $str = "hg19_ensGene_ENST00000237247 range=chr1:67208779-67210057 5'pad=0 3'pad=0 strand=+ repeatMasking=none";
  8. my ($range, $strand) = (split /[\s=]/, $str)[2,8];
  9. print Dumper ($range, $strand);
Mar 19 '10 #3

P: 3
Expand|Select|Wrap|Line Numbers
  1.  
  2. my $var="hg19_ensGene_ENST00000237247 range=chr1:67208779-67210057 5'pad=0 3'pad=0 strand=+ repeatMasking=none";
  3. if($var=~/.*(chr1(:)[0-9-]+).*(\+) .*/)
  4. {
  5.     print "$1$2$3";
  6. }
  7.  
Mar 20 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.