Genbank To Fasta Conversion
2
0
Entering edit mode
11.7 years ago
shilpy ▴ 20

I am using the code below but not getting any output. Please let me know what is wrong here.

my $string = param("genBankSeq");
my $format = "genbank";

my $fastaSeq;


my $stringfh;
open($stringfh, "<", \$string) or die "Could not open string for reading: $!";   

my $seqio = Bio::SeqIO-> new(
                             -fh     => $stringfh,
                             -format => $format,
                             );

while( my $seq = $seqio->next_seq ) {
    # process each seq
    $fastaSeq = $seq->seq();
}
my $formattedFastaSeq = "";
my $fromStr = 0;
my $temp = "";

while($fromStr < length($fastaSeq)){

    $temp = substr($fastaSeq, $fromStr, 70);
    $formattedFastaSeq = $formattedFastaSeq.$temp."<br>";
    $fromStr = $fromStr + length($temp);
}


print $formattedFastaSeq;
bioperl • 5.0k views
ADD COMMENT
2
Entering edit mode
11.7 years ago
SES 8.6k

Your first issue is you don't have use strict; and use warnings; at the top of your script. Without those lines in your code you will always be guessing if things worked. When things don't work it can be tedious to find simple mistakes, but thankfully those pragmas take all the guesswork out of programming so you can focus on your task. In other words, always put those lines at the top of your scripts.

I recommend you take a look at the methods available on the SeqIO HOWTO page, and it particular the genbank example where that link points to. It looks like you are trying to filter sequences by length somehow, but I think you are making it more complicated than necessary. One suggestion I can offer would be to tell us what you are trying to do so you can get a more specific answer to your problem.

ADD COMMENT
0
Entering edit mode
11.7 years ago
Lee Katz ★ 3.2k

You didn't concatenate

$fastaSeq .= $seq->seq();
ADD COMMENT
0
Entering edit mode

Sorry.........didn't work

ADD REPLY
0
Entering edit mode

Also... if you don't really need bioperl, there are several tools that make this pretty easy. This is an Emboss example. You'd have to save the genbank to a file first though.

seqret -filter < file.gbk > file.gbk.fasta
ADD REPLY
0
Entering edit mode

Thanks I got my code working I m supposed to use only bioperl.

ADD REPLY
0
Entering edit mode

that great. But, if I need to get CDS proteins sequence also of genbank format into fasta?

ADD REPLY

Login before adding your answer.

Traffic: 2888 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6