Hi, I have a GenBank file and am extracting a gene upstream and downstream of a target gene, with everything in between (3 genes + 2 intergenic regions). I am loading the sequence in BioPerl and outputting the sequence to a file.
However, I want to make genes uppercase and intergenic regions lowercase. Is there an easy way to do this? Is there a clean BioPerl way?
sub extractSeq{
my($file,$start,$end,$settings)=@_;
my $targetSeq;
my $seqin=Bio::SeqIO->new(-file=>$file);
if($$settings{contig}){
while(my $seq=$seqin->next_seq){
if($seq->id eq $$settings{contig}){
$targetSeq=$seq;
last;
}
}
} else {
$targetSeq=$seqin->next_seq;
}
my $sequence=$targetSeq->subseq($start,$end);
my $genomeName=basename($file,qw(.gbk .gbk.fna));
my $extractedSeq=Bio::Seq->new(-id=>join("_",$genomeName,$$settings{contig},$start,$end),-seq=>$sequence);
$extractedSeq=$extractedSeq->revcom if($$settings{revcom});
return $extractedSeq;
}
1 answer
sub highlightFeatures{ my($seq,$settings)=@_; my $highlight=$$settings{highlight_type}||"uc"; # TODO return false if not a rich seq for my $feat($seq->get_SeqFeatures){ next if($feat->primary_tag eq 'source'); my($start,$end)=($feat->location->start,$feat->location->end); if($highlight eq 'uc'){ my $firstPartOfTheSequence=($start>1)?$seq->subseq(1,$start-1):""; my $lastPartOfTheSequence=($end<$seq->length)?$seq->subseq($end+1,$seq->length):""; my $sequence=$firstPartOfTheSequence.uc($seq->subseq($start,$end)).$lastPartOfTheSequence; $seq->seq($sequence); } } }
Log in to answer this question.