469,271 Members | 1,286 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

How to print out a part of the line?

Hi all,

I was wondering if it's possible to print out only a part of a line? The problem is I have an array with one motif in different variants, like this:
small_motif_a CGTCGCACAGC
small_motif_b CGTCGCACGAC
small_motif_c CGTCGCCCAGC
But in my output I only want the variant, without the nucleotide motif. Is that possible?
Like this: small_motif_a 811 821
(positions will be find by the script)
Expand|Select|Wrap|Line Numbers
  1.  
  2. $pos= $pos + length($`)+1;
  3.         $pos2= $pos + length($&)-1;
  4.     print OUTFILE "$_\t $pos\t $pos2\n";
  5.     $refseq= $';
  6.         $temp=1;
  7.         $found=$found+1;    
  8.  
Cheers,
Anja
Oct 21 '10 #1
2 2285
toolic
70 Expert
Yes, it is possible to only print part of a line, and there are various ways to do so. One way is to use split as follows:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4. while (<DATA>) {
  5.     my $motif = (split)[0];
  6.     print "$motif\n";
  7. }
  8.  
  9. __DATA__
  10. small_motif_a CGTCGCACAGC
  11. small_motif_b CGTCGCACGAC
  12. small_motif_c CGTCGCCCAGC
  13.  
This prints out:

Expand|Select|Wrap|Line Numbers
  1. small_motif_a
  2. small_motif_b
  3. small_motif_c
I have no idea how you determine your position values. Can you elaborate?
Oct 21 '10 #2
looks like my reply wasn't published
your suggestion worked great thank you very much
Oct 21 '10 #3

Post your reply

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

Similar topics

4 posts views Thread by robert.spam.me.senseless | last post: by
5 posts views Thread by Patrick De Ridder | last post: by
2 posts views Thread by Ryan Gregg | last post: by
4 posts views Thread by Rob T | last post: by
reply views Thread by melanieab | last post: by
6 posts views Thread by Ant | last post: by
7 posts views Thread by Digital Puer | last post: by
18 posts views Thread by Brett | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.