mercredi 24 juillet 2019

Find pattern mulifasta list based on user input in Perl

I am trying to fix a Perl code. Given the following "file.txt":

>otu1  
AACGCCTTTCCNGGATGGCAAAATTTNTNGTAAA
AGGGCACCCANTTCTGGCTCGAAA  
>otu2
NNAATCGGNNNGGGGCGTAANGAGGTTNCGGCACGG
TNCCCGTTTANCG
>otu3   
CTGGNATAAAAAANNNNTACTTAA

After providing a otu number as argument (i.e. otu2) when calling the program, I want to first (1) check if that otu is present in the file.txt, then (2) find motifs matching with the pattern [NC].[CT] (element N or C, followed by any element . and followed by an element C or T), and finally (3) print out the start‐ and end‐position of every site.

For the first two questions I am trying with the following code but I am encountering problems by integrating subroutines.


#!/usr/bin/perl -w

use warnings;
use strict;

$otu = $ARGV[0];   
check_otu("file.txt");

sub check_otu {
    my $content = shift;
    open(my $fh, '<' , $filename) || die "File not found: $!";
    my $content;    

    while( my $line = <$fh> ) {
        if ( $line =~ /^>/ ) {
            check_pattern($content) if $content=$otu;
            $content = $line;
        }
        else {
            $content .= $line;
        }
    }
    check_motifs($content);
}

}
sub check_pattern{
    my $fasta = $content;
    $count++ if count_pattern($fasta);
}
sub count_pattern {
    my $chain = $content;
    my @all = $chain =~ /([NC].[CT])/g;
    scalar @all;
}

Would you have any suggestion? Any hint for the third question? Thanks for your help

Aucun commentaire:

Enregistrer un commentaire