Question: (Closed) Finding The Count And Location Of Two Substring In Two Different File Present In The Same Location.
0
gravatar for Jamis
8.5 years ago by
Jamis40
Jamis40 wrote:

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;
perl homework • 1.6k views
ADD COMMENTlink modified 8.4 years ago by Daniel Swan13k • written 8.5 years ago by Jamis40
6

I think we should be refusing to answer these homework questions!

ADD REPLYlink written 8.5 years ago by Casbon3.2k
3

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.

ADD REPLYlink written 8.5 years ago by Michael Dondrup46k
1

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.

ADD REPLYlink written 8.5 years ago by Giovanni M Dall'Olio26k
4
gravatar for Michael Dondrup
8.5 years ago by
Bergen, Norway
Michael Dondrup46k wrote:

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!

ADD COMMENTlink written 8.5 years ago by Michael Dondrup46k
2
gravatar for Daniel Swan
8.5 years ago by
Daniel Swan13k
Aberdeen, UK
Daniel Swan13k wrote:

This was also asked (and answered) on StackOverflow

ADD COMMENTlink written 8.5 years ago by Daniel Swan13k
1

Preferred your answer anyway :)

ADD REPLYlink written 8.5 years ago by Daniel Swan13k

fy faen, how I could waste my time with this nonsense....

ADD REPLYlink written 8.5 years ago by Michael Dondrup46k
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1109 users visited in the last hour