$Bio::EnsEMBL::DBSQL::TranscriptAdaptor::VERSION
=
'112.0_55'
;
$Bio::EnsEMBL::DBSQL::TranscriptAdaptor::VERSION
=
'112.055'
;
@ISA
=
qw( Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor )
;
sub
_tables {
return
(
[
'transcript'
,
't'
],
[
'xref'
,
'x'
],
[
'external_db'
,
'exdb'
] );
}
sub
_columns {
my
(
$self
) =
@_
;
my
$created_date
=
$self
->db()->dbc()->from_date_to_seconds(
"created_date"
);
my
$modified_date
=
$self
->db()->dbc()->from_date_to_seconds(
"modified_date"
);
my
@columns
=
(
't.transcript_id'
,
't.seq_region_id'
,
't.seq_region_start'
,
't.seq_region_end'
,
't.seq_region_strand'
,
't.analysis_id'
,
't.gene_id'
,
't.is_current'
,
't.stable_id'
,
't.version'
,
$created_date
,
$modified_date
,
't.description'
,
't.biotype'
,
'exdb.db_name'
,
'exdb.status'
,
'exdb.db_display_name'
,
'x.xref_id'
,
'x.display_label'
,
'x.dbprimary_acc'
,
'x.version'
,
'x.description'
,
'x.info_type'
,
'x.info_text'
,
'exdb.db_release'
);
$self
->schema_version > 74 and
push
@columns
,
't.source'
;
return
@columns
;
}
sub
_left_join {
return
(
[
'xref'
,
"x.xref_id = t.display_xref_id"
],
[
'external_db'
,
"exdb.external_db_id = x.external_db_id"
]
);
}
sub
fetch_by_stable_id {
my
(
$self
,
$stable_id
) =
@_
;
my
$constraint
=
"t.stable_id = ? AND t.is_current = 1"
;
$self
->bind_param_generic_fetch(
$stable_id
,SQL_VARCHAR);
my
(
$transcript
) = @{
$self
->generic_fetch(
$constraint
) };
if
(!
defined
(
$transcript
) && (
my
$vindex
=
rindex
(
$stable_id
,
'.'
))) {
$transcript
=
$self
->fetch_by_stable_id_version(
substr
(
$stable_id
,0,
$vindex
),
substr
(
$stable_id
,
$vindex
+1));
}
return
$transcript
;
}
sub
fetch_by_stable_id_version {
my
(
$self
,
$stable_id
,
$version
) =
@_
;
return
unless
(
$version
=~ /^\d+$/);
my
$constraint
=
"t.stable_id = ? AND t.version = ? AND t.is_current = 1"
;
$self
->bind_param_generic_fetch(
$stable_id
, SQL_VARCHAR);
$self
->bind_param_generic_fetch(
$version
, SQL_INTEGER);
my
(
$transcript
) = @{
$self
->generic_fetch(
$constraint
)};
return
$transcript
;
}
sub
fetch_all {
my
(
$self
) =
@_
;
my
$constraint
=
't.biotype != "LRG_gene" and t.is_current = 1'
;
my
@trans
= @{
$self
->generic_fetch(
$constraint
) };
return
\
@trans
;
}
sub
fetch_all_versions_by_stable_id {
my
(
$self
,
$stable_id
) =
@_
;
my
$constraint
=
"t.stable_id = ?"
;
$self
->bind_param_generic_fetch(
$stable_id
,SQL_VARCHAR);
return
$self
->generic_fetch(
$constraint
);
}
sub
fetch_by_rnaproduct_id {
my
(
$self
,
$p_dbID
) =
@_
;
throw(
"dbID argument is required"
)
unless
defined
(
$p_dbID
);
my
$sth
=
$self
->prepare(
"SELECT transcript_id FROM rnaproduct WHERE rnaproduct_id = ?"
);
$sth
->bind_param(1,
$p_dbID
, SQL_INTEGER);
$sth
->execute();
my
(
$dbID
) =
$sth
->fetchrow_array();
$sth
->finish();
if
(
$dbID
) {
return
$self
->fetch_by_dbID(
$dbID
);
}
return
;
}
sub
fetch_by_translation_stable_id {
my
(
$self
,
$transl_stable_id
) =
@_
;
my
$sth
=
$self
->prepare(
qq(
SELECT t.transcript_id
FROM translation tl,
transcript t
WHERE tl.stable_id = ?
AND tl.transcript_id = t.transcript_id
AND t.is_current = 1
)
);
$sth
->bind_param(1,
$transl_stable_id
, SQL_VARCHAR);
$sth
->execute();
my
(
$id
) =
$sth
->fetchrow_array;
$sth
->finish;
if
(
$id
){
return
$self
->fetch_by_dbID(
$id
);
}
elsif
(
my
$vindex
=
rindex
(
$transl_stable_id
,
'.'
)) {
return
$self
->fetch_by_translation_stable_id_version(
substr
(
$transl_stable_id
,0,
$vindex
),
substr
(
$transl_stable_id
,
$vindex
+1));
}
else
{
return
undef
;
}
}
sub
fetch_by_translation_stable_id_version {
my
(
$self
,
$transl_stable_id
,
$transl_version
) =
@_
;
return
unless
(
$transl_version
=~ /^\d+$/);
my
$sth
=
$self
->prepare(
qq(
SELECT t.transcript_id
FROM translation tl,
transcript t
WHERE tl.stable_id = ?
AND tl.version = ?
AND tl.transcript_id = t.transcript_id
AND t.is_current = 1
)
);
$sth
->bind_param(1,
$transl_stable_id
, SQL_VARCHAR);
$sth
->bind_param(2,
$transl_version
, SQL_INTEGER);
$sth
->execute();
my
(
$id
) =
$sth
->fetchrow_array;
$sth
->finish;
if
(
$id
){
return
$self
->fetch_by_dbID(
$id
);
}
else
{
return
undef
;
}
}
sub
fetch_by_translation_id {
my
(
$self
,
$p_dbID
) =
@_
;
if
( !
defined
(
$p_dbID
) ) {
throw(
"dbID argument is required"
);
}
my
$sth
=
$self
->prepare(
"SELECT transcript_id "
.
"FROM translation "
.
"WHERE translation_id = ?"
);
$sth
->bind_param( 1,
$p_dbID
, SQL_INTEGER );
$sth
->execute();
my
(
$dbID
) =
$sth
->fetchrow_array();
$sth
->finish();
if
(
$dbID
) {
return
$self
->fetch_by_dbID(
$dbID
);
}
return
undef
;
}
sub
fetch_all_by_Gene {
my
(
$self
,
$gene
) =
@_
;
my
$constraint
=
"t.gene_id = "
.
$gene
->dbID();
my
$gslice
=
$gene
->slice();
if
( !
defined
(
$gslice
) ) {
throw(
"Gene must have attached slice to retrieve transcripts."
);
}
my
$slice
;
if
(
$gene
->start() < 1 ||
$gene
->end() >
$gslice
->
length
() ) {
if
(
$gslice
->is_circular() ) {
$slice
=
$gslice
;
}
else
{
$slice
=
$self
->db->get_SliceAdaptor->fetch_by_Feature(
$gene
);
}
}
else
{
$slice
=
$gslice
;
}
my
$transcripts
=
$self
->fetch_all_by_Slice_constraint(
$slice
,
$constraint
);
if
(
$slice
!=
$gslice
) {
my
@out
;
foreach
my
$tr
( @{
$transcripts
} ) {
push
(
@out
,
$tr
->transfer(
$gslice
) );
}
$transcripts
= \
@out
;
}
my
$canonical_t
=
$gene
->canonical_transcript();
foreach
my
$t
( @{
$transcripts
} ) {
if
(
$t
->equals(
$canonical_t
) ) {
$t
->is_canonical(1);
last
;
}
}
return
$transcripts
;
}
sub
fetch_all_by_Slice {
my
(
$self
,
$slice
,
$load_exons
,
$logic_name
,
$constraint
,
$source
,
$biotype
) =
@_
;
if
(
defined
$constraint
and
$constraint
ne
''
) {
$constraint
.=
' AND t.is_current = 1'
;
}
else
{
$constraint
.=
't.is_current = 1'
;
}
if
(
defined
(
$source
)) {
$constraint
.=
" and t.source = '$source'"
;
}
if
(
defined
(
$biotype
)) {
my
$inline_variables
= 1;
$constraint
.=
" and "
.
$self
->generate_in_constraint(
$biotype
,
't.biotype'
, SQL_VARCHAR,
$inline_variables
);
}
my
$transcripts
=
$self
->SUPER::fetch_all_by_Slice_constraint(
$slice
,
$constraint
,
$logic_name
);
if
( !
$load_exons
||
@$transcripts
< 1 ) {
return
$transcripts
;
}
if
(
exists
(
$transcripts
->[0]->{
'_trans_exon_array'
} ) ) {
return
$transcripts
;
}
my
(
$min_start
,
$max_end
);
my
$ext_slice
;
unless
(
$slice
->is_circular()) {
foreach
my
$t
(
@$transcripts
) {
if
(!
defined
(
$min_start
) ||
$t
->seq_region_start() <
$min_start
) {
$min_start
=
$t
->seq_region_start();
}
if
(!
defined
(
$max_end
) ||
$t
->seq_region_end() >
$max_end
) {
$max_end
=
$t
->seq_region_end();
}
}
if
(
$min_start
>=
$slice
->start() &&
$max_end
<=
$slice
->end()) {
$ext_slice
=
$slice
;
}
else
{
my
$sa
=
$self
->db()->get_SliceAdaptor();
$ext_slice
=
$sa
->fetch_by_region(
$slice
->coord_system->name(),
$slice
->seq_region_name(),
$min_start
,
$max_end
,
$slice
->strand(),
$slice
->coord_system->version());
}
}
else
{
my
(
$min_start_feature
,
$max_end_feature
);
foreach
my
$t
(
@$transcripts
) {
if
(!
defined
(
$min_start
) || (
$t
->start >= 0 &&
$t
->start() <
$min_start
)) {
$min_start
=
$t
->start();
$min_start_feature
=
$t
;
}
if
(!
defined
(
$max_end
) || (
$t
->end() >= 0 &&
$t
->end() >
$max_end
)) {
$max_end
=
$t
->end();
$max_end_feature
=
$t
;
}
}
$min_start
=
$min_start_feature
->seq_region_start();
$max_end
=
$max_end_feature
->seq_region_end();
my
$sa
=
$self
->db()->get_SliceAdaptor();
$ext_slice
=
$sa
->fetch_by_region(
$slice
->coord_system->name(),
$slice
->seq_region_name(),
$min_start
,
$max_end
,
$slice
->strand(),
$slice
->coord_system->version());
}
my
%tr_hash
=
map
{
$_
->
dbID
=>
$_
} @{
$transcripts
};
my
$tr_id_str
=
join
(
','
,
keys
(
%tr_hash
) );
my
$sth
=
$self
->prepare(
"SELECT `transcript_id`, `exon_id`, `rank` "
.
"FROM exon_transcript "
.
"WHERE transcript_id IN ($tr_id_str)"
);
$sth
->execute();
my
(
$tr_id
,
$ex_id
,
$rank
);
$sth
->bind_columns( \(
$tr_id
,
$ex_id
,
$rank
) );
my
%ex_tr_hash
;
while
(
$sth
->fetch() ) {
$ex_tr_hash
{
$ex_id
} ||= [];
push
( @{
$ex_tr_hash
{
$ex_id
} }, [
$tr_hash
{
$tr_id
},
$rank
] );
}
my
$ea
=
$self
->db()->get_ExonAdaptor();
my
$exons
=
$ea
->fetch_all_by_Slice_constraint(
$ext_slice
,
sprintf
(
"e.exon_id IN (%s)"
,
join
(
','
,
sort
{
$a
<=>
$b
}
keys
(
%ex_tr_hash
) ) ) );
foreach
my
$ex
( @{
$exons
} ) {
my
$new_ex
;
if
(
$slice
!=
$ext_slice
) {
$new_ex
=
$ex
->transfer(
$slice
);
if
( !
defined
(
$new_ex
) ) {
throw(
"Unexpected. "
.
"Exon could not be transfered onto Transcript slice."
);
}
}
else
{
$new_ex
=
$ex
;
}
foreach
my
$row
( @{
$ex_tr_hash
{
$new_ex
->dbID() } } ) {
my
(
$tr
,
$rank
) = @{
$row
};
$tr
->add_Exon(
$new_ex
,
$rank
);
}
}
my
$tla
=
$self
->db()->get_TranslationAdaptor();
$tla
->fetch_all_by_Transcript_list(
$transcripts
);
return
$transcripts
;
}
sub
fetch_all_by_external_name {
my
(
$self
,
$external_name
,
$external_db_name
,
$override
) =
@_
;
my
$entryAdaptor
=
$self
->db->get_DBEntryAdaptor();
my
@ids
=
$entryAdaptor
->list_transcript_ids_by_extids(
$external_name
,
$external_db_name
,
$override
);
my
@features
= @{
$self
->fetch_all_by_dbID_list( \
@ids
) };
my
@reference
=
grep
{
$_
->slice()->is_reference() }
@features
;
my
@non_reference
=
grep
{ !
$_
->slice()->is_reference() }
@features
;
return
[
@reference
,
@non_reference
];
}
sub
fetch_all_by_GOTerm {
my
(
$self
,
$term
) =
@_
;
assert_ref(
$term
,
'Bio::EnsEMBL::OntologyTerm'
);
if
(
$term
->ontology() ne
'GO'
) {
throw(
'Argument is not a GO term'
);
}
my
$entryAdaptor
=
$self
->db->get_DBEntryAdaptor();
my
%unique_dbIDs
;
foreach
my
$accession
(
map
{
$_
->accession() }
(
$term
, @{
$term
->descendants() } ) )
{
my
@ids
=
$entryAdaptor
->list_transcript_ids_by_extids(
$accession
,
'GO'
);
foreach
my
$dbID
(
@ids
) {
$unique_dbIDs
{
$dbID
} = 1 }
}
my
@result
= @{
$self
->fetch_all_by_dbID_list(
[
sort
{
$a
<=>
$b
}
keys
(
%unique_dbIDs
) ]
) };
return
\
@result
;
}
sub
fetch_all_by_GOTerm_accession {
my
(
$self
,
$accession
) =
@_
;
if
(
$accession
!~ /^GO:/ ) {
throw(
'Argument is not a GO term accession'
);
}
my
$goAdaptor
=
Bio::EnsEMBL::Registry->get_adaptor(
'Multi'
,
'Ontology'
,
'OntologyTerm'
);
my
$term
=
$goAdaptor
->fetch_by_accession(
$accession
);
return
$self
->fetch_all_by_GOTerm(
$term
);
}
sub
fetch_by_display_label {
my
$self
=
shift
;
my
$label
=
shift
;
my
$constraint
=
"x.display_label = ? AND t.is_current = 1"
;
$self
->bind_param_generic_fetch(
$label
,SQL_VARCHAR);
my
(
$transcript
) = @{
$self
->generic_fetch(
$constraint
) };
return
$transcript
;
}
sub
fetch_all_by_exon_stable_id {
my
(
$self
,
$stable_id
) =
@_
;
my
@trans
;
my
$sth
=
$self
->prepare(
qq(
SELECT t.transcript_id
FROM exon_transcript et, exon e, transcript t
WHERE e.exon_id = et.exon_id
AND et.transcript_id = t.transcript_id
AND e.stable_id = ?
AND t.is_current = 1
)
);
$sth
->bind_param(1,
$stable_id
, SQL_VARCHAR);
$sth
->execute();
while
(
my
$id
=
$sth
->fetchrow_array ) {
my
$transcript
=
$self
->fetch_by_dbID(
$id
);
push
(
@trans
,
$transcript
)
if
$transcript
;
}
if
(!
@trans
) {
return
undef
;
}
return
\
@trans
;
}
sub
fetch_all_by_source {
my
(
$self
,
$source
) =
@_
;
my
@transcripts
= @{
$self
->generic_fetch(
$self
->source_constraint(
$source
))};
return
\
@transcripts
;
}
sub
source_constraint {
my
(
$self
,
$sources
,
$inline_variables
) =
@_
;
my
$constraint
=
"t.is_current = 1"
;
my
$in_statement
=
$self
->generate_in_constraint(
$sources
,
't.source'
, SQL_VARCHAR,
$inline_variables
);
$constraint
.=
" and $in_statement"
;
return
$constraint
;
}
sub
count_all_by_source {
my
(
$self
,
$source
) =
@_
;
return
$self
->generic_count(
$self
->source_constraint(
$source
));
}
sub
count_all_by_Slice {
my
(
$self
,
$slice
,
$biotype
,
$source
) =
@_
;
my
$constraint
=
't.is_current = 1'
;
if
(
defined
(
$source
)) {
$constraint
.=
" and t.source = '$source'"
;
}
if
(
defined
(
$biotype
)) {
$constraint
.=
" and "
.
$self
->biotype_constraint(
$biotype
);
}
return
$self
->count_by_Slice_constraint(
$slice
,
$constraint
);
}
sub
fetch_all_by_biotype {
my
(
$self
,
$biotype
) =
@_
;
my
@transcripts
= @{
$self
->generic_fetch(
$self
->biotype_constraint(
$biotype
))};
return
\
@transcripts
;
}
sub
biotype_constraint {
my
(
$self
,
$biotypes
,
$inline_variables
) =
@_
;
my
$constraint
=
"t.is_current = 1"
;
my
$in_statement
=
$self
->generate_in_constraint(
$biotypes
,
't.biotype'
, SQL_VARCHAR,
$inline_variables
);
$constraint
.=
" and $in_statement"
;
return
$constraint
;
}
sub
count_all_by_biotype {
my
(
$self
,
$biotype
) =
@_
;
return
$self
->generic_count(
$self
->biotype_constraint(
$biotype
));
}
sub
store {
my
(
$self
,
$transcript
,
$gene_dbID
,
$analysis_id
,
$skip_recalculating_coordinates
) =
@_
;
if
( !
ref
(
$transcript
)
|| !
$transcript
->isa(
'Bio::EnsEMBL::Transcript'
) )
{
throw(
"$transcript is not a EnsEMBL transcript - not storing"
);
}
my
$db
=
$self
->db();
if
(
$transcript
->is_stored(
$db
) ) {
return
$transcript
->dbID();
}
if
(!
$skip_recalculating_coordinates
) {
$transcript
->recalculate_coordinates();
}
my
$is_current
= (
defined
(
$transcript
->is_current() )
?
$transcript
->is_current()
: 1 );
my
$analysis
=
$transcript
->analysis();
my
$new_analysis_id
;
if
(
$analysis
) {
if
(
$analysis
->is_stored(
$db
) ) {
$new_analysis_id
=
$analysis
->dbID;
}
else
{
$new_analysis_id
=
$db
->get_AnalysisAdaptor->store(
$analysis
);
}
}
else
{
throw(
"Need an analysis_id to store the Transcript."
);
}
my
$exons
=
$transcript
->get_all_Exons();
my
$exonAdaptor
=
$db
->get_ExonAdaptor();
foreach
my
$exon
( @{
$exons
} ) {
$exonAdaptor
->store(
$exon
);
}
my
$original_translation
=
$transcript
->translation();
my
$original
=
$transcript
;
my
$seq_region_id
;
(
$transcript
,
$seq_region_id
) =
$self
->_pre_store(
$transcript
);
my
@columns
=
qw(
gene_id
analysis_id
seq_region_id
seq_region_start
seq_region_end
seq_region_strand
)
;
push
@columns
,
'source'
if
(
$self
->schema_version > 74);
push
@columns
,
qw(
biotype
description
is_current
canonical_translation_id
)
;
my
@canned_columns
;
my
@canned_values
;
if
(
defined
(
$transcript
->stable_id() ) ) {
push
@columns
,
'stable_id'
,
'version'
;
my
$created
=
$self
->db->dbc->from_seconds_to_date(
$transcript
->created_date());
my
$modified
=
$self
->db->dbc->from_seconds_to_date(
$transcript
->modified_date());
if
(
$created
) {
push
@canned_columns
,
'created_date'
;
push
@canned_values
,
$created
;
}
if
(
$modified
) {
push
@canned_columns
,
'modified_date'
;
push
@canned_values
,
$modified
;
}
}
my
$columns
=
join
(
', '
,
@columns
,
@canned_columns
);
my
$values
=
join
(
', '
, (
'?'
) x
@columns
,
@canned_values
);
my
$store_transcript_sql
=
qq(
INSERT INTO transcript ( $columns )
VALUES (
$values
)
);
my
$tst
=
$self
->prepare(
$store_transcript_sql
);
my
$i
= 0;
$tst
->bind_param( ++
$i
,
$gene_dbID
, SQL_INTEGER );
$tst
->bind_param( ++
$i
,
$new_analysis_id
, SQL_INTEGER );
$tst
->bind_param( ++
$i
,
$seq_region_id
, SQL_INTEGER );
$tst
->bind_param( ++
$i
,
$transcript
->start(), SQL_INTEGER );
$tst
->bind_param( ++
$i
,
$transcript
->end(), SQL_INTEGER );
$tst
->bind_param( ++
$i
,
$transcript
->strand(), SQL_TINYINT );
$self
->schema_version > 74 and
$tst
->bind_param( ++
$i
,
$transcript
->source(), SQL_VARCHAR );
$tst
->bind_param( ++
$i
,
$transcript
->get_Biotype->name, SQL_VARCHAR );
$tst
->bind_param( ++
$i
,
$transcript
->description(), SQL_LONGVARCHAR );
$tst
->bind_param( ++
$i
,
$is_current
, SQL_TINYINT );
$tst
->bind_param( ++
$i
,
undef
, SQL_INTEGER );
if
(
defined
(
$transcript
->stable_id() ) ) {
$tst
->bind_param( ++
$i
,
$transcript
->stable_id(), SQL_VARCHAR );
$tst
->bind_param( ++
$i
,
$transcript
->version(), SQL_INTEGER );
}
$tst
->execute();
$tst
->finish();
my
$transc_dbID
=
$self
->last_insert_id(
'transcript_id'
,
undef
,
'transcript'
);
my
$alt_translations
=
$transcript
->get_all_alternative_translations();
my
$translation
=
$transcript
->translation();
if
(
defined
(
$translation
) ) {
my
$start_exon
=
$translation
->start_Exon();
my
$end_exon
=
$translation
->end_Exon();
if
( !
defined
(
$start_exon
) ) {
throw(
"Translation does not define a start exon."
);
}
if
( !
defined
(
$end_exon
) ) {
throw(
"Translation does not defined an end exon."
);
}
if
( !
defined
(
$start_exon
->dbID() ) ) {
my
$key
=
$start_exon
->hashkey();
(
$start_exon
) =
grep
{
$_
->hashkey() eq
$key
}
@$exons
;
if
(
defined
(
$start_exon
) ) {
$translation
->start_Exon(
$start_exon
);
}
else
{
throw(
"Translation's start_Exon does not appear "
.
"to be one of the exons in "
.
"its associated Transcript"
);
}
}
if
( !
defined
(
$end_exon
->dbID() ) ) {
my
$key
=
$end_exon
->hashkey();
(
$end_exon
) =
grep
{
$_
->hashkey() eq
$key
}
@$exons
;
if
(
defined
(
$end_exon
) ) {
$translation
->end_Exon(
$end_exon
);
}
else
{
throw(
"Translation's end_Exon does not appear "
.
"to be one of the exons in "
.
"its associated Transcript."
);
}
}
my
$old_dbid
=
$translation
->dbID();
$db
->get_TranslationAdaptor()->store(
$translation
,
$transc_dbID
);
my
$sth
=
$self
->prepare(
q(
UPDATE transcript
SET canonical_translation_id = ?
WHERE transcript_id = ?)
);
$sth
->bind_param( 1,
$translation
->dbID(), SQL_INTEGER );
$sth
->bind_param( 2,
$transc_dbID
, SQL_INTEGER );
$sth
->execute();
$original_translation
->dbID(
$translation
->dbID() );
$original_translation
->adaptor(
$translation
->adaptor() );
}
if
(
defined
(
$alt_translations
)
&&
scalar
( @{
$alt_translations
} ) > 0 )
{
foreach
my
$alt_translation
( @{
$alt_translations
} ) {
my
$start_exon
=
$alt_translation
->start_Exon();
my
$end_exon
=
$alt_translation
->end_Exon();
if
( !
defined
(
$start_exon
) ) {
throw(
"Translation does not define a start exon."
);
}
elsif
( !
defined
(
$end_exon
) ) {
throw(
"Translation does not defined an end exon."
);
}
if
( !
defined
(
$start_exon
->dbID() ) ) {
my
$key
=
$start_exon
->hashkey();
(
$start_exon
) =
grep
{
$_
->hashkey() eq
$key
} @{
$exons
};
if
(
defined
(
$start_exon
) ) {
$alt_translation
->start_Exon(
$start_exon
);
}
else
{
throw(
"Translation's start_Exon does not appear "
.
"to be one of the exon in"
.
"its associated Transcript"
);
}
}
if
( !
defined
(
$end_exon
->dbID() ) ) {
my
$key
=
$end_exon
->hashkey();
(
$end_exon
) =
grep
{
$_
->hashkey() eq
$key
}
@$exons
;
if
(
defined
(
$end_exon
) ) {
$alt_translation
->end_Exon(
$end_exon
);
}
else
{
throw(
"Translation's end_Exon does not appear "
.
"to be one of the exons in "
.
"its associated Transcript."
);
}
}
$db
->get_TranslationAdaptor()
->store(
$alt_translation
,
$transc_dbID
);
}
}
my
$dbEntryAdaptor
=
$db
->get_DBEntryAdaptor();
foreach
my
$dbe
( @{
$transcript
->get_all_DBEntries() } ) {
$dbEntryAdaptor
->store(
$dbe
,
$transc_dbID
,
"Transcript"
, 1 );
}
if
(
my
$dxref
=
$transcript
->display_xref() ) {
my
$dxref_id
;
if
(
$dxref
->is_stored(
$db
) ) {
$dxref_id
=
$dxref
->dbID();
}
else
{
$dxref_id
=
$dbEntryAdaptor
->
exists
(
$dxref
);
}
if
(
defined
(
$dxref_id
) ) {
my
$sth
=
$self
->prepare(
"UPDATE transcript "
.
"SET display_xref_id = ? "
.
"WHERE transcript_id = ?"
);
$sth
->bind_param( 1,
$dxref_id
, SQL_INTEGER );
$sth
->bind_param( 2,
$transc_dbID
, SQL_INTEGER );
$sth
->execute();
$dxref
->dbID(
$dxref_id
);
$dxref
->adaptor(
$dbEntryAdaptor
);
$sth
->finish();
}
else
{
warning(
sprintf
(
"Display_xref %s:%s is not stored in database.\n"
.
"Not storing relationship to this transcript."
,
$dxref
->dbname(),
$dxref
->display_id() ) );
$dxref
->dbID(
undef
);
$dxref
->adaptor(
undef
);
}
}
my
$etst
=
$self
->prepare(
"INSERT INTO exon_transcript (`exon_id`,`transcript_id`,`rank`) "
.
"VALUES (?,?,?)"
);
my
$rank
= 1;
foreach
my
$exon
( @{
$transcript
->get_all_Exons } ) {
$etst
->bind_param( 1,
$exon
->dbID, SQL_INTEGER );
$etst
->bind_param( 2,
$transc_dbID
, SQL_INTEGER );
$etst
->bind_param( 3,
$rank
, SQL_INTEGER );
$etst
->execute();
$rank
++;
}
$etst
->finish();
my
$tsf_adaptor
=
$db
->get_TranscriptSupportingFeatureAdaptor();
$tsf_adaptor
->store(
$transc_dbID
,
$transcript
->get_all_supporting_features() );
my
$attr_adaptor
=
$db
->get_AttributeAdaptor();
$attr_adaptor
->store_on_Transcript(
$transc_dbID
,
$transcript
->get_all_Attributes() );
if
(
$transcript
->is_canonical()) {
my
$gene_adaptor
=
$self
->db()->get_GeneAdaptor();
my
$gene
=
$gene_adaptor
->fetch_by_dbID(
$gene_dbID
);
$transcript
->dbID(
$transc_dbID
);
$gene
->canonical_transcript(
$transcript
);
$gene_adaptor
->update(
$gene
);
}
my
$ise_adaptor
=
$db
->get_IntronSupportingEvidenceAdaptor();
my
$intron_supporting_evidence
=
$transcript
->get_all_IntronSupportingEvidence();
foreach
my
$ise
(@{
$intron_supporting_evidence
}) {
$ise_adaptor
->store(
$ise
);
$ise_adaptor
->store_transcript_linkage(
$ise
,
$transcript
,
$transc_dbID
);
}
$original
->dbID(
$transc_dbID
);
$original
->adaptor(
$self
);
return
$transc_dbID
;
}
sub
get_Interpro_by_transid {
my
(
$self
,
$trans_stable_id
) =
@_
;
my
$straight_join
=
$self
->_can_straight_join ?
'STRAIGHT_JOIN'
:
''
;
my
$sth
=
$self
->prepare(
qq(
SELECT ${straight_join} i.interpro_ac, x.description
FROM transcript t,
translation tl,
protein_feature pf,
interpro i,
xref x
WHERE t.stable_id = ?
AND tl.transcript_id = t.transcript_id
AND tl.translation_id = pf.translation_id
AND i.id = pf.hit_name
AND i.interpro_ac = x.dbprimary_acc
AND t.is_current = 1
)
);
$sth
->bind_param(1,
$trans_stable_id
, SQL_VARCHAR);
$sth
->execute();
my
@out
;
my
%h
;
while
( (
my
$arr
=
$sth
->fetchrow_arrayref()) ) {
if
(
$h
{
$arr
->[0]} ) {
next
; }
$h
{
$arr
->[0]}=1;
my
$string
=
$arr
->[0] .
":"
.
$arr
->[1];
push
(
@out
,
$string
);
}
return
\
@out
;
}
sub
is_Transcript_canonical {
my
(
$self
,
$transcript
) =
@_
;
return
$self
->dbc()->sql_helper()->execute_single_result(
-SQL
=>
'select count(*) from gene where canonical_transcript_id =?'
,
-PARAMS
=> [
$transcript
->dbID()]
);
}
sub
remove {
my
$self
=
shift
;
my
$transcript
=
shift
;
my
$update
=
shift
;
if
(!
ref
(
$transcript
) || !
$transcript
->isa(
'Bio::EnsEMBL::Transcript'
)) {
throw(
"Bio::EnsEMBL::Transcript argument expected"
);
}
if
(
$transcript
->isa(
'Bio::EnsEMBL::PredictionTranscript'
)) {
throw(
"TranscriptAdaptor can only remove Transcripts "
.
"not PredictionTranscripts"
);
}
if
( !
$transcript
->is_stored(
$self
->db()) ) {
warning(
"Cannot remove transcript "
.
$transcript
->dbID .
". Is not stored "
.
"in this database."
);
return
;
}
my
$prot_adp
=
$self
->db->get_ProteinAlignFeatureAdaptor;
my
$dna_adp
=
$self
->db->get_DnaAlignFeatureAdaptor;
my
$sfsth
=
$self
->prepare(
"SELECT feature_type, feature_id "
.
"FROM transcript_supporting_feature "
.
"WHERE transcript_id = ?"
);
$sfsth
->bind_param(1,
$transcript
->dbID, SQL_INTEGER);
$sfsth
->execute();
my
$sth1
=
$self
->prepare(
"SELECT count(*) FROM supporting_feature "
.
"WHERE feature_type = ? AND feature_id = ?"
);
my
$sth2
=
$self
->prepare(
"SELECT count(*) "
.
"FROM transcript_supporting_feature "
.
"WHERE feature_type = ? AND feature_id = ?"
);
SUPPORTING_FEATURE:
while
(
my
(
$type
,
$feature_id
) =
$sfsth
->fetchrow()){
$sth1
->bind_param(1,
$type
, SQL_VARCHAR);
$sth1
->bind_param(2,
$feature_id
, SQL_INTEGER);
$sth1
->execute;
$sth2
->bind_param(1,
$type
, SQL_VARCHAR);
$sth2
->bind_param(2,
$feature_id
, SQL_INTEGER);
$sth2
->execute;
my
(
$count1
) =
$sth1
->fetchrow;
my
(
$count2
) =
$sth2
->fetchrow;
if
(
$count1
+
$count2
> 1) {
next
SUPPORTING_FEATURE;
}
if
(
$type
eq
'protein_align_feature'
){
my
$f
=
$prot_adp
->fetch_by_dbID(
$feature_id
);
$prot_adp
->remove(
$f
);
}
elsif
(
$type
eq
'dna_align_feature'
){
my
$f
=
$dna_adp
->fetch_by_dbID(
$feature_id
);
$dna_adp
->remove(
$f
);
}
else
{
warning(
"Unknown supporting feature type $type. Not removing feature."
);
}
}
$sfsth
->finish();
$sth1
->finish();
$sth2
->finish();
$sfsth
=
$self
->prepare(
"DELETE FROM transcript_supporting_feature WHERE transcript_id = ?"
);
$sfsth
->bind_param(1,
$transcript
->dbID, SQL_INTEGER);
$sfsth
->execute();
$sfsth
->finish();
my
$ise_adaptor
=
$self
->db->get_IntronSupportingEvidenceAdaptor();
foreach
my
$ise
(@{
$transcript
->get_all_IntronSupportingEvidence()}) {
$ise_adaptor
->remove_transcript_linkage(
$ise
,
$transcript
);
if
(!
$ise
->has_linked_transcripts()) {
$ise_adaptor
->remove(
$ise
);
}
}
my
$dbeAdaptor
=
$self
->db->get_DBEntryAdaptor();
foreach
my
$dbe
(@{
$transcript
->get_all_DBEntries}) {
$dbeAdaptor
->remove_from_object(
$dbe
,
$transcript
,
'Transcript'
);
}
my
$attrib_adp
=
$self
->db->get_AttributeAdaptor;
$attrib_adp
->remove_from_Transcript(
$transcript
);
my
$translationAdaptor
=
$self
->db->get_TranslationAdaptor();
if
(
defined
(
$transcript
->translation()) ) {
$translationAdaptor
->remove(
$transcript
->translation );
}
my
$exonAdaptor
=
$self
->db->get_ExonAdaptor();
foreach
my
$exon
( @{
$transcript
->get_all_Exons()} ) {
my
$sth
=
$self
->prepare( "SELECT count(*)
FROM exon_transcript
WHERE exon_id = ?" );
$sth
->bind_param(1,
$exon
->dbID, SQL_INTEGER);
$sth
->execute();
my
(
$count
) =
$sth
->fetchrow_array();
$sth
->finish();
if
(
$count
== 1){
$exonAdaptor
->remove(
$exon
);
}
}
my
$sth
=
$self
->prepare( "DELETE FROM exon_transcript
WHERE transcript_id = ?" );
$sth
->bind_param(1,
$transcript
->dbID, SQL_INTEGER);
$sth
->execute();
$sth
->finish();
my
$gene
=
$transcript
->get_Gene;
$sth
=
$self
->prepare( "DELETE FROM transcript
WHERE transcript_id = ?" );
$sth
->bind_param(1,
$transcript
->dbID, SQL_INTEGER);
$sth
->execute();
$sth
->finish();
if
(
$update
) {
$gene
->remove_Transcript(
$transcript
);
}
$transcript
->dbID(
undef
);
$transcript
->adaptor(
undef
);
return
;
}
sub
update {
my
(
$self
,
$transcript
) =
@_
;
if
( !
defined
(
$transcript
)
|| !
ref
(
$transcript
)
|| !
$transcript
->isa(
'Bio::EnsEMBL::Transcript'
) )
{
throw(
"Must update a transcript object, not a $transcript"
);
}
my
$update_transcript_sql
=
sprintf
"UPDATE transcript SET stable_id = ?, analysis_id = ?, display_xref_id = ?, description = ?,%s biotype = ?, is_current = ?, canonical_translation_id = ?, version = ? WHERE transcript_id = ?"
, (
$self
->schema_version > 74)?
" source = ?,"
:
''
;
my
$display_xref
=
$transcript
->display_xref();
my
$display_xref_id
;
if
(
defined
(
$display_xref
) &&
$display_xref
->dbID() ) {
$display_xref_id
=
$display_xref
->dbID();
}
else
{
$display_xref_id
=
undef
;
}
my
$sth
=
$self
->prepare(
$update_transcript_sql
);
my
$i
= 0;
$sth
->bind_param( ++
$i
,
$transcript
->stable_id(), SQL_VARCHAR );
$sth
->bind_param( ++
$i
,
$transcript
->analysis()->dbID(), SQL_INTEGER );
$sth
->bind_param( ++
$i
,
$display_xref_id
, SQL_INTEGER );
$sth
->bind_param( ++
$i
,
$transcript
->description(), SQL_LONGVARCHAR );
$self
->schema_version > 74 and
$sth
->bind_param( ++
$i
,
$transcript
->source(), SQL_VARCHAR );
$sth
->bind_param( ++
$i
,
$transcript
->get_Biotype->name, SQL_VARCHAR );
$sth
->bind_param( ++
$i
,
$transcript
->is_current(), SQL_TINYINT );
$sth
->bind_param( ++
$i
, (
defined
(
$transcript
->translation() )
?
$transcript
->translation()->dbID()
:
undef
),
SQL_INTEGER );
$sth
->bind_param( ++
$i
,
$transcript
->version(), SQL_INTEGER );
$sth
->bind_param( ++
$i
,
$transcript
->dbID(), SQL_INTEGER );
$sth
->execute();
if
(
$transcript
->is_canonical()) {
my
$gene
=
$transcript
->get_Gene();
my
$gene_adaptor
=
$self
->db()->get_GeneAdaptor();
$gene
->canonical_transcript(
$transcript
);
$gene_adaptor
->update(
$gene
);
}
}
sub
list_dbIDs {
my
(
$self
,
$ordered
) =
@_
;
return
$self
->_list_dbIDs(
"transcript"
,
undef
,
$ordered
);
}
sub
list_stable_ids {
my
(
$self
) =
@_
;
return
$self
->_list_dbIDs(
"transcript"
,
"stable_id"
);
}
sub
_objs_from_sth {
my
(
$self
,
$sth
,
$mapper
,
$dest_slice
) =
@_
;
my
$sa
=
$self
->db()->get_SliceAdaptor();
my
$aa
=
$self
->db()->get_AnalysisAdaptor();
my
$dbEntryAdaptor
=
$self
->db()->get_DBEntryAdaptor();
my
@transcripts
;
my
%analysis_hash
;
my
%slice_hash
;
my
%sr_name_hash
;
my
%sr_cs_hash
;
my
(
$transcript_id
,
$seq_region_id
,
$seq_region_start
,
$seq_region_end
,
$seq_region_strand
,
$analysis_id
,
$gene_id
,
$is_current
,
$stable_id
,
$version
,
$created_date
,
$modified_date
,
$description
,
$biotype
,
$external_db
,
$external_status
,
$external_db_name
,
$display_xref_id
,
$xref_display_label
,
$xref_primary_acc
,
$xref_version
,
$xref_description
,
$xref_info_type
,
$xref_info_text
,
$external_release
,
$source
);
if
(
$self
->schema_version() > 74) {
$sth
->bind_columns(
\(
$transcript_id
,
$seq_region_id
,
$seq_region_start
,
$seq_region_end
,
$seq_region_strand
,
$analysis_id
,
$gene_id
,
$is_current
,
$stable_id
,
$version
,
$created_date
,
$modified_date
,
$description
,
$biotype
,
$external_db
,
$external_status
,
$external_db_name
,
$display_xref_id
,
$xref_display_label
,
$xref_primary_acc
,
$xref_version
,
$xref_description
,
$xref_info_type
,
$xref_info_text
,
$external_release
,
$source
) );
}
else
{
$sth
->bind_columns(
\(
$transcript_id
,
$seq_region_id
,
$seq_region_start
,
$seq_region_end
,
$seq_region_strand
,
$analysis_id
,
$gene_id
,
$is_current
,
$stable_id
,
$version
,
$created_date
,
$modified_date
,
$description
,
$biotype
,
$external_db
,
$external_status
,
$external_db_name
,
$display_xref_id
,
$xref_display_label
,
$xref_primary_acc
,
$xref_version
,
$xref_description
,
$xref_info_type
,
$xref_info_text
,
$external_release
) );
}
my
$dest_slice_start
;
my
$dest_slice_end
;
my
$dest_slice_strand
;
my
$dest_slice_length
;
my
$dest_slice_cs
;
my
$dest_slice_sr_name
;
my
$dest_slice_sr_id
;
my
$asma
;
if
(
$dest_slice
) {
$dest_slice_start
=
$dest_slice
->start();
$dest_slice_end
=
$dest_slice
->end();
$dest_slice_strand
=
$dest_slice
->strand();
$dest_slice_length
=
$dest_slice
->
length
();
$dest_slice_cs
=
$dest_slice
->coord_system();
$dest_slice_sr_name
=
$dest_slice
->seq_region_name();
$dest_slice_sr_id
=
$dest_slice
->get_seq_region_id();
$asma
=
$self
->db->get_AssemblyMapperAdaptor();
}
FEATURE:
while
(
$sth
->fetch()) {
my
$analysis
=
$analysis_hash
{
$analysis_id
} ||=
$aa
->fetch_by_dbID(
$analysis_id
);
$analysis_hash
{
$analysis_id
} =
$analysis
;
$seq_region_id
=
$self
->get_seq_region_id_internal(
$seq_region_id
);
my
$slice
=
$slice_hash
{
"ID:"
.
$seq_region_id
};
if
(!
$slice
) {
$slice
=
$sa
->fetch_by_seq_region_id(
$seq_region_id
);
$slice_hash
{
"ID:"
.
$seq_region_id
} =
$slice
;
$sr_name_hash
{
$seq_region_id
} =
$slice
->seq_region_name();
$sr_cs_hash
{
$seq_region_id
} =
$slice
->coord_system();
}
if
(!
$mapper
&&
$dest_slice
&& !
$dest_slice_cs
->equals(
$slice
->coord_system)) {
$mapper
=
$asma
->fetch_by_CoordSystems(
$dest_slice_cs
,
$slice
->coord_system);
}
my
$sr_name
=
$sr_name_hash
{
$seq_region_id
};
my
$sr_cs
=
$sr_cs_hash
{
$seq_region_id
};
if
(
$mapper
) {
if
(
defined
$dest_slice
&&
$mapper
->isa(
'Bio::EnsEMBL::ChainedAssemblyMapper'
) ) {
(
$seq_region_id
,
$seq_region_start
,
$seq_region_end
,
$seq_region_strand
) =
$mapper
->
map
(
$sr_name
,
$seq_region_start
,
$seq_region_end
,
$seq_region_strand
,
$sr_cs
, 1,
$dest_slice
);
}
else
{
(
$seq_region_id
,
$seq_region_start
,
$seq_region_end
,
$seq_region_strand
) =
$mapper
->fastmap(
$sr_name
,
$seq_region_start
,
$seq_region_end
,
$seq_region_strand
,
$sr_cs
);
}
next
FEATURE
if
(!
defined
(
$seq_region_id
));
$slice
=
$slice_hash
{
"ID:"
.
$seq_region_id
} ||=
$sa
->fetch_by_seq_region_id(
$seq_region_id
);
}
if
(
defined
(
$dest_slice
)) {
my
$seq_region_len
=
$dest_slice
->seq_region_length();
if
(
$dest_slice_strand
== 1 ) {
$seq_region_start
=
$seq_region_start
-
$dest_slice_start
+ 1;
$seq_region_end
=
$seq_region_end
-
$dest_slice_start
+ 1;
if
(
$dest_slice
->is_circular ) {
if
(
$seq_region_start
>
$seq_region_end
) {
if
(
$seq_region_end
>
$dest_slice_start
) {
$seq_region_start
-=
$seq_region_len
;
}
if
(
$seq_region_end
< 0 ) {
$seq_region_end
+=
$seq_region_len
;
}
}
else
{
if
(
$dest_slice_start
>
$dest_slice_end
&&
$seq_region_end
< 0) {
$seq_region_start
+=
$seq_region_len
;
$seq_region_end
+=
$seq_region_len
;
}
}
}
}
else
{
my
$start
=
$dest_slice_end
-
$seq_region_end
+ 1;
my
$end
=
$dest_slice_end
-
$seq_region_start
+ 1;
if
(
$dest_slice
->is_circular()) {
if
(
$dest_slice_start
>
$dest_slice_end
) {
if
(
$seq_region_start
>=
$dest_slice_start
) {
$end
+=
$seq_region_len
;
$start
+=
$seq_region_len
if
$seq_region_end
>
$dest_slice_start
;
}
elsif
(
$seq_region_start
<=
$dest_slice_end
) {
}
elsif
(
$seq_region_end
>=
$dest_slice_start
) {
$start
+=
$seq_region_len
;
$end
+=
$seq_region_len
;
}
elsif
(
$seq_region_end
<=
$dest_slice_end
) {
$end
+=
$seq_region_len
if
$end
< 0;
}
elsif
(
$seq_region_start
>
$seq_region_end
) {
$end
+=
$seq_region_len
;
}
}
else
{
if
(
$seq_region_start
<=
$dest_slice_end
and
$seq_region_end
>=
$dest_slice_start
) {
}
elsif
(
$seq_region_start
>
$seq_region_end
) {
if
(
$seq_region_start
<=
$dest_slice_end
) {
$start
-=
$seq_region_len
;
}
elsif
(
$seq_region_end
>=
$dest_slice_start
) {
$end
+=
$seq_region_len
;
}
}
}
}
$seq_region_start
=
$start
;
$seq_region_end
=
$end
;
$seq_region_strand
*= -1;
}
if
(
$seq_region_end
< 1
||
$seq_region_start
>
$dest_slice_length
|| (
$dest_slice_sr_id
!=
$seq_region_id
)) {
next
FEATURE;
}
$slice
=
$dest_slice
;
}
my
$display_xref
;
if
(
$display_xref_id
) {
$display_xref
= Bio::EnsEMBL::DBEntry->new_fast( {
'dbID'
=>
$display_xref_id
,
'adaptor'
=>
$dbEntryAdaptor
,
'display_id'
=>
$xref_display_label
,
'primary_id'
=>
$xref_primary_acc
,
'version'
=>
$xref_version
,
'description'
=>
$xref_description
,
'release'
=>
$external_release
,
'dbname'
=>
$external_db
,
'db_display_name'
=>
$external_db_name
,
'info_type'
=>
$xref_info_type
,
'info_text'
=>
$xref_info_text
});
$display_xref
->status(
$external_status
);
}
my
$params
=
{
'analysis'
=>
$analysis
,
'biotype'
=>
$biotype
,
'start'
=>
$seq_region_start
,
'end'
=>
$seq_region_end
,
'strand'
=>
$seq_region_strand
,
'adaptor'
=>
$self
,
'slice'
=>
$slice
,
'dbID'
=>
$transcript_id
,
'stable_id'
=>
$stable_id
,
'version'
=>
$version
,
'created_date'
=>
$created_date
||
undef
,
'modified_date'
=>
$modified_date
||
undef
,
'description'
=>
$description
,
'external_name'
=>
$xref_display_label
,
'external_status'
=>
$external_status
,
'external_display_name'
=>
$external_db_name
,
'external_db'
=>
$external_db
,
'display_xref'
=>
$display_xref
,
'is_current'
=>
$is_current
,
'edits_enabled'
=> 1
};
$self
->schema_version > 74 and
$params
->{
'source'
} =
$source
;
push
(
@transcripts
,
$self
->_create_feature_fast(
'Bio::EnsEMBL::Transcript'
,
$params
) );
}
return
\
@transcripts
;
}
sub
fetch_all_by_exon_supporting_evidence {
my
(
$self
,
$hit_name
,
$feature_type
,
$analysis
) =
@_
;
if
(
$feature_type
!~ /(dna)|(protein)_align_feature/) {
throw(
"feature type must be dna_align_feature or protein_align_feature"
);
}
my
$anal_from
=
""
;
$anal_from
=
", analysis a "
if
(
$analysis
);
my
$anal_where
=
""
;
$anal_where
=
"AND a.analysis_id = f.analysis_id AND a.analysis_id=? "
if
(
$analysis
);
my
$sql
=
qq(
SELECT DISTINCT(t.transcript_id)
FROM transcript t,
exon_transcript et,
supporting_feature sf,
$feature_type
f
$anal_from
WHERE t.transcript_id = et.transcript_id
AND t.is_current = 1
AND et.exon_id = sf.exon_id
AND sf.feature_id = f.${feature_type}_id
AND sf.feature_type = ?
AND f.hit_name=?
$anal_where
);
my
$sth
=
$self
->prepare(
$sql
);
$sth
->bind_param(1,
$feature_type
, SQL_VARCHAR);
$sth
->bind_param(2,
$hit_name
, SQL_VARCHAR);
$sth
->bind_param(3,
$analysis
->dbID(), SQL_INTEGER)
if
(
$analysis
);
$sth
->execute();
my
@transcripts
;
while
(
my
$id
=
$sth
->fetchrow_array ) {
my
$transcript
=
$self
->fetch_by_dbID(
$id
);
push
(
@transcripts
,
$transcript
)
if
$transcript
;
}
return
\
@transcripts
;
}
sub
fetch_all_by_transcript_supporting_evidence {
my
(
$self
,
$hit_name
,
$feature_type
,
$analysis
) =
@_
;
if
(
$feature_type
!~ /(dna)|(protein)_align_feature/) {
throw(
"feature type must be dna_align_feature or protein_align_feature"
);
}
my
$anal_from
=
""
;
$anal_from
=
", analysis a "
if
(
$analysis
);
my
$anal_where
=
""
;
$anal_where
=
"AND a.analysis_id = f.analysis_id AND a.analysis_id=? "
if
(
$analysis
);
my
$sql
=
qq(
SELECT DISTINCT(t.transcript_id)
FROM transcript t,
transcript_supporting_feature sf,
$feature_type
f
$anal_from
WHERE t.transcript_id = sf.transcript_id
AND t.is_current = 1
AND sf.feature_id = f.${feature_type}_id
AND sf.feature_type = ?
AND f.hit_name=?
$anal_where
);
my
$sth
=
$self
->prepare(
$sql
);
$sth
->bind_param(1,
$feature_type
, SQL_VARCHAR);
$sth
->bind_param(2,
$hit_name
, SQL_VARCHAR);
$sth
->bind_param(3,
$analysis
->dbID(), SQL_INTEGER)
if
(
$analysis
);
$sth
->execute();
my
@transcripts
;
while
(
my
$id
=
$sth
->fetchrow_array ) {
my
$transcript
=
$self
->fetch_by_dbID(
$id
);
push
(
@transcripts
,
$transcript
)
if
$transcript
;
}
return
\
@transcripts
;
}
sub
_final_clause {
return
' ORDER BY t.transcript_id'
}
sub
update_canonical_attribute {
my
(
$self
,
$transcript_id
,
$old_transcript_id
) =
@_
;
my
$db
=
$self
->db();
my
$attr_adaptor
=
$db
->get_AttributeAdaptor();
my
$canonical_attrib_id
= @{
$attr_adaptor
->fetch_by_code(
'is_canonical'
)}[0];
throw(
"No attrib_type_id found for 'is_canonical' attribute in attrib_type table."
)
if
(!
defined
(
$canonical_attrib_id
));
my
$sth
=
$self
->prepare(
"SELECT value FROM transcript_attrib WHERE transcript_id=? AND attrib_type_id=?"
);
$sth
->execute(
$transcript_id
,
$canonical_attrib_id
);
if
(
my
(
$exists
) =
$sth
->fetchrow_array()) {
$sth
->finish();
$sth
=
$self
->prepare(
"UPDATE transcript_attrib SET value=? WHERE transcript_id=? AND attrib_type_id=?"
);
$sth
->execute(
'1'
,
$transcript_id
,
$canonical_attrib_id
);
}
else
{
$sth
->finish();
$sth
=
$self
->prepare(
"INSERT INTO transcript_attrib (transcript_id, attrib_type_id, value) values(?,?,?)"
);
$sth
->execute(
$transcript_id
,
$canonical_attrib_id
,
'1'
);
}
$sth
->finish();
if
(
defined
(
$old_transcript_id
) &&
$old_transcript_id
ne
$transcript_id
) {
$sth
=
$self
->prepare(
"DELETE FROM transcript_attrib WHERE transcript_id=? AND attrib_type_id=?"
);
$sth
->execute(
$old_transcript_id
,
$canonical_attrib_id
);
$sth
->finish();
}
}
1;