Perl: GenBank Handling (Accession Number) - by Eun Bae Kim (08/21/2018)
 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  
use strict;
use Bio::SeqIO;
use Bio::DB::GenBank;


# https://www.ncbi.nlm.nih.gov/nuccore/X13199.1/
# Reference: https://metacpan.org/pod/Bio::DB::GenBank

my $sAccNo = "X13199";
my $oDb = new Bio::DB::GenBank;       # DB ¿¬°áÇÒ Object »ý¼º


# my $oGbk = $oDb->get_Seq_by_acc("X13199"); # Accession Number
# my $oGbk = $oDb->get_Seq_by_version("X13199.1"); # Accession.version
# my $oGbk = $oDb->get_Seq_by_gi('405830'); # GI Number

# For Primary Tags
print "--------------------------------------------\n";
if(my $oGbk = $oDb->get_Seq_by_acc($sAccNo)) {               # Get Information by Accession Number
	foreach my $oFeat ($oGbk->top_SeqFeatures()) {
		print $oFeat->primary_tag();
		print "\n";
	}
	print "-----------------------------------\n";
	print "Display ID:  ".$oGbk->display_id()."\n";
	print "Description: ".$oGbk->desc()."\n";
	print "Sequence:    ".$oGbk->seq()."\n";
}


# Get sub-information from a Primary Tag, "CDS"
print "--------------------------------------------\n";
if(my $oGbk = $oDb->get_Seq_by_acc($sAccNo)) {               # Get Information by Accession Number
	foreach my $oFeat ($oGbk->top_SeqFeatures()) {
		if($oFeat->primary_tag() eq "CDS") {                 # Only for "CDS" Primary Tag.
			my $oSeqPart = $oFeat->spliced_seq();

			print "Display ID:  ".$oSeqPart->display_id()."\n";
			print "Description: ".$oSeqPart->desc()."\n";
			print "Sequence:    ".$oSeqPart->seq()."\n";

			my @aDbXrefs = ();
			eval {                                           # Exeception handling
				@aDbXrefs = $oFeat->get_tag_values("db_xref");
			};
			if ($@) {  # Exception occurred!
				print "No Data on db_xref\n";
				print $@;
				print "\n";
			} else {	# No Exception
				foreach my $sCurDbXref (@aDbXrefs) {
					print "db_xref:     ".$sCurDbXref."\n";
				}
			}

			my @aTranslation = ();
			eval {                                           # Exeception handling
				@aTranslation = $oFeat->get_tag_values("translation");
			};
			if ($@) {  # Exception occurred!
				print "No Data on translation\n";
				print $@;
				print "\n";
			} else {	# No Exception
				foreach my $sCurTranslation (@aTranslation) {
					print "Translation: ".$sCurTranslation."\n";
				}
			}

		}
	}
}




# For more information, refer to the following link
# https://www.tutorialspoint.com/perl
# https://metacpan.org/pod/Bio::DB::GenBank