in reply to Trying to get intergenic sequences using BioPerl

What is the relevance of my @two = shift @features;?. Since shift shortens @features by one through removing the first element held therein you might end mis-assigning feature tags to variables since you can't be sure that all features in a genbank file are consistent for every annotation.

Have you printed out the value of $pt to verify that it is either "CDS" , "rRNA" or "tRNA" ?

Within the same if block you're pushing into and shifting out of @two inside the foreach loop. A practice that can make it harder for you to track current elements within @two

If we define intergenic regions as any region upstream of the next gene and downstream of the first gene and since genes can be in the forward or the backward strands; right next to each other spaced apart by a random number of nucleotides then extracting the intergenic region might be very tricky since you have to consider the orientation of the genes flanking the region and their start and end (start>end for forward strand genes and start<end for backward strand)

From my experience, dealing with Genbank or any other format besides gff is suboptimal due to inconsistent and erroneous annotations. However, try with the  -i flag. Be very vigilant for inconsistencies in extracted regions and consider that the output of FeatureExtract might need further cleaning up.

My approach is to parse a GFF file myself and get the coordinates for the features I want to extract then use sfetch to extract the sequences from the corresponding genbank file by passing these coordinates for the features (genes, CDs, RNA, tRNA ..etc). The sfetch utility appropriately takes care of the orientation for you in that if you pass it a "from" position that is larger than a "to" position then it'd extract and reverse translate the negative strand.

In the case of intergenic regions this can simply be reading between the lines of the gff file. I am passing you my one-liners for this activity which you could modify to your content. I put appropriate comments there to get you started.

#Given a gff file and embl file for a genome extract the upstream sequ +ences that correspond to intergenic regions #STEP1: Parse a GFF file to get upstream regions #The idea is to create a hash using the line numbers as keys (line num +bers correspond to genes), upstream regions for positive #strand genes are enclosed between $F[3] of the current line and $F[4] + of the PREVIOUS line. Upstream regions for negative #strand genes are enclosed between $F[4] of the current line and $F[3] + of the SUBSEQUENT line. #if the first gene record was on the positive strand then the upstream + region is counted from 1 upto $F[3]. cat file.gff | perl -F'\t' -lane 'push @{$hash{$.}}, @F }{ @record_lin +e_numbers= sort {$a<=>$b} keys %hash; foreach $element (@record_line_ +numbers){if($element ==1 && @{$hash{$element}}[6] eq "+" ){print "$el +ement\t1\t@{$hash{$element}}[3]\t@{$hash{$element}}[6] "}elsif(@{$has +h{$element}}[6] eq "+"){$prev_line=$element-1;print "$element\t@{$has +h{$prev_line}}[4]\t@{$hash{$element}}[3]\t@{$hash{$element}}[6]" }els +if(@{$hash{$element}}[6] eq "-" ){$next_line=$element+1; print "$elem +ent\t@{$hash{$element}}[4]\t@{$hash{$next_line}}[3]\t@{$hash{$element +}}[6]" } } ' | perl -F'\t' -lane 'next if(($F[2] - $F[1]) < 10); +print' > file.upstream.coord.txt #extract sequences 200 nts upstream upto 5 nts after the start codon t +hrough sfetch cat file.upstream.coord.txt | perl -F'\t' -lane '$length=$F[2]-$F[1]; +if($length>200 && $F[3] eq "+"){$from=$F[2]-200;$to=$F[2]+7; $name = +join("_",$F[0],$from,$to,$F[3]); print "sfetch -d bacteria.embl -F \" +fasta\" -f $from -t $to -r \"$name\" ." }elsif($length < 200 && $F[3] + eq "+"){$from=$F[1];$to=$F[2]+7; $name=join("_", $F[0],$from,$to, $F +[3]); print "sfetch -d bacteria.embl -F \"fasta\" -f $from -t $to -r +\"$name\" ." }elsif($length > 200 && $F[3] eq "-"){$from=$F[1]+200; $ +to=$F[1]-7; $name =join("_", $F[0],$from,$to, $F[3]); print "sfetch - +d bacteria.embl -F \"fasta\" -f $from -t $to -r \"$name\" ." }elsif($ +length <200 && $F[3] eq "-"){$from=$F[2];$to=$F[1]-7;$name=join("_", +$F[0],$from,$to, $F[3]); print "bacteria.embl -F \"fasta\" -f $from - +t $to -r \"$name\" ."} ' | sh > file.upstream.fa

Something or the other, a monk since 2009