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
          Beyond CRISPR/Cas9: Understand, Choose, and Use the Right Genome Editing Tool
          by SEQadmin2



          CRISPR/Cas9 sparked the gene editing revolution for both research and therapeutics.1 But this system still showed severe issues that limited its applications. The most prominent were the heavy reliance on PAM sequences, delivery limitations, double-stranded breaks that prompt unintended edits and cell death, and editing inefficiency (both in targeting and in knock-in reliability).

          Despite this, “CRISPR helped turn genome editing from a specialized technique into
          ...
          07-31-2026, 11:01 AM
        • SEQadmin2
          Proteomic Platforms: How to Choose the Right Analytical Strategy to Improve Detection and Clinical Applications
          by SEQadmin2


          Proteomics platforms are evolving rapidly, with advances in mass spectrometry and affinity-based approaches expanding what researchers can detect and at what scale. As the field moves toward deeper proteome coverage and clinical applications, scientists face an increasingly complex landscape of tools. This article will explore how researchers are navigating these choices to find the right platform for their work.

          The systematic characterization of the human proteome has
          ...
          07-20-2026, 11:48 AM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by SEQadmin2, Yesterday, 12:22 PM
        0 responses
        12 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 08-11-2026, 10:35 AM
        0 responses
        13 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 08-06-2026, 07:41 AM
        0 responses
        30 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 08-03-2026, 10:13 AM
        0 responses
        48 views
        0 reactions
        Last Post SEQadmin2  
        Working...