Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • perl script to generate six frame sequences

    Hi everyone
    I wrote a script to generate siz frame sequences (+1 +2 +3 -1 -2 -3 frames). However, it only works on frames +1 +2 +3 -1. For example the following is -3 frame sequence generation. Where is wrong? Note after the script i make an output example. Thank you very much!

    Code:
    #!/bin/perl
    use strict;
    use warnings;
    
    my $frame = -3;  #when changing to -1 output sequences are ok; but -2 or -3 does not work;
    open IN, $ARGV[0];
    
    while (<IN>){
    	chomp;
    	my $m = length ($_);
    	
    	if(/^>(\w+)/){
    	 print ">$1"."_"."frame"."$frame"."\n";
    	 }else{
    		my $comprevseq = reverse $_;
    		$comprevseq =~ tr/[A,T,C,G]/[T,A,G,C]/; 
    		my $frameseq = substr ($comprevseq, abs($frame)-1, $m-abs($frame)+1);
    		
    		print "$frameseq\n";
    	}
    }
    close IN;
    INPUT file
    Code:
    >seq1
    ATGC
    >seq2
    ATGC
    >seq3
    TTTT
    OUTPUT result
    Code:
    >seq1_frame-3
    CAT
    >seq2_frame-3
    CAT
    >seq3_frame-3
    AA

  • #2
    This gives the correct answer (and is pretty much your code without the reading in the lines):
    #!/bin/perl

    my $frame = -3;
    $s = "ATGC";

    my $m = length ($s);


    my $comprevseq = reverse $s;
    $comprevseq =~ tr/[A,T,C,G]/[T,A,G,C]/;
    my $frameseq = substr ($comprevseq, abs($frame)-1, $m-abs($frame)+1);

    print "$frameseq\n";

    exit(0);
    output:
    AT
    The fact that the last input in your example works points to the problem being the linefeeds. You do chomp the input. But if the input has windows-type carriage returns and linefeeds there will be an extra invisible character. You can:
    local $/ = "\r\n";

    so that chomp removes both characters.
    Providing nextRAD genotyping and PacBio sequencing services. http://snpsaurus.com

    Comment


    • #3
      Thank you very much, SNPsaurus. You comment is really helpful!

      Comment

      Latest Articles

      Collapse

      • seqadmin
        Essential Discoveries and Tools in Epitranscriptomics
        by seqadmin




        The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist...
        04-22-2024, 07:01 AM
      • seqadmin
        Current Approaches to Protein Sequencing
        by seqadmin


        Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
        04-04-2024, 04:25 PM

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by seqadmin, Yesterday, 08:47 AM
      0 responses
      12 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 04-11-2024, 12:08 PM
      0 responses
      60 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 04-10-2024, 10:19 PM
      0 responses
      60 views
      0 likes
      Last Post seqadmin  
      Started by seqadmin, 04-10-2024, 09:21 AM
      0 responses
      54 views
      0 likes
      Last Post seqadmin  
      Working...
      X