fy faen, how I could waste my time with this nonsense....
From a given two sequences i need to check for every three codons and if the changes are same as in the following list, then i ve to check out the location of changes and the codons which are changed and count their number of occurences.
For eg:
seq1- TTCAUUUCCCAU
seq2- TTTAUAUCGCAC
so, the output which i need to get is:
TTC->TTT considered / location-1 / count-1
AUU->AUA considered / location-2 / count-1
UCC->UCG considered / location-3 / count-1
NOTE:
CAU->CAC not considered because it is not there in the following list
LIST:-> The direction of changes should also be considered.
first sequence->second sequence
TTC->TTT
CTG->UUA
AUU->AUA
GUG->GUA
UCC->UCG
CCC->CCG
ACC->ACG
GCC->GCG
UAC->UAU
UGA->UAG
CAC->CAU
CAG->CAA
AAC->AAU
AAG->AAA
GAC->GAU
GAG->GAA
UGC->UGU
CGG->CGU
AGC->AGU
AGG->CGU
AGA->CGU
UAA->UAG
GGC->GGU
and the code which i ve written till now is :
#!/usr/bin/perl
print"Enter the sequence:";
$a=<>;
print"Enter the mutated sequence:";
$b=<>;
chomp($a);
chomp($b);
my @codon=split(/(\w{3})/,$a);
my @codon1=split(/(\w{3})/,$b);
open(OUT,">output.txt") or die;
$count=0;
@new=();
@new1=();
for($i=0;$i<=$#codon;$i++)
{
for($j=0;$j<=$#codon1;$j++)
{
if($codon[$i]={TTC}) || ($codon1[$j]={TTT})
{
$count++;
}
}
}
print OUT " @new";
close OUT;
2 answers
Try change:
if($codon[$i]={TTC}) || ($codon1[$j]={TTT})
to
if($codon[$i] eq "TTC") && ($codon1[$j] eq "TTT")
Remember string comparison is eq not ==. = is wrong
For easier lookup build a codon replacement table in a hash aka:
%codonAdaptation = ('TTCTTT' => 0,
'CTGUUA' => 0,
'AUUAUA' => 0,
'GUGGUA' => 0, ....)
Then you need only one loop and that line becomes very simple:
if (exists $codonAdaptation{$codon[$i].$codon1[$i]})
$codonAdaptation{$codon[$i].$codon1[$i]}++;
There you go!
This was also asked (and answered) on StackOverflow
Preferred your answer anyway :)
Log in to answer this question.
I think we should be refusing to answer these homework questions!
I agree with Casbon. If you want to get help here, you should demonstrate that you tried to solve the problem by yourself before posting.
I agree, but in this case the op at least showed some very crude attempt to do it herself. So if we not take them whole way but give some hints, the student has still enough to figure out.