471,893 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,893 software developers and data experts.

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
  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;    
Oct 21 '10 #1
2 2341
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;
  4. while (<DATA>) {
  5.     my $motif = (split)[0];
  6.     print "$motif\n";
  7. }
  9. __DATA__
  10. small_motif_a CGTCGCACAGC
  11. small_motif_b CGTCGCACGAC
  12. small_motif_c CGTCGCCCAGC
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 YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.