You dont explain very well what you want. What do you mean by gene for instance

I think this does most of what you are after. but it is a memory hog.

use strict; use warnings; my @genes; my %genes_found; my $genesFn = "Genes_list.txt"; open my $genesFh, "<", $genesFn or die "could not open genes file hand +le $!\n"; while (my $gene=<$genesFh>) { chomp $gene; push @genes, $gene; } my $an_fn='annotation_files_path.txt'; open my $an,'<',$an_fn or die "cant open $an_fn $!"; while (my $annotationsFn =<$an>){ chomp $annotationsFn ; open my $gff,'<',$annotationsFn or die "cant open $annotationsFn $! +"; while (my $gff_line =<$gff>){ chomp $gff_line; for my $gene (@genes) { if (index($gff_line,$gene) != -1) { $genes_found{$gene}{$annotationsFn}=[] unless (defined ($genes +_found{$gene}{$annotationsFn})); push @{$genes_found{$gene}{$annotationsFn}},$gff_line; } # index } # gene } # gff_line close $gff; } # my $annotationsFn close $an; for my $gene (@genes) { unless ($genes_found{$gene}) { print "gene $gene not found \n";} else { my $resultsFn='result-gene-'.$gene.'.txt'; open my $resultsFh, ">", $resultsFn or die "could not open handle +to results file $!\n"; for my $annotationsFn (sort keys (%{$genes_found{$gene}})) { print $resultsFh 'from:'.$annotationsFn."\n"; for my $found (@{$genes_found{$gene}{$annotationsFn}}){ print $resultsFh 'line:'.$found."\n"; } # found } #$annotationsFn close $resultsFh; } # else } # gene


In reply to Re: perl script for extracting gene information from gff file by huck
in thread perl script for extracting gene information from gff file by Anonymous Monk

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.