#!/usr/bin/perl-w # perl program to find motif in text file eith its positions. use strict; use Bio::SeqIO; open(my $outfile, ">", "Motif_Result.txt"); my $file = 'seq.txt'; print {$outfile}"\t\t\t\t\t Positions\n"; print {$outfile}"\tPattern Name\tSequence Name\tStart\tEnd\tLength of Sequence\n\n"; my $patternseq= 'pat.txt'; open(FIH, $patternseq); my $in; my %patsmap; my @residue; my @pats; my $seqcount = 0; while ($in=<FIH>) { chomp($in); my @pats=split " ",$in; my $residue=shift@pats; foreach my $nnn (@pats) # @pats = (AAAAA, TTTTT, GGGGG); { $patsmap{$nnn}=@residue; } print "Patterns\t"; print "@pats"; print "\n"; my $length = @pats; print "Total Patterns are: $length"; print "\n"; my $seqobj; my $in = Bio::SeqIO->new(-format => 'fasta', -file => $file); my $motif_count = 0; while ( my $seq = $in->next_seq) { $seqcount++; # count the number of sequences my $head = $seq->display_id(); my $str = $seq->seq; # get the sequence as a string $str =~ s/\*//g; # remove all '*' from sequence my $i; for ($i=0; $i<=$length; $i++) { while ( $str =~ m/(?=$pats$i)/ig) { my @l = split('', $str); my $length=@l; print {$outfile}"\t"; print {$outfile}$pats$i; printf {$outfile}"\t\t$head\t\t%d", pos($str)+1; printf {$outfile}"\t%d", pos($str)+5; print {$outfile}"\t"; print {$outfile}$length; print {$outfile}"\n"; } } } print {$outfile}"\n\tTotal Sequences in file name $file\t:$seqcount\n"; exit; }