#!usr/bin/perl use strict; use warnings; if (! @ARGV) { print < basecount.pl HELP exit; } 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; ++$counts{$_} for grep {/\S/} split '', $line; } my $bases; my $errors; $bases += $_ for @counts{@baseList}; $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; # 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. my $DNA=join('',@ARGV); my $motif=''; do { print "\n\nEnter a motif to count its number and lengths between motifs:\n";# $motif = ; chomp $motif; # Look for the motif if ( $DNA=~ / $motif/ ) { print "I found the motif!\n\n"; } else { print"I couldn\'t find it.\n\n"; } # Count number of motifs and Count number of nt between two motifs use 5.010; my $string ="@ARGV"; # Remove whitespace $string=~ s/\s//g; my $count= () =$string=~ /$motif/g; print "Number of motifs: $count.\n\n"; say "The inter-motif nt Lengths are:\n"; say length for split/$motif/,$string; my @a=map length,split/$motif/,$string; # Output to a text page my $output="result .txt"; unless (open(RESULT,"> $output")){ print"Cannot open file\"$output\".\n\n"; exit; } 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); } until (my $motif =~ /^\s*$/ ); exit;