Privates (from "my" definitions)
%fkey = ( "cvterm.cv_id" => "cv", "dbxref.db_id" => "db", "feature.type_id" => "cvterm", "feature.organism_id" => "organism", "feature.dbxref_id" => "dbxref", "featureprop.type_id" => "cvterm", "feature_pub.pub_id" => "pub", "feature_cvterm.cvterm_id" => "cvterm", "feature_cvterm.pub_id" => "pub", "feature_dbxref.dbxref_id" => "dbxref", "feature_relationship.object_id" => "feature", "feature_relationship.subject_id" => "feature", "feature_relationship.type_id" => "cvterm", "featureloc.srcfeature_id" => "feature", "pub.type_id" => "cvterm", "pub_dbxref.dbxref_id" => "dbxref", "pub_author.author_id" => "author", "pub_relationship.obj_pub_id" => "pub", "pub_relationship.subj_pub_id" => "pub", "pub_relationship.type_id" => "cvterm", "pubprop.type_id" => "cvterm",)
%feattype_args2so = ( "aberr" => "aberration_junction", "variation" => "sequence_variant", "mutation1" => "point_mutation", "mutation2" => "sequence_variant", "rescue" => "rescue_fragment", "protein_bind" => "protein_binding_site", "misc_feature" => "region", "CDS" => "protein", "reg_element" => "regulatory_region", "seq_variant" => "sequence_variant",)
$chadotables = 'feature featureprop feature_relationship featureloc feature_cvterm cvterm cv feature_pub pub pub_dbxref pub_author author pub_relationship pubprop feature_dbxref dbxref db'
This object can transform Bio::Seq objects to and from chadoxml flat
file databases (for chadoxml DTD, see
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/gmod/schema/chado/dat/chado.dtd).
CURRENTLY ONLY TO
$seqio = Bio::SeqIO->new(-file => '>outfile.xml', -format => 'chadoxml');
#we have a Bio::Seq object $seq which is a gene located on chromosome arm 'X', to be
#written out to chadoxml
#before converting to chadoxml, $seq object must be transformed so that
#all the coordinates in $seq are against the source feature to be passed
#into Bio::SeqIO::chadoxml->write_seq() -- chromosome arm X in the example
#below.
$seqio->write_seq(-seq=>$seq, -seq_so_type=>'gene',
-src_feature=>'X', -src_feat_type=>'chromosome_arm');
The chadoxml output of
Bio::SeqIO::chadoxml->write_seq() method can be
passed to the loader utility in XORT package
(
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/gmod/schema/XMLTools/XORT/)
to be loaded into chado.
This object is currently implemented to work with sequence and
annotation data from whole genome projects deposited in GenBank. It
may not be able to handle all different types of data from all
different sources.
In converting a Bio::Seq object into chadoxml, a top-level feature is
created to represent the object and all sequence features inside the
Bio::Seq object are treated as subfeatures of the top-level
feature. The
Bio::SeqIO::chadoxml object calls
Bio::SeqFeature::Tools::Unflattener to unflatten the flat feature list
contained in the subject Bio::Seq object, to build gene model
containment hierarchy conforming to chado central dogma model: gene
--> mRNA --> exons and protein.
Destination of data in the subject Bio::Seq object $seq is as following:
*$seq->display_id: name of the top-level feature;
*$seq->accession_number: if defined, uniquename and
feature_dbxref of the top-level
feature if not defined,
$seq->display_id is used as the
uniquename of the top-level feature;
*$seq->molecule: transformed to SO type, used as the feature
type of the top-level feature if -seq_so_type
argument is supplied, use the supplied SO type
as the feature type of the top-level feature;
*$seq->species: organism of the top-level feature;
*$seq->seq: residues of the top-level feature;
*$seq->is_circular, $seq->division: feature_cvterm;
*$seq->keywords, $seq->desc, comments: featureprop;
*references: pub and feature_pub;
medline/pubmed id's: pub_dbxref;
comments: pubprop;
*feature "source" span: featureloc for top-level feature;
*feature "source" db_xref: feature_dbxref for top-level feature;
*feature "source" other tags: featureprop for top-level feature;
*subfeature 'symbol' or 'label' tag: feature uniquename, if
none of these is present, the chadoxml object
generates feature uniquenames as:
--
(e.g. foo-mRNA--1000..3000);
*gene model: feature_relationship built based on the
containment hierarchy;
*feature span: featureloc;
*feature accession numbers: feature_dbxref;
*feature tags (except db_xref, symbol and gene): featureprop;
Things to watch out for:
*chado schema change: this version works with the chado
version tagged chado_1_01 in GMOD CVS.
*feature uniquenames: especially important if using XORT
loader to do incremental load into
chado. may need pre-processing of the
source data to put the correct
uniquenames in place.
*pub uniquenames: chadoxml->write_seq() has the FlyBase policy
on pub uniquenames hard-coded, it assigns
pub uniquenames in the following way: for
journals and books, use ISBN number; for
published papers, use MEDLINE ID; for
everything else, use FlyBase unique
identifier FBrf#. need to modify the code to
implement your policy. look for the comments
in the code.
*for pubs possibly existing in chado but with no knowledge of
its uniquename:put "op" as "match", then need to run the
output chadoxml through a special filter that
talks to chado database and tries to find the
pub by matching with the provided information
instead of looking up by the unique key. after
matching, the filter also resets the "match"
operation to either "force" (default), or
"lookup", or "insert", or "update". the
"match" operation is for a special FlyBase use
case. please modify to work according to your
rules.
*chado initialization for loading:
cv & cvterm: in the output chadoxml, all cv's and
cvterm's are lookup only. Therefore,
before using XORT loader to load the
output into chado, chado must be
pre-loaded with all necessary CVs and
CVterms, including "SO" , "property
type", "relationship type", "pub type",
"pubprop type", "pub relationship type",
"sequence topology", "GenBank feature
qualifier", "GenBank division". A pub by
the uniquename 'nullpub' of type 'null
pub' needs to be inserted.
sub write_seq
{ my $usage = <<EOUSAGE Bio::SeqIO::chadoxml->write_seq() Usage : \$stream->write_seq(-seq=>\$seq, -seq_so_type=>\$SOtype, -src_feature=>\$srcfeature, -src_feat_type=>\$srcfeattype) Args : \$seq : a Bio::Seq object \$SOtype : the SO term to use as the feature type of the \$seq record, optional \$srcfeature : unique name of the source feature, a string containing at least one alphabetical letter (a-z, A-Z), optional \$srcfeattype : feature type of \$srcfeature. one of SO terms. optional when \$srcfeature is given, \$srcfeattype becomes mandatory, EOUSAGE
my ($self,@args) = @_;
my ($seq, $seq_so_type, $srcfeature, $srcfeattype) =
$self->_rearrange([qw(SEQ
SEQ_SO_TYPE
SRC_FEATURE
SRC_FEAT_TYPE
)],
@args);
if( !defined $seq ) {
$self->throw("Attempting to write with no seq!");
}
if( ! ref $seq || ! $seq->isa('Bio::Seq::RichSeqI') ) {
$self->warn(" $seq is not a RichSeqI compliant module. Attempting to dump, but may fail!");
}
if (defined $srcfeature)
{
if ($srcfeature =~ /[a-zA-Z]/)
{
chomp($srcfeature);
} else {
$self->throw( $usage );
}
if (! defined $srcfeattype)
{
$self->throw( $usage );
} else {
if ($srcfeattype =~ /\S+/) {
chomp($srcfeattype);
} else {
$self->throw( $usage );
}
}
}
my $div = undef;
my $hkey = undef;
undef(my @top_featureprops);
my $name = $seq->display_id;
undef(my @feature_cvterms);
undef(my %sthash);
undef(my %dvhash);
undef(my %h1);
undef(my %h2);
my $temp = undef;
my $ann = undef;
undef(my @references);
undef(my @feature_pubs);
my $ref = undef;
my $location = undef;
my $fbrf = undef;
my $journal = undef;
my $issue = undef;
my $volume = undef;
my $volumeissue = undef;
my $pages = undef;
my $year = undef;
my $pubtype = undef;
my $uniquename = undef;
my $refhash = undef;
my $feat = undef;
my $tag = undef;
my $ftype = undef;
my $subfeatcnt = undef;
undef(my @top_featrels);
undef (my %srcfhash);
local($^W) = 0;
if ($seq->can('accession_number') && defined $seq->accession_number) {
$uniquename = $seq->accession_number;
} elsif ($seq->can('accession') && defined $seq->accession) {
$uniquename = $seq->accession;
} else {
$uniquename = $name;
}
my $len = $seq->length();
undef(my $gb_type);
if (!$seq->can('molecule') || ! defined ($gb_type = $seq->molecule()) ) {
$gb_type = $seq->alphabet || 'DNA';
}
$gb_type = 'DNA' if $ftype eq 'dna';
$gb_type = 'RNA' if $ftype eq 'rna';
if (defined $seq_so_type) {
$ftype = $seq_so_type;
}
else {
$ftype = $gb_type;
}
my %ftype_hash = ( "name" => $ftype, "cv_id" => {"name" => 'SO'});
my $spec = $seq->species();
if (!defined $spec) {
$self->throw("$seq does not know what organism it is from, which is required by chado. cannot proceed!\n");
} else {
%organism = ("genus"=>$spec->genus(), "species" => $spec->species());
}
my $residues = $seq->seq || '';
%datahash = (
"name" => $name,
"uniquename" => $uniquename,
"seqlen" => $len,
"residues" => $residues,
"type_id" =>\% ftype_hash,
"organism_id" =>\% organism,
);
if (!defined $srcfeature) {
$srcfeature = $uniquename;
$srcfeattype = $ftype;
}
if ($seq->is_circular) {
%sthash = (
"cvterm_id" => {'name' => 'circular',
'cv_id' => {
'name' => 'sequence topology',
},
},
"pub_id" => {'miniref' => 'nullpub',
'type_id' => {
'name' => 'null pub',
'cv_id' => {
'name'=> 'pub type',
},
},
},
);
} else {
%sthash = (
"cvterm_id" => { 'name' => 'linear',
'cv_id' => {
'name' => 'sequence topology',
}
},
"pub_id" => {'miniref' => 'nullpub',
'type_id' => {
'name' => 'null pub',
'cv_id' => {
'name'=> 'pub type',
},
},
},
);
}
push(@feature_cvterms,\% sthash);
if ($seq->can('division') && defined $seq->division()) {
$div = $seq->division();
%dvhash = (
"cvterm_id" => {'name' => $div,
'cv_id' => {
'name' => 'GenBank division'}},
"pub_id" => {'miniref' => 'nullpub',
'type_id' => {
'name' => 'null pub',
'cv_id' => {
'name'=> 'pub type'},
}},
);
push(@feature_cvterms,\% dvhash);
}
$datahash{'feature_cvterm'} =\@ feature_cvterms;
if ($seq->can('desc') && defined $seq->desc()) {
$temp = $seq->desc();
my %prophash = (
"type_id" => {'name' => 'description',
'cv_id' => {
'name' => 'property type'}},
"value" => $temp,
);
push(@top_featureprops,\% prophash);
}
if ($seq->can('keywords')) {
$temp = $seq->keywords();
if (defined $temp && $temp ne '.' && $temp ne '') {
my %prophash = (
"type_id" => {'name' => 'keywords',
'cv_id' =>
{'name' => 'property type'}
},
"value" => $temp,
);
push(@top_featureprops,\% prophash);
}
}
if ($seq->can('annotation')) {
$ann = $seq->annotation();
foreach my $comment ($ann->get_Annotations('comment')) {
$temp = $comment->as_text();
my %prophash = (
"type_id" => {'name' => 'comment',
'cv_id' =>
{'name' => 'property type'}},
"value" => $temp,
);
push(@top_featureprops,\% prophash);
}
}
my @top_dbxrefs = ();
if ($seq->can('accession_number') && defined $seq->accession_number) {
my $db = $self->_guess_acc_db($seq, $seq->accession_number);
my %acchash = (
"db_id" => {'name' => $db},
"accession" => $seq->accession_number,
"version" => $seq->seq_version,
);
my %fdbx = ('dbxref_id' =>\% acchash);
push(@top_dbxrefs,\% fdbx);
}
if( $seq->isa('Bio::Seq::RichSeqI') && defined $seq->get_secondary_accessions() ) {
my @secacc = $seq->get_secondary_accessions();
my $acc;
foreach $acc (@secacc) {
my %acchash = (
"db_id" => {'name' => 'GB'},
"accession" => $acc,
);
my %fdbx = ('dbxref_id' =>\% acchash);
push(@top_dbxrefs,\% fdbx);
}
}
if( $seq->isa('Bio::Seq::RichSeqI') && defined ($seq->pid)) {
my $id = $seq->pid;
my %acchash = (
"db_id" => {'name' => 'GI'},
"accession" => $id,
);
my %fdbx = ('dbxref_id' =>\% acchash);
push (@top_dbxrefs,\% fdbx);
}
if (defined $ann) {
@references = $ann->get_Annotations('reference');
foreach $ref (@references) {
undef(my %pubhash);
$refhash = $ref->hash_tree();
$location = $ref->location || $refhash->{'location'};
if (index($location, ' ==') >= 0) {
$location =~ /\s==/;
$fbrf = $PREMATCH;
$location = $POSTMATCH;
$location =~ s/^\s//;
}
if ($location =~ /Unpublished/) {
$pubtype = 'unpublished';
%pubhash = (
"title" => $ref->title || $refhash->{'title'},
"type_id" => {'name' => $pubtype, 'cv_id' => {'name' =>'pub type'}}
);
}
elsif ($location =~ /Submitted/) {
$pubtype = 'submitted';
%pubhash = (
"title" => $ref->title || $refhash->{'title'},
"type_id" => {'name' => $pubtype, 'cv_id' => {'name' =>'pub type'}}
);
undef(my $pyear);
$pyear = $self->_getSubmitYear($location);
if (defined $pyear) {
$pubhash{'pyear'} = $pyear;
}
}
elsif ($location =~ /\D+\s\d+\s\((\d+|\d+-\d+)\),\s(\d+-\d+|\d+--\d+)\s\(\d\d\d\d\)$/) {
$pubtype = 'paper';
$location =~ /\(\d\d\d\d\)$/;
$year = $MATCH;
my $stuff = $PREMATCH;
$year =~ s/\(//; $year =~ s/\)//;
$stuff =~ /,\s(\d+-\d+|\d+--\d+)\s$/;
$pages = $MATCH;
$stuff = $PREMATCH;
$pages =~ s/^, //; $pages =~ s/ $//;
$stuff =~ /\s\d+\s\((\d+|\d+-\d+)\)$/;
$volumeissue = $MATCH;
$journal = $PREMATCH;
$volumeissue =~ s/^ //; $volumeissue =~ /\((\d+|\d+-\d+)\)$/;
$issue = $MATCH;
$volume = $PREMATCH;
$issue =~ s/^\(//; $issue =~ s/\)$//; $volume =~ s/^\s//; $volume =~ s/\s$//;
%pubhash = (
"title" => $ref->title || $refhash->{'title'},
"volume" => $volume,
"issue" => $issue,
"pyear" => $year,
"pages" => $pages,
"type_id" => {'name' => $pubtype, 'cv_id' => {'name' =>'pub type'}},
"pub_relationship" => {
'obj_pub_id' => {
'uniquename' => $journal,
'title' => $journal,
'type_id' =>{'name' => 'journal',
'cv_id' =>
{'name' => 'pub type'
},
},
},
'type_id' => {
'name' => 'published_in',
'cv_id' => {
'name' => 'pub relationship type'},
},
},
);
}
else {
$pubtype = 'other';
%pubhash = (
"title" => $ref->title || $refhash->{'title'},
"type_id" => {
'name' => $pubtype,
'cv_id' => {'name' =>'pub type'}
}
);
}
my $autref = $self->_getRefAuthors($ref);
if (defined $autref) {
$pubhash{'pub_author'} = $autref;
}
else {
if ($pubtype eq 'submitted') {
my $autref = $self->_getSubmitAddr($ref);
if (defined $autref) {
$pubhash{'pub_author'} = $autref;
}
}
}
if (defined $ref->comment || defined $refhash->{'comment'}) {
my $comnt = $ref->comment || $refhash->{'comment'};
$pubhash{'pubprop'} = {
"type_id" => {'name' => 'comment', 'cv_id' => {'name' => 'pubprop type'}},
"value" => $comnt,
};
}
undef(my @pub_dbxrefs);
if (defined $fbrf) {
push(@pub_dbxrefs, {dbxref_id => {accession => $fbrf, db_id => {'name' => 'FlyBase'}}});
}
if (defined ($temp = $ref->medline)) {
push(@pub_dbxrefs, {dbxref_id => {accession => $temp, db_id => {'name' => 'MEDLINE'}}});
$pubhash{'uniquename'} = $temp;
}
if (defined ($temp = $ref->pubmed)) {
push(@pub_dbxrefs, {dbxref_id => {accession => $temp, db_id => {'name' => 'PUBMED'}}});
}
$pubhash{'pub_dbxref'} =\@ pub_dbxrefs;
if (!defined $pubhash{'uniquename'} || $pubhash{'uniquename'} eq '') {
if (defined $fbrf) {
$pubhash{'uniquename'} = $fbrf;
}
}
if (($ref->start == 1 && $ref->end == $len) || (!defined $ref->start && !defined $ref->end)) {
push(@feature_pubs, {"pub_id" =>\% pubhash});
}
else {
my %parf = (
'uniquename' => $uniquename . ':' . $ref->start . "\.\." . $ref->end,
'organism_id' =>\%organism,
'type_id' =>{'name' =>'region', 'cv_id' => {'name' => 'SO'}},
);
my %parfsrcf = (
'uniquename' => $uniquename,
'organism_id' =>\%organism,
);
my %parfloc = (
'srcfeature_id' =>\% parfsrcf,
'fmin' => $ref->start - 1,
'fmax' => $ref->end,
);
$parf{'featureloc'} =\% parfloc;
$parf{'feature_pub'} = {'pub_id' =>\% pubhash};
my %ffr = (
'subject_id' =>\% parf,
'type_id' => { 'name' => 'partof', 'cv_id' => { 'name' => 'relationship type'}},
);
push(@top_featrels,\% ffr);
}
}
$datahash{'feature_pub'} =\@ feature_pubs;
}
if (defined $srcfeature) {
%srcfhash = ('uniquename' => $srcfeature,
'organism_id' =>\% organism,
'type_id' => {'name' => $srcfeattype, 'cv_id' => {'name' => 'SO'}},
);
}
if ($gb_type eq 'gene' || $gb_type eq 'DNA') {
my $u = Bio::SeqFeature::Tools::Unflattener->new;
$u->unflatten_seq(-seq=>$seq, -use_magic=>1);
}
my @top_sfs = $seq->get_SeqFeatures;
my $si = 0;
foreach $feat (@top_sfs) {
my $prim_tag = $feat->primary_tag;
if ($prim_tag eq 'source') {
foreach $tag ($feat->all_tags()) {
if ($tag eq 'db_xref') {
my @t1 = $feat->each_tag_value($tag);
foreach $temp (@t1) {
$temp =~ /:/;
my $db = $PREMATCH;
my $xref = $POSTMATCH;
my %acchash = (
"db_id" => {'name' => $db},
"accession" => $xref,
);
my %fdbx = ('dbxref_id' =>\% acchash);
push (@top_dbxrefs,\% fdbx);
}
} elsif ($tag ne 'gene') {
my %prophash = undef;
%prophash = (
"type_id" => {'name' => $tag, 'cv_id' => {'name' => 'GenBank feature qualifier'}},
"value" => join(' ',$feat->each_tag_value($tag)),
);
push(@top_featureprops,\% prophash);
}
}
my $fmin = undef;
my $fmax = undef;
my $strand = undef;
my %fl = undef;
$fmin = $feat->start - 1;
$fmax = $feat->end;
$strand = $feat->strand;
%fl = (
"srcfeature_id" =>\% srcfhash,
"fmin" => $fmin,
"fmax" => $fmax,
"strand" => $strand,
);
$datahash{'featureloc'} =\% fl;
splice(@top_sfs, $si, 1);
}
$si ++;
}
foreach $feat (@top_sfs) {
my $r = $self->_subfeat2featrelhash($name, $ftype, $feat,\% srcfhash);
if (!($ftype eq 'mRNA' && $feat->primary_tag eq 'gene')) {
my %fr = %$r;
push(@top_featrels,\% fr);
} else {
%finaldatahash = %$r;
}
}
if (@top_dbxrefs) {
$datahash{'feature_dbxref'} =\@ top_dbxrefs;
}
if (@top_featureprops) {
$datahash{'featureprop'} =\@ top_featureprops;
}
if (@top_featrels) {
$datahash{'feature_relationship'} =\@ top_featrels;
}
if ($ftype eq 'mRNA' && %finaldatahash) {
$finaldatahash{'feature_relationship'} = {
'subject_id' =>\% datahash,
'type_id' => { 'name' => 'partof', 'cv_id' => { 'name' => 'relationship type'}},
};
} else {
%finaldatahash = %datahash;
}
my $mainTag = 'feature';
$self->_hash2xml(undef, $mainTag,\% finaldatahash);
return 1; } |
sub _hash2xml
{ my $self = shift;
my $isMatch = undef;
$isMatch = shift;
my $ult = shift;
my $ref = shift;
my %mh = %$ref;
undef(my $writer);
$writer = shift if (@_);
my $key;
my $v;
my $sh;
my $xx;
my $yy;
my $nt;
my $ntref;
my $output;
my $root = shift if (@_);
if (!defined $writer) {
$root = 1;
$writer = new XML::Writer(OUTPUT => $self->_fh,
DATA_MODE => 1,
DATA_INDENT => 3);
$writer->xmlDecl("UTF-8");
$writer->comment("created by Peili Zhang, Flybase, Harvard University");
$writer->startTag('chado');
}
my $temp;
my %subh = undef;
if ($ult eq 'pub' && $mh{'type_id'}->{'name'} eq 'journal') {
$writer->startTag($ult, 'ref' => $mh{'title'} . ':journal:abbreviation');
}
elsif ($ult eq 'pub' && !defined $mh{'uniquename'}) {
$writer->startTag($ult, 'op' => 'match');
$isMatch = 1;
}
elsif (($ult eq 'cvterm') || ($ult eq 'cv')) {
$writer->startTag($ult, 'op' => 'lookup');
}
elsif ($isMatch) {
$writer->startTag($ult, 'op' => 'match');
}
else {
$writer->startTag($ult);
}
foreach $key (keys %mh)
{
$xx = ' ' . $key;
$yy = $key . ' ';
if (index($chadotables, $xx) < 0 && index($chadotables, $yy) < 0)
{
if ($isMatch) {
$writer->startTag($key, 'op' => 'match');
} else {
$writer->startTag($key);
}
my $x = $ult . '.' . $key;
if (defined $fkey{$x})
{
$nt = $fkey{$x};
$sh = $mh{$key};
$self->_hash2xml($isMatch, $nt, $sh, $writer, 0);
} else
{
$writer->characters($mh{$key});
}
$writer->endTag($key);
}
}
foreach $key (keys %mh)
{
$xx = ' ' . $key;
$yy = $key . ' ';
if (index($chadotables, $xx) > 0 || index($chadotables, $yy) > 0)
{
$ntref = $mh{$key};
if (ref($ntref) =~ 'HASH') {
$self->_hash2xml($isMatch, $key, $ntref, $writer, 0);
} elsif (ref($ntref) =~ 'ARRAY') {
foreach $ref (@$ntref) {
$self->_hash2xml($isMatch, $key, $ref, $writer, 0);
}
}
}
}
$writer->endTag($ult);
if ($root == 1) {
$writer->endTag('chado');
}} |
sub _subfeat2featrelhash
{ my $self = shift;
my $genename = shift;
my $seqtype = shift;
my $feat = shift;
my $r = shift;
my %srcf = %$r;
my $prim_tag = $feat->primary_tag;
my $sfunique = undef; my $sfname = undef; my $sftype = undef;
if ($feat->has_tag('symbol')) {
($sfname) = $feat->each_tag_value("symbol");
} elsif ($feat->has_tag('label')) {
($sfname) = $feat->each_tag_value("label");
} else {
$sfname = $self->_genFeatUniqueName($genename, $feat);
}
$sfunique = $sfname;
if (defined $feattype_args2so{$prim_tag}) {
$sftype = $feattype_args2so{$prim_tag};
} else {
$sftype = $prim_tag;
}
if ($prim_tag eq 'mutation') {
if ($feat->start == $feat->end) {
$sftype = $feattype_args2so{'mutation1'};
} else {
$sftype = $feattype_args2so{'mutation2'};
}
}
my %sfhash = (
"name" => $sfname,
"uniquename" => $sfunique,
"organism_id" =>\% organism,
"type_id" => { 'name' => $sftype, 'cv_id' => { 'name' => 'SO'}},
);
undef(my $sfmin);
undef(my $sfmax);
undef(my $is_sfmin_partial);
undef(my $is_sfmax_partial);
undef(my $sfstrand);
$sfmin = $feat->start - 1;
$sfmax = $feat->end;
$sfstrand = $feat->strand();
if ($seqtype eq 'mRNA' && $sftype eq 'gene') {
} else {
if ($feat->location->isa('Bio::Location::FuzzyLocationI')) {
if ($feat->location->start_pos_type() ne 'EXACT') {
$is_sfmin_partial = 'true';
}
if ($feat->location->end_pos_type() ne 'EXACT') {
$is_sfmax_partial = 'true';
}
}
my %sfl = (
"srcfeature_id" =>\% srcf,
"fmin" => $sfmin,
"is_fmin_partial" => $is_sfmin_partial || '',
"fmax" => $sfmax,
"is_fmax_partial" => $is_sfmax_partial || '',
"strand" => $sfstrand,
);
$sfhash{'featureloc'} =\% sfl;
}
undef(my @sfdbxrefs); undef(my @sub_featureprops); foreach my $tag ($feat->all_tags()) {
if ($tag eq 'db_xref') {
my @t1 = $feat->each_tag_value($tag);
for my $temp (@t1) {
$temp =~ /:/;
my $db = $PREMATCH;
my $xref = $POSTMATCH;
my %acchash = (
"db_id" => {'name' => $db},
"accession" => $xref,
);
my %sfdbx = ('dbxref_id' =>\% acchash);
push (@sfdbxrefs,\% sfdbx);
}
} elsif ($tag ne 'gene' && $tag ne 'symbol') {
foreach my $val ($feat->each_tag_value($tag)) {
my %prophash = undef;
%prophash = (
"type_id" => {'name' => $tag, 'cv_id' => {'name' => 'GenBank feature qualifier'}},
"value" => $val,
);
push(@sub_featureprops,\% prophash);
}
}
}
if (@sub_featureprops) {
$sfhash{'featureprop'} =\@ sub_featureprops;
}
if (@sfdbxrefs) {
$sfhash{'feature_dbxref'} =\@ sfdbxrefs;
}
undef(my @ssfeatrel);
if ($feat->has_tag('locus_tag')) {
($genename)= $feat->each_tag_value('locus_tag');
} elsif ($feat->has_tag('gene')) {
($genename)= $feat->each_tag_value('gene');
}
foreach my $sf ($feat->get_SeqFeatures()) {
my $rref = $self->_subfeat2featrelhash($genename, $sftype, $sf,\% srcf);
if (defined $rref) {
push(@ssfeatrel, $rref);
}
}
if (@ssfeatrel) {
$sfhash{'feature_relationship'} =\@ ssfeatrel;
}
undef(my $reltypename);
if ($sftype eq 'protein') {
$reltypename = 'producedby';
} else {
$reltypename = 'partof';
}
my %fr = (
"subject_id" =>\% sfhash,
"type_id" => { 'name' => $reltypename, 'cv_id' => { 'name' => 'relationship type'}},
);
if ($seqtype eq 'mRNA' && $sftype eq 'gene') {
return\% sfhash;
} else {
return\% fr;
} } |