Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Trying to get intergenic sequences using BioPerl

by biohisham (Priest)
on Jul 27, 2015 at 14:12 UTC ( #1136463=note: print w/replies, xml ) Need Help??

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

Replies are listed 'Best First'.
Re^2: Trying to get intergenic sequences using BioPerl
by Sosi (Sexton) on Jul 27, 2015 at 16:43 UTC

    Thank you very much! Yes, I read somewhere that many people criticize gbff for this sort of thing, so I started playing around with the .gff. However, the next question that raises is: in the case of organisms with multiple chromosomes/plasmids, how do you then get the subseqs out of the gbff (once you have the coordinates from the gff) by pointing for a specific chromosome? I will now look into your code and see how it goes, I hope I can convert it to regular script! Thank you very much!

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

    Yes, it was retrieving "CDS", "rRNA" and "tRNA". Which is strange because then I can find some "Source" within "@two"

      I am not sure I can answer your question without context except through an educated guess. What species are your working with ? The subseq coordinates in the gff file should ideally have been assigned as an offset from the start of the sequence file to where they are regardless of their chromosomal position. Another possibility is that the gff files for each chromosome have been generated individually. In the first case using the coordinates can get you the region corresponding to the chromosome without needing to worry about chromosomal location. In the second scenario extracting the subsequence will be as simple as accessing the right chromosomal gff file.

      Something or the other, a monk since 2009

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1136463]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2021-10-22 21:27 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (85 votes). Check out past polls.