From 848db9d74f8540c13ce136761aaac5bd54ae2f32 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 20 Oct 2012 05:53:42 -0500 Subject: another solution --- GC.pl | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 GC.pl diff --git a/GC.pl b/GC.pl new file mode 100644 index 0000000..b25fdb6 --- /dev/null +++ b/GC.pl @@ -0,0 +1,44 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.016; + +sub calculate_gc { + my ($dna) = @_; + return(($dna =~ tr/GC/GC/) / length($dna)); +} + +my ($max_name, $max_gc); +sub process_string { + my ($name, $dna) = @_; + if ($max_name) { + my $gc = calculate_gc($dna); + if ($gc > $max_gc) { + $max_name = $name; + $max_gc = $gc; + } + } + else { + $max_name = $name; + $max_gc = calculate_gc($dna); + } +} + +{ + my ($name, $dna); + while (<>) { + chomp; + if (/^>(.*)/) { + process_string($name, $dna) if $name; + $name = $1; + $dna = ''; + } + else { + $dna .= $_; + } + } + process_string($name, $dna); +} + +say $max_name; +say $max_gc * 100 . '%'; -- cgit v1.2.3