Search for a FASTA file for a motive and return a title bar for each sequence containing a motive

Below is the code to search for the FASTA file entered on the command line for the bridge provided by the user. When I launched it and entered a motive, which, as I know, is in the file, it returns "Motive not found." I'm just new to Perl, and I can't figure out how to get it to print the found motive, not to mention returning the title bar. I would appreciate any help in resolving this.

Thank.

use warnings;
use strict;


my $motif;  
my $filename;  
my @seq;   
#my $motif_found;  
my $scalar;  

$filename = $ARGV[0];  

open (DNAFILE,$filename) || die "Cannot open file\n";
@seq = split(/[>]/, $filename);
print "Enter a motif to search for; ";

$motif = <STDIN>;  

chomp $motif;  
foreach $scalar(@seq) {  
    if ($scalar =~ m/$motif/ig) {
        print "Motif found in following sequences\n";  
        print $scalar;  
    } else {
        print "Motif was not found\n";  
    }  
}  
close DNAFILE;
+3
source share
2 answers

" " Fasta. BioPerl , , .

use strict;
use Bio::SeqIO;

my $usage = "perl dnamotif.pl <fasta file> <motif>";
my $fasta_filename = shift(@ARGV) or die("Usage: $usage $!");
my $motif = shift(@ARGV) or die("Usage: $usage $!");

my $fasta_parser = Bio::SeqIO->new(-file => $fasta_filename, -format => 'Fasta');
while(my $seq_obj = $fasta_parser->next_seq())
{
  printf("Searching sequence '%s'...", $seq_obj->id);
  if((my $pos = index($seq_obj->seq(), $motif)) != -1)
  {
    printf("motif found at position %d!\n", $pos + 1);
  }
  else
  {
    printf("motif not found.\n");
  }
}

(1 ) . , . . " ".:)

BioPerl, . , - .

, , BioStar .

+2

, .

@seq = split(/[>]/, $filename);

@seq = <DNAFILE>

( , - , split/[ > ]/: []).

+1

Source: https://habr.com/ru/post/1777917/


All Articles