How to print out a part of the line?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Anja Friedrich

    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)
    Code:
     
    $pos= $pos + length($`)+1;
            $pos2= $pos + length($&)-1;
    	print OUTFILE "$_\t $pos\t $pos2\n";
    	$refseq= $';
            $temp=1;
            $found=$found+1;
    Cheers,
    Anja
    Last edited by Atli; Oct 21 '10, 04:43 PM. Reason: Fixed the [/code] tag.
  • toolic
    Recognized Expert New Member
    • Sep 2009
    • 70

    #2
    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:

    Code:
    use strict;
    use warnings;
    
    while (<DATA>) {
        my $motif = (split)[0];
        print "$motif\n";
    }
    
    __DATA__
    small_motif_a CGTCGCACAGC
    small_motif_b CGTCGCACGAC
    small_motif_c CGTCGCCCAGC
    This prints out:

    Code:
    small_motif_a
    small_motif_b
    small_motif_c
    I have no idea how you determine your position values. Can you elaborate?

    Comment

    • Anja Friedrich

      #3
      looks like my reply wasn't published
      your suggestion worked great thank you very much

      Comment

      Working...