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
          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, Today, 08:47 AM
        0 responses
        11 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
        59 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