8/foxp2.pl
#!/usr/bin/perl -w
use strict;
# 1 # Read sequences and store them in a hash
open(IN, 'foxp2.fasta') or die "Could not open file\n";
my %nonhuman;
my $id = undef;
my $seq;
my $id_human;
my $humanseq;
while (<IN>) {
chomp;
if (/^>/) {
if ($id) {
if ( $id !~ /HUMAN/ ) {
$nonhuman{$id} = $seq;
}
else {
$humanseq = $seq;
$id_human = $id;
}
}
$id = $_;
$id =~ s/>//;
$seq = '';
}
else {
$seq .= $_;
}
}
$nonhuman{$id} = $seq; # this assumes that we know that the
# final sequence read is non human
close IN;
# 2 # Analyze the multiple alignment
for ( my $i = 0 ; $i < length($humanseq) ; $i++ ) {
my $unique = 1;
foreach my $key ( keys %nonhuman ) {
# check if the amino acid in the human sequence
# is the same as in the non-human sequence
if ( substr( $humanseq, $i, 1 ) eq
substr( $nonhuman{$key}, $i, 1 ) ) {
$unique = 0;
}
}
if ($unique) {
my $pos = $i + 1;
print "At position $pos\n";
my $aa = substr( $humanseq, $i, 1 );
print "$id_human\t$aa\n";
foreach my $key ( keys %nonhuman ) {
my $aa = substr( $nonhuman{$key}, $i, 1 );
print "$key\t$aa\n";
}
}
}