Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • [PERL] Compare two sequences from fasta file

    Hello !

    I would like to compare sequences that I have in one file. The most important think to me is that I would like to compare them in columns, so first position form sequence A with first position in sequence B etc.

    Do you have any idea how to start?
    (of course I don't expect prepared code, but maybe someone do something like this and could help me start )

    This is how I start but it's give me error That file cannot be read.
    Code:
    my $end = $#a1 < $#a2 ? $#a1 : $#a2; 
     my $result = 0; 
     for (my $l=0; $l<=$end; $l++) { 
      $result++ if $a1[$l] eq $a2[$l];  
     } 
     
     my $A = (2 * $result) / ($#a1 + $#a2 + 2); 
     my $B = $result / ($end+1); 
     print "Similar = $result, A = $A, B = $B\n"; 
    } 
     
      
    my $file = 'seqs.txt';  
    open I, '<', $file 
    or die "Can't open '$file' for reading: $!\n"; 
      
    chop (%hash = map { split /\s*,\s*/,$_,2 } grep (!/^$/,<I>)); 
     
     
     
     print "$_$hash{$_}\n" for keys %hash; 
    open  
    open (IN, $ARGV[0]) || die "File not found $ARGV[0]: $!\n"; 
    chomp(my @in = <IN>); 
     
     
    map { 
      s/[^agtc]//ig; 
    } @in; 
     
     
    my $dna1 = read_file($ARGV[0]); 
    my $dna2 = read_file($ARGV[1]); 
    compare ($dna1, $dna2); 
     
    compare($in[0], $in[1]); 
    compare($in[1], $in[2]); 
    compare($in[2], $in[3]); 
     
    close (IN);
    Last edited by frenchcookie; 12-15-2012, 12:59 PM.

  • #2
    Hi Frenchcookie,

    Could ask your question with and example? Such as the nature of your files and what you want the output to look like. Such as it is with the case here

    HTH

    Comment


    • #3
      Do you mean something like this?
      Code:
      open( my $fh "filename.txt" )or die $!;
      my @lines = <FILE>;
      while ( <FILE> ) { print $_; 
        my @columns = split(separatorBetweenColumns,$_);
        my @splittedA = split('',$columns[0]);
        my @splittedB = split('',$columns[1]);
        for(my $i = 0; $i < @splittedA; $i++){
          if($splittedA[$i] eq $splittedB[$i]){
            #chars are equal...
          }
        }
      }
      close( $fh )
      didn't test it, but this is a way to do it...

      Comment


      • #4
        Hello,

        Without knowing what the inputs looks like, I will not know if the variables of your script is (scalar or string). If your files have columns, are they tab delimited? What should the script do if first position from sequence A matches with first position in sequence B? Simply put, the question is not clear to me.

        Comment

        Latest Articles

        Collapse

        • seqadmin
          Recent Advances in Sequencing Analysis Tools
          by seqadmin


          The sequencing world is rapidly changing due to declining costs, enhanced accuracies, and the advent of newer, cutting-edge instruments. Equally important to these developments are improvements in sequencing analysis, a process that converts vast amounts of raw data into a comprehensible and meaningful form. This complex task requires expertise and the right analysis tools. In this article, we highlight the progress and innovation in sequencing analysis by reviewing several of the...
          Yesterday, 07:48 AM
        • 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

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by seqadmin, Yesterday, 07:17 AM
        0 responses
        11 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 05-02-2024, 08:06 AM
        0 responses
        19 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 04-30-2024, 12:17 PM
        0 responses
        20 views
        0 likes
        Last Post seqadmin  
        Started by seqadmin, 04-29-2024, 10:49 AM
        0 responses
        28 views
        0 likes
        Last Post seqadmin  
        Working...
        X