#!usr/bin/perl use strict; use warnings; if (! @ARGV) { print < basecount.pl HELP exit; } # Line 10 open my $dnaIn, '<', $ARGV[0] or die "Can't open bases file $ARGV[0]: +$!\n"; my %counts; my @baseList = qw(A T G C); while (defined (my $line = <$dnaIn>)) { chomp $line; # Line 15 ++$counts{$_} for grep {/\S/} split '', $line; } my $bases; my $errors; $bases += $_ for @counts{@baseList}; # Line 20 $errors += $_ for map {$counts{$_}} grep {! /[ATGC]/} keys %counts; print "\n\n Total bases: $bases\n\n"; print join (', ', map {"$_= $counts{$_}"} @baseList), "\n"; print "Errors (N)= $errors\n" if $errors; # Line 24 # In a loop, ask the user for a motif, search for the motif, and report if it was found.Exit if no motif is entered.Line 25 my $DNA=join('',@ARGV); my $motif=''; # Line 26 do { print "\n\nEnter a motif to count its number and lengths between motifs:\n";# Line 28 $motif = ;# Line 29 # Remove the newline at the end of $motif chomp $motif; # Look for the motif Line 32 if ( $DNA=~ / $motif/ ) { print "I found the motif!\n\n"; # Line 34 } else { print"I couldn\'t find it.\n\n"; } #Line 37 # Count number of motifs and Count number of nt between two motifs use 5.010; # Line 39 my $string ="@ARGV"; # Remove whitespace Line 41 $string=~ s/\s//g; my $count= () =$string=~ /$motif/g; # Line 43 print "Number of motifs: $count.\n\n"; say "The inter-motif nt Lengths are:\n"; # Line 45 say length for split/$motif/,$string; my @a=map length,split/$motif/,$string; # exit on an empty user input Line 48 my $output="result .txt"; unless (open(RESULT,"> $output")){ print"Cannot open file\"$output\".\n\n";# Line 51 exit; } # Line 53 print RESULT"\n\n Number of bases: $bases. Errors(N)=$errors.\n Motif: $motif. Number of motifs: $count.\n\n The inter-motif nt Lengths are:\n\n @a"; close(RESULT);# Line 56 } until (my $motif =~ /^\s*$/ );# Line 58 exit;