Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Complement command help

Status
Not open for further replies.

tsbatth

Programmer
Mar 5, 2008
7
US
Hey I wrote the following program that checks for a dna sequence (letters ATGC only), it converts all lower atgc to uppercase and checks to see if its only dna sequence, if it is not dna sequence it terminates, however it says that to all sequences I write, even if I input correct dna sequence, here is the code can anyone help?



print "Enter the DNA Sequence: ";
$DNA = <stdin>;
$DNA = chomp($DNA);
$DNA =~ tr/atgc/ATGC/;
$DNA2=$DNA;
$nbad=($DNA2 =~ tr/ATGC//c);
if ($nbad != 0)
{
die "Your DNA contains non-DNA sequence, please recheck your sequence \n";
}
 
$DNA = chomp($DNA);
should just be
chomp($DNA);

Also, please "use strict".
If your just trying to capitalize change
$DNA =~ tr/atgc/ATGC/;
to
$DNA = uc($DNA);


If your just looking for ATGC in a row do this
if ($DNA !~ /^ATGC$/) {
die "Your DNA contains non-DNA sequence, please recheck your sequence \n";
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Travis is absolutely right about chomp, you'll probably want to take a look at the documentation for that function.
perldoc -f chomp said:
This safer version of "chop" removes any trailing string that corresponds to the current value of $/ (also known as $INPUT_RECORD_SEPARATOR in the "English" module). It returns the total number of characters removed from all its arguments.
In the original code, after [blue]$DNA = chomp($DNA);[/blue] $DNA would probably have the value 1 instead of the input from the command line.

Also, if I understand the problem correctly, the regex needs to be changed just a bit:
Code:
if ($DNA !~ /^[ACGT]+$/) {
	print "Your DNA contains non-DNA sequence, please recheck your sequence.\n";
} else {
	print "Looks good!\n";
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top