use
Carp
qw(cluck carp verbose)
;
our
$VERSION
=
'0.11'
;
sub
new {
my
$self
= {};
my
$dummy
=
shift
;
my
$db
=
shift
;
my
$id
=
shift
;
my
$i
;
my
$ret
=
$db
->query(
"SELECT * FROM sequence WHERE sequence_primary_id = $id;"
);
my
@fields
= @{
$$ret
[0]};
$self
->{DB} =
$db
;
$self
->{PRIMARY} =
$fields
[0];
$self
->{FAKE} =
$fields
[1];
$self
->{DB_ID} =
$fields
[2];
$self
->{LENGTH} =
$fields
[3];
$self
->{DATE} =
$fields
[4];
$self
->{VERSION} =
$fields
[5];
$self
->{ANNOT} =
$fields
[6];
$self
->{ORIG} =
$fields
[7];
$self
->{DATA} =
$fields
[8];
$self
->{TAXON} =
$fields
[9];
if
(
defined
(
$self
->{ANNOT})){
$ret
=
$db
->query(
"SELECT * FROM sequence_annotation WHERE sequence_annotation_primary_id = "
.
$self
->{ANNOT}.
";"
);
@fields
= @{
$$ret
[0]};
$self
->{MAINDBID} =
$fields
[1];
$self
->{UTR} =
$fields
[2];
$self
->{DESC} =
$fields
[3];
$self
->{GENENAME} =
$fields
[4];
}
else
{
}
if
(
defined
(
$self
->{DATA})) {
$ret
=
$db
->query(
"SELECT * FROM sequence_data WHERE sequence_data_primary_id ="
.
$self
->{DATA}.
";"
);
@fields
= @{
$$ret
[0]};
$self
->{FASTA} =
$fields
[2];
$self
->{BLAST} =
$fields
[3];
}
else
{
}
$ret
=
$db
->query(
"SELECT * FROM taxon_annotation WHERE taxon_primary_id ="
.
$self
->{TAXON}.
";"
);
@fields
= @{
$$ret
[0]};
$self
->{TAXID} =
$fields
[1];
$self
->{TAXNAME} =
$fields
[2];
$self
->{TAXCLASS} =
$fields
[3];
my
%xref
;
$ret
=
$db
->query(
"SELECT xref_id,xref_type FROM sequence_xref WHERE sequence_primary_id = $id;"
);
for
(
$i
= 0;
$i
<
$#$ret
+1;
$i
++){
@fields
= @{
$$ret
[
$i
]};
push
@{
$xref
{
$fields
[1]} },
$fields
[0];
}
$self
->{XREF} = \
%xref
;
bless
$self
;
return
(
$self
);
}
sub
new_from_dbid {
my
$self
= {};
my
$dummy
=
shift
;
my
$db
=
shift
;
my
$id
=
shift
;
my
$i
;
my
$ret
=
$db
->query(
"SELECT * FROM sequence WHERE sequence_id = $id;"
);
my
@fields
= @{
$$ret
[0]};
$self
->{DB} =
$db
;
$self
->{PRIMARY} =
$fields
[0];
$self
->{FAKE} =
$fields
[1];
$self
->{DB_ID} =
$fields
[2];
$self
->{LENGTH} =
$fields
[3];
$self
->{DATE} =
$fields
[4];
$self
->{VERSION} =
$fields
[5];
$self
->{ANNOT} =
$fields
[6];
$self
->{ORIG} =
$fields
[7];
$self
->{DATA} =
$fields
[8];
$self
->{TAXON} =
$fields
[9];
if
(
defined
(
$self
->{ANNOT})){
$ret
=
$db
->query(
"SELECT * FROM sequence_annotation WHERE sequence_annotation_primary_id = "
.
$self
->{ANNOT}.
";"
);
@fields
= @{
$$ret
[0]};
$self
->{MAINDBID} =
$fields
[1];
$self
->{UTR} =
$fields
[2];
$self
->{DESC} =
$fields
[3];
$self
->{GENENAME} =
$fields
[4];
}
else
{
}
if
(
defined
(
$self
->{DATA})) {
$ret
=
$db
->query(
"SELECT * FROM sequence_data WHERE sequence_data_primary_id ="
.
$self
->{DATA}.
";"
);
@fields
= @{
$$ret
[0]};
$self
->{FASTA} =
$fields
[2];
$self
->{BLAST} =
$fields
[3];
}
else
{
}
$ret
=
$db
->query(
"SELECT * FROM taxon_annotation WHERE taxon_primary_id ="
.
$self
->{TAXON}.
";"
);
@fields
= @{
$$ret
[0]};
$self
->{TAXID} =
$fields
[1];
$self
->{TAXNAME} =
$fields
[2];
$self
->{TAXCLASS} =
$fields
[3];
my
%xref
;
$ret
=
$db
->query(
"SELECT xref_id,xref_type FROM sequence_xref WHERE sequence_primary_id = $id;"
);
for
(
$i
= 0;
$i
<
$#$ret
+1;
$i
++){
@fields
= @{
$$ret
[
$i
]};
push
@{
$xref
{
$fields
[1]} },
$fields
[0];
}
$self
->{XREF} = \
%xref
;
bless
$self
;
return
(
$self
);
}
sub
get_id {
my
$self
=
shift
;
return
(
$self
->{PRIMARY});
}
sub
get_fake_id {
my
$self
=
shift
;
return
(
$self
->{FAKE});
}
sub
get_db_id {
my
$self
=
shift
;
return
(
$self
->{DB_ID});
}
sub
get_length {
my
$self
=
shift
;
return
(
$self
->{LENGTH});
}
sub
get_date {
my
$self
=
shift
;
return
(
$self
->{DATE});
}
sub
get_ver {
my
$self
=
shift
;
return
(
$self
->{VERSION});
}
sub
get_annot_id {
my
$self
=
shift
;
return
(
$self
->{ANNOT});
}
sub
get_orig_id {
my
$self
=
shift
;
return
(
$self
->{ORIG});
}
sub
get_data_id {
my
$self
=
shift
;
return
(
$self
->{DATA});
}
sub
get_taxon_id {
my
$self
=
shift
;
return
(
$self
->{TAXON});
}
sub
get_data_main_db_id {
my
$self
=
shift
;
return
(
$self
->{MAINDBID});
}
sub
get_utr_length {
my
$self
=
shift
;
return
(
$self
->{UTR});
}
sub
get_desc {
my
$self
=
shift
;
return
(
$self
->{DESC});
}
sub
get_gene_name {
my
$self
=
shift
;
return
(
$self
->{GENENAME});
}
sub
get_fasta {
my
$self
=
shift
;
my
$seq
=
">"
.
$self
->{DB_ID}.
"\n"
.
$self
->{FASTA}.
"\n"
;
return
(
$seq
);
}
sub
get_raw_seq {
my
$self
=
shift
;
my
$seq
=
$self
->{FASTA};
return
(
$seq
);
}
sub
get_blast {
my
$self
=
shift
;
return
(
$self
->{BLAST});
}
sub
get_taxid {
my
$self
=
shift
;
return
(
$self
->{TAXID});
}
sub
get_taxon_name {
my
$self
=
shift
;
return
(
$self
->{TAXNAME});
}
sub
get_taxon_class {
my
$self
=
shift
;
return
(
$self
->{TAXCLASS});
}
sub
print_all_xref {
my
$self
=
shift
;
for
my
$keys
(
keys
%{
$self
->{XREF} }){
print
"$keys: "
;
for
(@{ ${
$self
->{XREF} }{
$keys
} }){
print
"$_ "
}
print
"\n"
;
}
}
sub
get_all_xref_keys {
my
$self
=
shift
;
my
@xrefkeys
=
keys
%{
$self
->{XREF} };
return
(\
@xrefkeys
);
}
sub
get_xref_value {
my
$self
=
shift
;
my
$key
=
shift
;
if
(${
$self
->{XREF} }{
$key
}){
return
(${
$self
->{XREF} }{
$key
});
}
else
{
return
(-1);
}
}
sub
get_all_seq_features {
my
$self
=
shift
;
my
@seqfeatures
;
my
$query
=
"SELECT sequence_feature_primary_id FROM sequence_feature WHERE sequence_primary_id ="
.
$self
->{PRIMARY}.
" ORDER BY feature_start;"
;
my
$ref
=
$self
->{DB}->query(
$query
);
if
(
$#$ref
== -1){
return
(-1);
}
for
my
$sfpid
(
@$ref
){
my
$sf
= Bio::DOOP::SequenceFeature->new(
$self
->{DB},
$$sfpid
[0]);
push
@seqfeatures
,
$sf
;
}
return
(\
@seqfeatures
);
}
sub
get_all_subsets {
my
$self
=
shift
;
my
@subsets
;
my
$id
=
$self
->{PRIMARY};
my
$query
=
"SELECT subset_primary_id FROM subset_xref WHERE sequence_primary_id = $id"
;
my
$ref
=
$self
->{DB}->query(
$query
);
if
(
$#$ref
== -1){
return
(-1);
}
for
my
$subset
(
@$ref
){
push
@subsets
, Bio::DOOP::ClusterSubset->new(
$self
->{DB},
$$subset
[0]);
}
return
(\
@subsets
);
}
1;