Dear monks,

I've written perl codes below. My wish that this code should give output : how many times each motif match with the sequences ($dna), but $regexp (variable contain multiple motifs) only read the last motif instead of 11 motifs (in subroutine its give 11 motifs, but when I call the function its give only 1 motif). Please help me what's wrong with my scripts. Thanks in advance.

use strict; use warnings; my @file_data = (); my %motif_hash = (); my $dna; my $regexp; my @positions = (); my $site; my @motifs; my $match; my $count; @file_data = get_file_data("promoters.txt"); $dna = extract_sequence(@file_data); $regexp = parseMOTIF('motifs.txt'); print "Regexp: '$regexp'\n"; $match = match_positions($count); push(@positions,$match); print "match : $match"; sub match_positions{ my($regexp,$dna) = @_; my $count= 0; my @positions; my $regexp; my $dna; while ($dna =~ /$regexp/g){ push(@positions,pos($dna)-length($&)+1); ++$count; } return $count; } sub parseMOTIF { use strict; use warnings; my @motiffile = (); my $name; my $site; my $regexp; my %motif_hash = (); my $motiffile = $_[0]; @motiffile = get_file_data($motiffile); foreach $motiffile(@motiffile){ if($motiffile =~ /(^[A|S]\d+\s+|^[A|S]\d+b\s+)([A-Z]+)(\s+.*)$ +/){ my $name = $1; my $site = $2; $regexp = IUB_to_regexp($site); $motif_hash{$name} = "$site $regexp\n"; print "motif : $site\n"; print "The regexp : $regexp\n"; } } return $regexp; } sub get_file_data{ my ($filename)=@_; use strict; use warnings; my @filedata=(); unless(open(GET_FILE_DATA, $filename)){ print STDERR "can't open file $filename\"\n\n"; exit; } @filedata = <GET_FILE_DATA>; close GET_FILE_DATA; return @filedata; } sub extract_sequence { use strict; my (@file_data) = @_; use warnings; my $sequence = ""; foreach my $line(@file_data) { if ($line =~ /^>/){ next; } else { $sequence .= $line; } } #$sequence =~ s/\s//g; return $sequence; } sub IUB_to_regexp{ my($iub) = @_; my $regular_expression =""; my %iub2char_class = ( A =>'A', C =>'C', G =>'G', T =>'T', R =>'GA', Y =>'CT', M =>'AC', K =>'GT', S =>'GC', W =>'AT', B =>'CGT', D =>'AGT', H =>'ACT', V =>'ACG', N =>'ACGT', ); for (my $i=0;$i<length($iub);$i++){ $regular_expression .= $iub2char_class{substr($iub,$i,1)}; } return $regular_expression; }

In reply to codes error :( by Bio_student

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.