SEQanswers

SEQanswers (http://seqanswers.com/forums/index.php)
-   Bioinformatics (http://seqanswers.com/forums/forumdisplay.php?f=18)
-   -   Generate consensus from MultiFasta (http://seqanswers.com/forums/showthread.php?t=35285)

Antony03 11-11-2013 12:59 PM

Generate consensus from MultiFasta
 
Hi,

I have a multifasta like:

>sequence1
ATCGATCATCG
>sequence2
ATCGATNNTCG
>sequence3
ATCGATCATCG

All sequences are the same, except there are some N. I want to make a consensus with the N if there are.

Do you know I can do this?
Thanks!

Antony03 11-13-2013 04:30 PM

A little up!

Please :)

gringer 11-13-2013 06:43 PM

here's my rough 5-minute attempt:
Code:

#!/usr/bin/perl
use warnings;
use strict;
my @sequence = ();
while(<>){
  if(!/^>/){
    chomp;
    my @bases = split(//,$_);
    for(my $i = 0; $i < @bases; $i++){
      if($bases[$i] eq "N"){
        $sequence[$i] = "N";
      } elsif($sequence[$i] ne "N") {
        $sequence[$i] = $bases[$i];
      }
    }
  }
}

print(">consensus\n".join("",@sequence)."\n");

[may not compile, will probably contain bugs, will probably be very slow]


All times are GMT -8. The time now is 09:24 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2020, vBulletin Solutions, Inc.