Exercise 5.5D
Return to Week 2
Exercise 5.3 in Beginning Perl for Bioinformatics
#!/usr/bin/perl -w
use strict;
#Damian Almiron
#Ex5-5
#Pseudocode:
#write a program that reports the percentage of hydrophobic amino acids
#in a protein sequence obtain from a file.
#my variables (do we always have to make var equal to zero? If not always,when
my @protein_original = 0;
my $protein_joint = 0;
my $count_hydrophobic = 0;
my $count_other = 0;
my $percentage_hydrophobic = 0;
#Open file.
open(PROTEINFILE)
@protein_original = <PROTEINFILE>;
close PROTEINFILE;
$protein_joint = join( '', @protein_string);
#Removing whitespace
$protein_sequence =~ s/\s//g;
#Determine if each AA is hydrophobic or not (go over this code)
while ($protein_sequence =~ /V/ig) {$count_hydrophobic++}
while ($protein_sequence =~ /I/ig) {$count_hydrophobic++}
while ($protein_sequence =~ /L/ig) {$count_hydrophobic++}
while ($protein_sequence =~ /A/ig) {$count_hydrophobic++}
while ($protein_sequence =~ /[^VILA]/ig) {$count_other++}
#Calculate % hydrophobic aa (review code)
# $rounded = sprintf("%.3f", $number);
$percentage_hydrophobic = sprintf("%.1f",$count_hydrophobic/$count_other*100);
#Print results
print "The follwing percentage is hydrophobic:$percentage_hydrophobic.\n";
exit;