Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • frenchcookie
    Junior Member
    • Dec 2012
    • 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

        • GATTACAT
          Reply to Nine Things a Sample Prep Scientist Thinks About Before Sequencing
          by GATTACAT
          Love this - good data definitely starts from good input, and poor input can only give relatively poor data. I particularly like the mention of Nanodrop/absorbance based methods for quantification. It's such a toss up if you'll get an accurate reading or what amounts to a randomly generated number, and a lot of library/sequencing related issues can be traced back to poor quant.
          07-01-2026, 11:43 AM
        • SEQadmin2
          Nine Things a Sample Prep Scientist Thinks About Before Sequencing
          by SEQadmin2


          I’m not a sequencing expert. I’m a purification scientist who uses NGS to evaluate workflows my group develops. With this perspective, we think about the sample first and the NGS workflow second. The sequencer is an exceptionally honest reporter, but it can only report on what you give it, so whether you get clean, interpretable data from an NGS workflow is largely determined before you begin.

          Here are nine questions we think about, in roughly the order they matter, before...
          06-18-2026, 07:11 AM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by SEQadmin2, Yesterday, 11:08 AM
        0 responses
        6 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 06-30-2026, 05:37 AM
        0 responses
        11 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 06-26-2026, 11:10 AM
        0 responses
        19 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 06-17-2026, 06:09 AM
        0 responses
        53 views
        0 reactions
        Last Post SEQadmin2  
        Working...