I was writing a code to find out the exact positions of different variants of a motif in a sequence. Therefore I have two arrays. One with the sequence and one with the different variants of the motif (e.g. small_motif_a CGTCGCACAGC). The problem is my output is completely senseless as it gives me positions that does not even lay in my sequence, and it finds only one position. There must be something wrong with the search in the loop...
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/perl -w
- use strict;
- use Bio::Perl;
- # This script will find the exact location of motifs in a DNA sequence
- my $dnafilename;
- my $varfilename;
- my $refseq;
- my $pos;
- my $motif;
- my $refseqtemp;
- my @dna;
- my $dna;
- my @var;
- my $var;
- @var=();
- @dna=();
- print "Enter the filename of your input file with the sequence:= "; # File that contains your DNA sequence
- chomp ($dnafilename=<STDIN>);
- open(DNAINPUT,'<',$dnafilename) or die ("$dnafilename Can not open file\n");
- print "Enter the filename of your input file with the variants:= "; # File that contains your different variants
- chomp ($varfilename=<STDIN>);
- open (VARINPUT,'<',$varfilename) or die ("$varfilename Can not open file\n");
- @dna=<DNAINPUT>; # stores the sequence in an array
- # print @dna;
- while (<VARINPUT>)
- { # stores the variants in an array
- chomp;
- push @var, $_;
- }
- $refseq= $dna[0];
- chomp $refseq;
- $pos=0; # position of the first base
- my $temp;
- $temp=1;
- foreach my $thing (@var)
- {
- $motif=$thing;
- $refseqtemp = $refseq; #start for every motif with the whole sequence
- print "$motif\n";
- $motif =~ s/^\w*\s//;
- print "$motif\n";
- while(length($refseq)>0 && $temp>0) # as long as there is a rest sequence (>0)
- {
- $temp=0;
- my $length = length($refseq);
- print "length now $length\n";
- if ($refseq=~ /($motif)/ig) # search for the motif (variant)
- {
- print "found\n";
- $pos= $pos + length($')-1;
- print "pos $pos\n";
- $pos= $pos + length($&);
- $refseq= $';
- $dna=$dna+1;
- $temp=1;
- }
- else {
- print "Sorry, no match\n";
- }
- }
- }
Cheers,
Anja