Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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 FeatureExtract.py 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

In reply to Re: Trying to get intergenic sequences using BioPerl by biohisham
in thread Trying to get intergenic sequences using BioPerl by Sosi

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (5)
    As of 2020-07-06 17:57 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?