Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • frenchcookie
    Junior Member
    • Dec 2012
    • 1

    #1

    [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.
  • Apexy
    Member
    • Apr 2011
    • 62

    #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

    • Jetse
      Member
      • Nov 2012
      • 38

      #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

      • Apexy
        Member
        • Apr 2011
        • 62

        #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

        • SEQadmin2
          New Genomics Technologies Take Aim at Long-Standing Limits
          by SEQadmin2


          Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

          We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
          ...
          Yesterday, 10:25 AM
        • SEQadmin2
          How Immunogenomics Decodes Immunity’s Genetic Blueprint
          by SEQadmin2




          The immune system’s power comes from its genetic diversity, allowing myriad threats to be neutralized through first recognizing foreign antigens. That diversity is also what makes the immune system so difficult to study. Recent advances in sequencing technology and computational biology, however, are giving researchers new tools to understand immune responses and immune-related diseases in greater detail.

          This convergence of genetics, immunology, and computation...
          09-01-2026, 05:41 AM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by SEQadmin2, Today, 09:51 AM
        0 responses
        9 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 09-25-2026, 09:06 AM
        0 responses
        32 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 09-23-2026, 11:05 AM
        0 responses
        27 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 09-18-2026, 11:37 AM
        1 response
        48 views
        0 reactions
        Last Post pekgio
        by pekgio
         
        Working...