#!/usr/bin/perl -w ## Determining frequency of nucleotides # Get the name of the file with the DNA sequence data print "Please type the pattern: "; #$pattern = "l{2}|[U{2}A] s{6}|(A) l*| ~s{6}|."; #; $pattern = " s+|(A) l+|(AA) ~s+"; print "Please type the filename of the DNA sequence data: "; $dna_filename = "rna";#; # Remove the newline from the DNA filename chomp $dna_filename; # open the file, or exit unless ( open(DNAFILE, $dna_filename) ) { print "Cannot open file \"$dna_filename\"\n\n"; exit; } # Read the DNA sequence data from the file, and store it # into the array variable @DNA @DNA = ; # Close the file close DNAFILE; # From the lines of the DNA file, # put the DNA sequence data into a single string. $DNA = join( '', @DNA); # Remove whitespace $DNA =~ s/\s//g; open (FOLD, "echo \"$DNA\"\| RNAfold -noLP|") ; $pattern =~ s/\~s/\)/gi; $pattern =~ s/l/\./g; $pattern =~ s/s/\(/gi; print "Pattern".$pattern."\n"; @pattern = split(" ", $pattern) ; $secregexp=""; for ( $i=0 ; $i <= $#pattern;$i++){ $pattern[$i] .= "|" if($pattern[$i] !~ /\|/); print("P A T T E R N: ".$pattern[$i]."\n"); $pattern[$i] =~ /(.*?)\|(.*)/; $secregexp .="(\\$1?)"; # if($pattern[$i] !~ /\|$/) {$pattern[$i] =".*" } else{$pattern[$i]= $2 } $pattern[$i]= ($2?$2:".*") ;print $1."secregexp $secregexp \n var2---pattern i $pattern[$i] \n"; } $pri=""; $it=0; $sec=""; while () { $_ =~ /(\S*)/; print $1." $pattern\n"; if($it == 0 ){ $pri=$1;} else{ $sec= $1; while () { $_ =~ /(\S*)/; print $1." $pattern\n"; if($it == 0 ){ $pri=$1;} else{ $sec= $1; while( $sec =~ /$secregexp/ig ) { print "P O S: $@".pos()."\n"; for($i=1; $i<=$#pattern+1; $i++) { print ($-[$i]."<___>".$+[$i]."matched:".$$i); $str = substr($pri, $-[$i], $+[$i] - $-[$i]+1 ); print "$secregexp str: $str patt: $pattern[$i-1]\n"; if( $str !~ /$pattern[$i-1]/){ print " no t f o u n d\n"; last; #redo; }else{print "ok\n";} if($#pattern==$i-1){ print "f o u n d\n"; $last_pos = $+[$i]; } } } } $it++; } close FOLD;