3 # BioPerl module for Bio::SeqIO::chadoxml
5 # Peili Zhang <peili@morgan.harvard.edu>
7 # You may distribute this module under the same terms as perl itself
9 # POD documentation - main docs before the code
13 Bio::SeqIO::chadoxml - chadoxml sequence output stream
17 It is probably best not to use this object directly, but
18 rather go through the SeqIO handler system:
20 $writer = Bio::SeqIO->new(-file => ">chado.xml",
21 -format => 'chadoxml');
23 # assume you already have Sequence or SeqFeature objects
24 $writer->write_seq($seq_obj);
26 #after writing all seqs
27 $writer->close_chadoxml();
33 This object can transform Bio::Seq objects to chadoxml flat
34 file databases (for chadoxml DTD, see
35 http://gmod.cvs.sourceforge.net/gmod/schema/chado/dat/chado.dtd).
37 This is currently a write-only module.
39 $seqio = Bio::SeqIO->new(-file => '>outfile.xml',
41 -suppress_residues => 1,
42 -allow_residues => 'chromosome',
45 # we have a Bio::Seq object $seq which is a gene located on
46 # chromosome arm 'X', to be written out to chadoxml
47 # before converting to chadoxml, $seq object B<must> be transformed
48 # so that all the coordinates in $seq are against the source
49 # feature to be passed into Bio::SeqIO::chadoxml->write_seq()
50 # -- chromosome arm X in the example below.
52 $seqio->write_seq(-seq=>$seq,
54 -species => 'sapiens',
57 -src_feat_type=>'chromosome_arm',
60 -data_source=>'GenBank');
62 The chadoxml output of Bio::SeqIO::chadoxml-E<gt>write_seq() method can be
63 passed to the loader utility in XORT package
64 (http://gmod.cvs.sourceforge.net/gmod/schema/XMLTools/XORT/)
65 to be loaded into chado.
67 This object is currently implemented to work with sequence and
68 annotation data from whole genome projects deposited in GenBank. It
69 may not be able to handle all different types of data from all
72 In converting a Bio::Seq object into chadoxml, a top-level feature is
73 created to represent the object and all sequence features inside the
74 Bio::Seq object are treated as subfeatures of the top-level
75 feature. The Bio::SeqIO::chadoxml object calls
76 Bio::SeqFeature::Tools::Unflattener to unflatten the flat feature list
77 contained in the subject Bio::Seq object, to build gene model
78 containment hierarchy conforming to chado central dogma model: gene
79 --E<gt> mRNA --E<gt> exons and protein.
81 Destination of data in the subject Bio::Seq object $seq is as following:
83 *$seq->display_id: name of the top-level feature;
85 *$seq->accession_number: if defined, uniquename and
86 feature_dbxref of the top-level
87 feature if not defined,
88 $seq->display_id is used as the
89 uniquename of the top-level feature;
91 *$seq->molecule: transformed to SO type, used as the feature
92 type of the top-level feature if -seq_so_type
93 argument is supplied, use the supplied SO type
94 as the feature type of the top-level feature;
96 *$seq->species: organism of the top-level feature;
98 *$seq->seq: residues of the top-level feature;
100 *$seq->is_circular, $seq->division: feature_cvterm;
102 *$seq->keywords, $seq->desc, comments: featureprop;
104 *references: pub and feature_pub;
105 medline/pubmed ids: pub_dbxref;
108 *feature "source" span: featureloc for top-level feature;
110 *feature "source" db_xref: feature_dbxref for top-level feature;
112 *feature "source" other tags: featureprop for top-level feature;
114 *subfeature 'symbol' or 'label' tag: feature uniquename, if
115 none of these is present, the chadoxml object
116 generates feature uniquenames as:
117 <gene>-<feature_type>-<span>
118 (e.g. foo-mRNA--1000..3000);
120 *gene model: feature_relationship built based on the
121 containment hierarchy;
123 *feature span: featureloc;
125 *feature accession numbers: feature_dbxref;
127 *feature tags (except db_xref, symbol and gene): featureprop;
129 Things to watch out for:
131 *chado schema change: this version works with the chado
132 version tagged chado_1_01 in GMOD CVS.
134 *feature uniquenames: especially important if using XORT
135 loader to do incremental load into
136 chado. may need pre-processing of the
137 source data to put the correct
138 uniquenames in place.
140 *pub uniquenames: chadoxml->write_seq() has the FlyBase policy
141 on pub uniquenames hard-coded, it assigns
142 pub uniquenames in the following way: for
143 journals and books, use ISBN number; for
144 published papers, use MEDLINE ID; for
145 everything else, use FlyBase unique
146 identifier FBrf#. need to modify the code to
147 implement your policy. look for the comments
150 *for pubs possibly existing in chado but with no knowledge of
151 its uniquename:put "op" as "match", then need to run the
152 output chadoxml through a special filter that
153 talks to chado database and tries to find the
154 pub by matching with the provided information
155 instead of looking up by the unique key. after
156 matching, the filter also resets the "match"
157 operation to either "force" (default), or
158 "lookup", or "insert", or "update". the
159 "match" operation is for a special FlyBase use
160 case. please modify to work according to your
163 *chado initialization for loading:
165 cv & cvterm: in the output chadoxml, all cv's and
166 cvterm's are lookup only. Therefore,
167 before using XORT loader to load the
168 output into chado, chado must be
169 pre-loaded with all necessary CVs and
170 CVterms, including "SO" , "property
171 type", "relationship type", "pub type",
172 "pubprop type", "pub relationship type",
173 "sequence topology", "GenBank feature
174 qualifier", "GenBank division". A pub by
175 the uniquename 'nullpub' of type 'null
176 pub' needs to be inserted.
182 User feedback is an integral part of the evolution of this and other
183 Bioperl modules. Send your comments and suggestions preferably to one
184 of the Bioperl mailing lists. Your participation is much appreciated.
186 bioperl-l@bioperl.org - General discussion
187 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
191 Please direct usage questions or support issues to the mailing list:
193 I<bioperl-l@bioperl.org>
195 rather than to the module maintainer directly. Many experienced and
196 reponsive experts will be able look at the problem and quickly
197 address it. Please include a thorough description of the problem
198 with code and data examples if at all possible.
200 =head2 Reporting Bugs
202 Report bugs to the Bioperl bug tracking system to help us keep track
203 the bugs and their resolution.
204 Bug reports can be submitted via the web:
206 http://bugzilla.bioperl.org
208 =head1 AUTHOR - Peili Zhang
210 Email peili@morgan.harvard.edu
214 The rest of the documentation details each of the object
215 methods. Internal methods are usually preceded with a _
219 # Let the code begin...
221 package Bio
::SeqIO
::chadoxml
;
231 use Bio
::Seq
::RichSeq
;
232 use Bio
::SeqIO
::FTHelper
;
234 use Bio
::Seq
::SeqFactory
;
235 use Bio
::Factory
::SequenceStreamI
;
236 use Bio
::SeqFeature
::Generic
;
237 use Bio
::Annotation
::Collection
;
238 use Bio
::Annotation
::Comment
;
239 use Bio
::Annotation
::Reference
;
240 use Bio
::Annotation
::DBLink
;
241 use Bio
::SeqFeature
::Tools
::Unflattener
;
244 undef(my %finaldatahash); #data from Bio::Seq object stored in a hash
245 undef(my %datahash); #data from Bio::Seq object stored in a hash
247 my $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 synonym feature_synonym';
250 "cvterm.cv_id" => "cv",
251 "cvterm.dbxref_id" => "dbxref",
252 "dbxref.db_id" => "db",
253 "feature.type_id" => "cvterm",
254 "feature.organism_id" => "organism",
255 "feature.dbxref_id" => "dbxref",
256 "featureprop.type_id" => "cvterm",
257 "feature_pub.pub_id" => "pub",
258 "feature_cvterm.cvterm_id" => "cvterm",
259 "feature_cvterm.pub_id" => "pub",
260 "feature_cvterm.feature_id" => "feature",
261 "feature_dbxref.dbxref_id" => "dbxref",
262 "feature_relationship.object_id" => "feature",
263 "feature_relationship.subject_id" => "feature",
264 "feature_relationship.type_id" => "cvterm",
265 "featureloc.srcfeature_id" => "feature",
266 "pub.type_id" => "cvterm",
267 "pub_dbxref.dbxref_id" => "dbxref",
268 "pub_author.author_id" => "author",
269 "pub_relationship.obj_pub_id" => "pub",
270 "pub_relationship.subj_pub_id" => "pub",
271 "pub_relationship.type_id" => "cvterm",
272 "pubprop.type_id" => "cvterm",
273 "feature_synonym.feature_id" => "feature",
274 "feature_synonym.synonym_id" => "synonym",
275 "feature_synonym.pub_id" => "pub",
276 "synonym.type_id" => "cvterm",
280 'relationship' => 'relationship',
281 'sequence' => 'sequence',
282 'feature_property' => 'feature_property',
285 my %feattype_args2so = (
286 "aberr" => "aberration_junction",
287 # "conflict" => "sequence_difference",
288 # "polyA_signal" => "polyA_signal_sequence",
289 "variation" => "sequence_variant",
290 "mutation1" => "point_mutation", #for single-base mutation
291 "mutation2" => "sequence_variant", #for multi-base mutation
292 "rescue" => "rescue_fragment",
293 # "rfrag" => "restriction_fragment",
294 "protein_bind" => "protein_binding_site",
295 "misc_feature" => "region",
296 # "prim_transcript" => "primary_transcript",
297 "CDS" => "polypeptide",
298 "reg_element" => "regulatory_region",
299 "seq_variant" => "sequence_variant",
300 "mat_peptide" => "mature_peptide",
301 "sig_peptide" => "signal_peptide",
306 use base
qw(Bio::SeqIO);
310 my($self,%args) = @_;
312 $self->SUPER::_initialize
(%args);
313 unless( defined $self->sequence_factory ) {
314 $self->sequence_factory(Bio
::Seq
::SeqFactory
->new
315 (-verbose
=> $self->verbose(),
316 -type
=> 'Bio::Seq::RichSeq'));
318 #optional arguments that can be passed in
319 $self->suppress_residues($args{'-suppress_residues'})
320 if defined $args{'-suppress_residues'};
322 $self->allow_residues($args{'-allow_residues'})
323 if defined $args{'-allow_residues'};
330 Usage : $stream->write_seq(-seq=>$seq, -seq_so_type=>$seqSOtype,
331 -src_feature=>$srcfeature,
332 -src_feat_type=>$srcfeattype,
333 -nounflatten=>0 or 1,
334 -is_analysis=>'true' or 'false',
335 -data_source=>$datasource)
336 Function: writes the $seq object (must be seq) into chadoxml.
337 Returns : 1 for success and 0 for error
338 Args : A Bio::Seq object $seq, optional $seqSOtype, $srcfeature,
339 $srcfeattype, $nounflatten, $is_analysis and $data_source.
341 When $srcfeature (a string, the uniquename of the source feature) is given, the
342 location and strand information of the top-level feature against the source
343 feature will be derived from the sequence feature called 'source' of the $seq
344 object, a featureloc record is generated for the top -level feature on
345 $srcfeature. when $srcfeature is given, $srcfeattype must also be present. All
346 feature coordinates in $seq should be against $srcfeature. $seqSOtype is the
347 optional SO term to use as the type of the top-level feature. For example, a
348 GenBank data file for a Drosophila melanogaster genome scaffold has the molecule
349 type of "DNA", when converting to chadoxml, a $seqSOtype argument of
350 "golden_path_region" can be supplied to save the scaffold as a feature of type
351 "golden_path_region" in chadoxml, instead of "DNA". a feature with primary tag
352 of 'source' must be present in the sequence feature list of $seq, to decribe the
353 whole sequence record.
355 In the current implementation:
363 A top-level feature of type $seq-E<gt>alphabet is generated for the whole GenBank
364 record, features listed are unflattened for DNA records to build gene model
365 feature graph, and for the other types of records all features in $seq are
366 treated as subfeatures of the top-level feature.
372 If a 'gene' feature is present, it B<must> have a /symbol or /label tag to
373 contain the uniquename of the gene. a top-level feature of type 'gene' is
374 generated. the mRNA is written as a subfeature of the top-level gene feature,
375 and the other sequence features listed in $seq are treated as subfeatures of the
383 my $usage = <<EOUSAGE;
384 Bio::SeqIO::chadoxml->write_seq()
385 Usage : \$stream->write_seq(-seq=>\$seq,
386 -seq_so_type=>\$SOtype,
387 -src_feature=>\$srcfeature,
388 -src_feat_type=>\$srcfeattype,
389 -nounflatten=>0 or 1,
390 -is_analysis=>'true' or 'false',
391 -data_source=>\$datasource)
392 Args : \$seq : a Bio::Seq object
393 \$SOtype : the SO term to use as the feature type of
394 the \$seq record, optional
395 \$srcfeature : unique name of the source feature, a string
396 containing at least one alphabetical letter
398 \$srcfeattype : feature type of \$srcfeature. one of SO terms.
400 when \$srcfeature is given, \$srcfeattype becomes mandatory,
401 \$datasource : source of the sequence annotation data,
402 e.g. 'GenBank' or 'GFF'.
405 my ($self,@args) = @_;
407 my ($seq, $seq_so_type, $srcfeature, $srcfeattype, $nounflatten, $isanalysis, $datasource, $genus, $species) =
408 $self->_rearrange([qw(SEQ
419 #print "$seq_so_type, $srcfeature, $srcfeattype\n";
421 if( !defined $seq ) {
422 $self->throw("Attempting to write with no seq!");
425 if( ! ref $seq || ! $seq->isa('Bio::Seq::RichSeqI') ) {
426 ## FIXME $self->warn(" $seq is not a RichSeqI compliant module. Attempting to dump, but may fail!");
429 # try to get the srcfeature from the seqFeature object
430 # for this to work, the user has to pass in the srcfeature type
432 if ($seq->can('seq_id')) {
433 $srcfeature=$seq->seq_id if ($seq->seq_id ne $seq->display_name);
437 #$srcfeature, when provided, should contain at least one alphabetical letter
438 if (defined $srcfeature)
440 if ($srcfeature =~ /[a-zA-Z]/)
444 $self->throw( $usage );
447 #check for mandatory $srcfeattype
448 if (! defined $srcfeattype)
450 $self->throw( $usage );
451 #$srcfeattype must be a string of non-whitespace characters
453 if ($srcfeattype =~ /\S+/) {
456 $self->throw( $usage );
461 # variables local to write_seq()
464 undef(my @top_featureprops);
465 undef(my @featuresyns);
466 undef(my @top_featurecvterms);
467 my $name = $seq->display_id if $seq->can('display_id');
468 $name = $seq->display_name if $seq->can('display_name');
469 undef(my @feature_cvterms);
476 undef(my @references);
477 undef(my @feature_pubs);
479 my $location = undef;
484 my $volumeissue = undef;
488 # my $miniref= undef;
489 my $uniquename = undef;
495 my $subfeatcnt = undef;
496 undef(my @top_featrels);
497 undef (my %srcfhash);
499 local($^W
) = 0; # supressing warnings about uninitialized fields.
501 if (!$name && $seq->can('attributes') ) {
502 ($name) = $seq->attributes('Alias');
505 if ($seq->can('accession_number') && defined $seq->accession_number && $seq->accession_number ne 'unknown') {
506 $uniquename = $seq->accession_number;
507 } elsif ($seq->can('accession') && defined $seq->accession && $seq->accession ne 'unknown') {
508 $uniquename = $seq->accession;
509 } elsif ($seq->can('attributes')) {
510 ($uniquename) = $seq->attributes('load_id');
514 my $len = $seq->length();
520 if (!$seq->can('molecule') || ! defined ($gb_type = $seq->molecule()) ) {
521 $gb_type = $seq->can('alphabet') ?
$seq->alphabet : 'DNA';
523 $gb_type = 'DNA' if $ftype eq 'dna';
524 $gb_type = 'RNA' if $ftype eq 'rna';
526 if(length $seq_so_type > 0) {
527 if (defined $seq_so_type) {
528 $ftype = $seq_so_type;
531 $ftype = ($seq->type =~ /(.*):/)
543 my %ftype_hash = $self->return_ftype_hash($ftype);
546 %organism = ("genus"=>$genus, "species" => $species);
549 my $spec = $seq->species();
550 if (!defined $spec) {
551 $self->throw("$seq does not know what organism it is from, which is required by chado. cannot proceed!\n");
553 %organism = ("genus"=>$spec->genus(), "species" => $spec->species());
558 if (!$self->suppress_residues ||
559 ($self->suppress_residues && $self->allow_residues eq $ftype)) {
560 $residues = $seq->seq->isa('Bio::PrimarySeq')
568 #set is_analysis flag for gene model features
570 if ($ftype eq 'gene' || $ftype eq 'mRNA' || $ftype eq 'exon' || $ftype eq 'protein' || $ftype eq 'polypeptide') {
571 $isanal = $isanalysis;
572 $isanal = 'false' if !defined $isanal;
577 "uniquename" => $uniquename,
579 "residues" => $residues,
580 "type_id" => \
%ftype_hash,
581 "organism_id" => \
%organism,
582 "is_analysis" => $isanal || 'false',
585 if (defined $srcfeature) {
586 %srcfhash = $self->_srcf_hash($srcfeature,
591 if ($seq->can('phase')) {
592 $phase = $seq->phase;
595 if ($seq->can('strand')) {
596 $strand = $seq->strand;
599 "srcfeature_id" => \
%srcfhash,
600 "fmin" => $seq->start - 1,
606 $datahash{'featureloc'} = \
%fl;
611 #if $srcfeature is not given, use the Bio::Seq object itself as the srcfeature for featureloc's
612 if (!defined $srcfeature) {
613 $srcfeature = $uniquename;
614 $srcfeattype = $ftype;
617 #default data source is 'GenBank'
618 if (!defined $datasource) {
619 $datasource = 'GenBank';
622 if ($datasource =~ /GenBank/i) {
623 #sequence topology as feature_cvterm
624 if ($seq->can('is_circular') && $seq->is_circular) {
626 "cvterm_id" => {'name' => 'circular',
628 'name' => 'sequence topology',
631 "pub_id" => {'uniquename' => 'nullpub',
633 'name' => 'null pub',
642 "cvterm_id" => { 'name' => 'linear',
644 'name' => 'sequence topology',
647 "pub_id" => {'uniquename' => 'nullpub',
649 'name' => 'null pub',
657 push(@feature_cvterms, \
%sthash);
659 #division as feature_cvterm
660 if ($seq->can('division') && defined $seq->division()) {
661 $div = $seq->division();
663 "cvterm_id" => {'name' => $div,
665 'name' => 'GenBank division'}},
666 "pub_id" => {'uniquename' => 'nullpub',
668 'name' => 'null pub',
670 'name'=> 'pub type'},
673 push(@feature_cvterms, \
%dvhash);
676 $datahash{'feature_cvterm'} = \
@feature_cvterms;
677 } # closes if GenBank
681 if ($seq->can('desc') && defined $seq->desc()) {
682 $temp = $seq->desc();
685 "type_id" => {'name' => 'description',
688 $cv_name{'feature_property'}
694 push(@top_featureprops, \
%prophash);
698 if ($seq->can('keywords')) {
699 $temp = $seq->keywords();
701 if (defined $temp && $temp ne '.' && $temp ne '') {
703 "type_id" => {'name' => 'keywords',
706 $cv_name{'feature_property'}
712 push(@top_featureprops, \
%prophash);
717 if ($seq->can('annotation')) {
718 $ann = $seq->annotation();
719 foreach my $comment ($ann->get_Annotations('comment')) {
720 $temp = $comment->as_text();
721 #print "fcomment: $temp\n";
723 "type_id" => {'name' => 'comment',
726 $cv_name{'feature_property'}
732 push(@top_featureprops, \
%prophash);
736 my @top_dbxrefs = ();
737 #feature object from Bio::DB::SeqFeature::Store
738 if ($seq->can('attributes')) {
739 my %attributes = $seq->attributes;
740 for my $key (keys %attributes) {
741 next if ($key eq 'parent_id');
742 next if ($key eq 'load_id');
744 if ($key eq 'Alias') {
745 @featuresyns = $self->handle_Alias_tag($seq,@featuresyns);
748 ###FIXME deal with Dbxref, Ontology_term,source,
749 elsif ($key eq 'Ontology_term') {
750 @top_featurecvterms = $self->handle_Ontology_tag($seq,@top_featurecvterms);
753 elsif ($key eq 'dbxref' or $key eq 'Dbxref') {
754 @top_dbxrefs = $self->handle_dbxref($seq, $key, @top_dbxrefs);
757 elsif ($key =~ /^[a-z]/) {
759 = $self->handle_unreserved_tags($seq,$key,@top_featureprops);
763 $datahash{'feature_synonym'} = \
@featuresyns;
765 if ($seq->can('source')) {
766 @top_dbxrefs = $self->handle_source($seq,@top_dbxrefs);
769 #accession and version as feature_dbxref
770 if ($seq->can('accession_number') && defined $seq->accession_number && $seq->accession_number ne 'unknown') {
771 my $db = $self->_guess_acc_db($seq, $seq->accession_number);
773 "db_id" => {'name' => $db},
774 "accession" => $seq->accession_number,
775 "version" => $seq->seq_version,
777 my %fdbx = ('dbxref_id' => \
%acchash);
778 push(@top_dbxrefs, \
%fdbx);
781 if( $seq->isa('Bio::Seq::RichSeqI') && defined $seq->get_secondary_accessions() ) {
782 my @secacc = $seq->get_secondary_accessions();
784 foreach $acc (@secacc) {
786 "db_id" => {'name' => 'GB'},
789 my %fdbx = ('dbxref_id' => \
%acchash);
790 push(@top_dbxrefs, \
%fdbx);
795 if( $seq->isa('Bio::Seq::RichSeqI') && defined ($seq->pid)) {
797 #print "reftype: ", ref($id), "\n";
799 #if (ref($id) eq 'HASH') {
801 "db_id" => {'name' => 'GI'},
804 my %fdbx = ('dbxref_id' => \
%acchash);
805 push (@top_dbxrefs, \
%fdbx);
808 #REFERENCES as feature_pub
811 @references = $ann->get_Annotations('reference');
812 foreach $ref (@references) {
814 $refhash = $ref->hash_tree();
815 $location = $ref->location || $refhash->{'location'};
816 #print "location: $location\n";
818 #get FBrf#, special for FlyBase SEAN loading
819 if (index($location, ' ==') >= 0) {
821 #print "match: $MATCH\n";
822 #print "prematch: $PREMATCH\n";
823 #print "postmatch: $POSTMATCH\n";
825 $location = $POSTMATCH;
826 $location =~ s/^\s//;
829 #print "location: $location\n";
830 #unpublished reference
831 if ($location =~ /Unpublished/) {
832 $pubtype = 'unpublished';
834 "title" => $ref->title || $refhash->{'title'},
835 #"miniref" => substr($location, 0, 255),
836 #"uniquename" => $fbrf,
837 "type_id" => {'name' => $pubtype, 'cv_id' => {'name' =>'pub type'}}
841 elsif ($location =~ /Submitted/) {
842 $pubtype = 'submitted';
845 "title" => $ref->title || $refhash->{'title'},
846 #"miniref" => substr($location, 0, 255),
847 #"uniquename" => $fbrf,
848 "type_id" => {'name' => $pubtype, 'cv_id' => {'name' =>'pub type'}}
852 $pyear = $self->_getSubmitYear($location);
853 if (defined $pyear) {
854 $pubhash{'pyear'} = $pyear;
858 #published journal paper
859 elsif ($location =~ /\D+\s\d+\s\((\d+|\d+-\d+)\),\s(\d+-\d+|\d+--\d+)\s\(\d\d\d\d\)$/) {
862 #parse location to get journal, volume, issue, pages & year
863 $location =~ /\(\d\d\d\d\)$/;
866 my $stuff = $PREMATCH;
867 $year =~ s/\(//; #remove the leading parenthesis
868 $year =~ s/\)//; #remove the trailing parenthesis
870 $stuff =~ /,\s(\d+-\d+|\d+--\d+)\s$/;
874 $pages =~ s/^, //; #remove the leading comma and space
875 $pages =~ s/ $//; #remove the last space
877 $stuff =~ /\s\d+\s\((\d+|\d+-\d+)\)$/;
879 $volumeissue = $MATCH;
880 $journal = $PREMATCH;
881 $volumeissue =~ s/^ //; #remove the leading space
882 $volumeissue =~ /\((\d+|\d+-\d+)\)$/;
885 $issue =~ s/^\(//; #remove the leading parentheses
886 $issue =~ s/\)$//; #remove the last parentheses
887 $volume =~ s/^\s//; #remove the leading space
888 $volume =~ s/\s$//; #remove the last space
891 "title" => $ref->title || $refhash->{'title'},
896 #"miniref" => substr($location, 0, 255),
898 #"uniquename" => $fbrf,
899 "type_id" => {'name' => $pubtype, 'cv_id' => {'name' =>'pub type'}},
900 "pub_relationship" => {
902 'uniquename' => $journal,
904 #'miniref' => substr($journal, 0, 255),
905 'type_id' =>{'name' => 'journal',
907 {'name' => 'pub type'
910 #'pubprop' =>{'value'=> $journal,
911 # 'type_id'=>{'name' => 'abbreviation', 'cv_id' => {'name' => 'pubprop type'}},
915 'name' => 'published_in',
917 'name' => 'pub relationship type'},
927 "title" => $ref->title || $refhash->{'title'},
931 'cv_id' => {'name' =>'pub type'}
937 my $autref = $self->_getRefAuthors($ref);
938 if (defined $autref) {
939 $pubhash{'pub_author'} = $autref;
941 # if no author and is type 'submitted' and has submitter address, use the first 100 characters of submitter address as the author lastname.
943 if ($pubtype eq 'submitted') {
944 my $autref = $self->_getSubmitAddr($ref);
945 if (defined $autref) {
946 $pubhash{'pub_author'} = $autref;
951 #$ref->comment as pubprop
952 #print "ref comment: ", $ref->comment, "\n";
953 #print "ref comment: ", $refhash->{'comment'}, "\n";
954 if (defined $ref->comment || defined $refhash->{'comment'}) {
955 my $comnt = $ref->comment || $refhash->{'comment'};
956 #print "remark: ", $comnt, "\n";
957 $pubhash{'pubprop'} = {
958 "type_id" => {'name' => 'comment', 'cv_id' => {'name' => 'pubprop type'}},
964 undef(my @pub_dbxrefs);
966 push(@pub_dbxrefs, {dbxref_id
=> {accession
=> $fbrf, db_id
=> {'name' => 'FlyBase'}}});
968 if (defined ($temp = $ref->medline)) {
969 push(@pub_dbxrefs, {dbxref_id
=> {accession
=> $temp, db_id
=> {'name' => 'MEDLINE'}}});
970 #use medline # as the pub's uniquename
971 $pubhash{'uniquename'} = $temp;
973 if (defined ($temp = $ref->pubmed)) {
974 push(@pub_dbxrefs, {dbxref_id
=> {accession
=> $temp, db_id
=> {'name' => 'PUBMED'}}});
976 $pubhash{'pub_dbxref'} = \
@pub_dbxrefs;
978 #if the pub uniquename is not defined or blank, put its FBrf# as its uniquename
979 #this is unique to FlyBase
980 #USERS OF THIS MODULE: PLEASE MODIFY HERE TO IMPLEMENT YOUR POLICY
981 # ON PUB UNIQUENAME!!!
982 if (!defined $pubhash{'uniquename'} || $pubhash{'uniquename'} eq '') {
984 $pubhash{'uniquename'} = $fbrf;
987 # $pubhash{'uniquename'} = $self->_CreatePubUname($ref);
991 #add to collection of references
992 #if the pub covers the entire sequence of the top-level feature, add it to feature_pubs
993 if (($ref->start == 1 && $ref->end == $len) || (!defined $ref->start && !defined $ref->end)) {
994 push(@feature_pubs, {"pub_id" => \
%pubhash});
996 #the pub is about a sub-sequence of the top-level feature
997 #create a feature for the sub-sequence and add pub as its feature_pub
998 #featureloc of this sub-sequence is against the top-level feature, in interbase coordinates.
1001 'uniquename' => $uniquename . ':' . $ref->start . "\.\." . $ref->end,
1002 'organism_id' =>\
%organism,
1003 'type_id' =>{'name' =>'region', 'cv_id' => {'name' => $cv_name{'sequence'} }},
1006 'uniquename' => $uniquename,
1007 'organism_id' =>\
%organism,
1010 'srcfeature_id' => \
%parfsrcf,
1011 'fmin' => $ref->start - 1,
1012 'fmax' => $ref->end,
1014 $parf{'featureloc'} = \
%parfloc;
1015 $parf{'feature_pub'} = {'pub_id' => \
%pubhash};
1017 'subject_id' => \
%parf,
1018 'type_id' => { 'name' => 'partof', 'cv_id' => { 'name' => $cv_name{'relationship'}}},
1020 push(@top_featrels, \
%ffr);
1023 $datahash{'feature_pub'} = \
@feature_pubs;
1026 ##construct srcfeature hash for use in featureloc
1027 if (defined $srcfeature) {
1028 %srcfhash = $self->_srcf_hash($srcfeature,
1032 # "object_id" => \%srcfhash,
1033 # "type_id" => { 'name' => 'partof', 'cv_id' => { 'name' => 'relationship type'}},
1036 # push (@top_featrels, \%fr);
1039 #unflatten the seq features in $seq if $seq is a gene or a DNA sequence
1040 if (($gb_type eq 'gene' || $gb_type eq 'DNA') &&
1042 my $u = Bio
::SeqFeature
::Tools
::Unflattener
->new;
1043 $u->unflatten_seq(-seq
=>$seq, -use_magic
=>1);
1046 my @top_sfs = $seq->get_SeqFeatures;
1047 #print $#top_sfs, "\n";
1051 if ($datasource =~ /GenBank/i) {
1052 $tag_cv = 'GenBank feature qualifier';
1053 } elsif ($datasource =~ /GFF/i) {
1054 $tag_cv = 'feature_property';
1056 $tag_cv = $cv_name{'feature_property'};
1060 foreach $feat (@top_sfs) {
1061 #$feat = $top_sfs[$si];
1063 my $prim_tag = $feat->primary_tag;
1064 #print $prim_tag, "\n";
1066 # get all qualifiers of the 'source' feature, load these as top_featureprops of the top level feature
1067 if ($prim_tag eq 'source') {
1068 foreach $tag ($feat->all_tags()) {
1070 if ($tag eq 'db_xref'
1072 or $tag eq 'dbxref') {
1073 my @t1 = $feat->each_tag_value($tag);
1074 foreach $temp (@t1) {
1075 $temp =~ /([^:]*?):(.*)/;
1078 #PRE/POST very inefficent
1079 #my $db = $PREMATCH;
1080 #my $xref = $POSTMATCH;
1082 "db_id" => {'name' => $db},
1083 "accession" => $xref,
1085 my %fdbx = ('dbxref_id' => \
%acchash);
1086 push (@top_dbxrefs, \
%fdbx);
1089 } elsif ($tag eq 'Ontology_term') {
1090 my @t1 = $feat->each_tag_value($tag);
1091 foreach $temp (@t1) {
1094 #other tags as featureprop
1095 } elsif ($tag ne 'gene') {
1096 my %prophash = undef;
1098 "type_id" => {'name' => $tag, 'cv_id' => {'name' => $tag_cv}},
1099 "value" => join(' ',$feat->each_tag_value($tag)),
1101 push(@top_featureprops, \
%prophash);
1105 if ($feat->can('source')) {
1106 my $source = $feat->source();
1107 @top_dbxrefs = $self->handle_source($feat, @top_dbxrefs);
1110 #featureloc for the top-level feature
1117 $fmin = $feat->start - 1;
1119 $strand = $feat->strand;
1121 if ($feat->can('phase')) {
1122 $phase = $feat->phase;
1126 "srcfeature_id" => \
%srcfhash,
1129 "strand" => $strand,
1133 $datahash{'featureloc'} = \
%fl;
1135 #delete 'source' feature from @top_sfs
1136 splice(@top_sfs, $si, 1);
1139 #close loop over top_sfs
1142 #the top-level features other than 'source'
1143 foreach $feat (@top_sfs) {
1144 #print $feat->primary_tag, "\n";
1146 my $r = $self->_subfeat2featrelhash($name, $ftype, $feat, \
%srcfhash, $tag_cv, $isanalysis);
1148 if (!($ftype eq 'mRNA' && $feat->primary_tag eq 'gene')) {
1150 push(@top_featrels, \
%fr);
1152 %finaldatahash = %$r;
1157 $datahash{'feature_dbxref'} = \
@top_dbxrefs;
1160 if (@top_featureprops) {
1161 $datahash{'featureprop'} = \
@top_featureprops;
1164 if (@top_featrels) {
1165 $datahash{'feature_relationship'} = \
@top_featrels;
1168 if (@top_featurecvterms) {
1169 $datahash{'feature_cvterm'} = \
@top_featurecvterms;
1172 if ($ftype eq 'mRNA' && %finaldatahash) {
1173 $finaldatahash{'feature_relationship'} = {
1174 'subject_id' => \
%datahash,
1175 'type_id' => { 'name' => 'partof', 'cv_id' => { 'name' => $cv_name{'relationship'} }},
1178 %finaldatahash = %datahash;
1181 my $mainTag = 'feature';
1182 $self->_hash2xml(undef, $mainTag, \
%finaldatahash);
1189 my $isMatch = undef;
1202 my $root = shift if (@_);
1203 #print "ult: $ult\n";
1204 if (!defined $self->{'writer'}) {
1206 $self->_create_writer();
1212 #if pub record of type 'journal', form the 'ref' attribute for special pub lookup
1213 #requires that the journal name itself is also stored as a pubprop record for the journal with value equal
1214 #to the journal name and type of 'abbreviation'.
1215 if ($ult eq 'pub' && $mh{'type_id'}->{'name'} eq 'journal') {
1216 $self->{'writer'}->startTag($ult, 'ref' => $mh{'title'} . ':journal:abbreviation');
1219 #special pub match if pub uniquename not known
1220 elsif ($ult eq 'pub' && !defined $mh{'uniquename'}) {
1221 $self->{'writer'}->startTag($ult, 'op' => 'match');
1222 #set the match flag, all the sub tags should also have "op"="match"
1226 #if cvterm or cv, lookup only
1227 elsif (($ult eq 'cvterm') || ($ult eq 'cv')) {
1228 $self->{'writer'}->startTag($ult, 'op' => 'lookup');
1231 #if nested tables of match table, match too
1233 $self->{'writer'}->startTag($ult, 'op' => 'match');
1237 $self->{'writer'}->startTag($ult);
1240 #first loop to produce xml for all the table columns
1241 foreach $key (keys %mh)
1243 #print "key: $key\n";
1246 if (index($chadotables, $xx) < 0 && index($chadotables, $yy) < 0)
1249 $self->{'writer'}->startTag($key, 'op' => 'match');
1251 $self->{'writer'}->startTag($key);
1254 my $x = $ult . '.' . $key;
1255 #the column is a foreign key
1256 if (defined $fkey{$x})
1260 $self->_hash2xml($isMatch, $nt, $sh, 0);
1263 #print "$key: $mh{$key}\n";
1264 $self->{'writer'}->characters($mh{$key});
1266 $self->{'writer'}->endTag($key);
1270 #second loop to produce xml for all the nested tables
1271 foreach $key (keys %mh)
1273 #print "key: $key\n";
1277 if (index($chadotables, $xx) > 0 || index($chadotables, $yy) > 0)
1279 #$writer->startTag($key);
1281 #print "$key: ", ref($ntref), "\n";
1282 if (ref($ntref) =~ 'HASH') {
1283 $self->_hash2xml($isMatch, $key, $ntref, 0);
1284 } elsif (ref($ntref) =~ 'ARRAY') {
1285 #print "array dim: ", $#$ntref, "\n";
1286 foreach $ref (@
$ntref) {
1288 $self->_hash2xml($isMatch, $key, $ref, 0);
1291 #$writer->endTag($key);
1296 $self->{'writer'}->endTag($ult);
1299 # $self->{'writer'}->endTag('chado');
1307 #print "acc: $acc\n";
1309 if ($acc =~ /^NM_\d{6}/ || $acc =~ /^NP_\d{6}/ || $acc =~ /^NT_\d{6}/ || $acc =~ /^NC_\d{6}/) {
1311 } elsif ($acc =~ /^XM_\d{6}/ || $acc =~ /^XP_\d{6}/ || $acc =~ /^XR_\d{6}/) {
1313 } elsif ($acc =~ /^[a-zA-Z]{1,2}\d{5,6}/) {
1315 } elsif ($seq->molecule() eq 'protein' && $acc =~ /^[a-zA-z]\d{5}/) {
1317 } elsif ($seq->molecule() eq 'protein' && $acc =~ /^\d{6,7}[a-zA-Z]/) {
1319 } elsif ($acc =~ /\d+/ && $acc !~ /[a-zA-Z]/) {
1321 } elsif ($acc =~ /^CG\d+/ || $acc =~ /^FB[a-z][a-z]\d+/) {
1328 sub _subfeat2featrelhash
{
1330 my $genename = shift;
1331 my $seqtype = shift;
1334 my %srcf = %$r; #srcfeature hash for featureloc.srcfeature_id
1336 my $isanalysis = shift;
1338 my $prim_tag = $feat->primary_tag;
1340 my $sfunique = undef; #subfeature uniquename
1341 my $sfname = undef; #subfeature name
1342 my $sftype = undef; #subfeature type
1344 if ($feat->has_tag('symbol')) {
1345 ($sfunique) = $feat->each_tag_value("symbol");
1346 } elsif ($feat->has_tag('label')) {
1347 ($sfunique) = $feat->each_tag_value("label");
1349 #$self->throw("$prim_tag at " . $feat->start . "\.\." . $feat->end . " does not have symbol or label! To convert into chadoxml, a seq feature must have a /symbol or /label tag holding its unique name.");
1350 #generate feature unique name as <genename>-<feature-type>-<span>
1351 $sfunique = $self->_genFeatUniqueName($genename, $feat);
1354 if ($feat->has_tag('Name')) {
1355 ($sfname) = $feat->each_tag_value("Name");
1358 #feature type translation
1359 if (defined $feattype_args2so{$prim_tag}) {
1360 $sftype = $feattype_args2so{$prim_tag};
1362 $sftype = $prim_tag;
1365 if ($prim_tag eq 'mutation') {
1366 if ($feat->start == $feat->end) {
1367 $sftype = $feattype_args2so{'mutation1'};
1369 $sftype = $feattype_args2so{'mutation2'};
1373 #set is_analysis flag for gene model features
1375 if ($sftype eq 'gene' || $sftype eq 'mRNA' || $sftype eq 'exon' || $sftype eq 'protein' || $sftype eq 'polypeptide') {
1376 $isanal = $isanalysis;
1381 "uniquename" => $sfunique,
1382 "organism_id" => \
%organism,
1383 "type_id" => { 'name' => $sftype, 'cv_id' => { 'name' => $cv_name{'sequence'} }},
1384 "is_analysis" => $isanal || 'false',
1387 #make a copy of %sfhash for passing to this method when recursively called
1389 # "name" => $sfname,
1390 # "uniquename" => $sfunique,
1391 # "organism_id" => \%organism,
1392 # "type_id" => { 'name' => $sftype, 'cv_id' => { 'name' => 'SO'}},
1395 #featureloc for subfeatures
1398 undef(my $is_sfmin_partial);
1399 undef(my $is_sfmax_partial);
1400 undef(my $sfstrand);
1402 $sfmin = $feat->start - 1;
1403 $sfmax = $feat->end;
1404 $sfstrand = $feat->strand();
1406 if ($feat->can('phase')) {
1407 $sfphase = $feat->phase;
1410 #if the gene feature in an mRNA record, cannot use its coordinates, omit featureloc
1411 if ($seqtype eq 'mRNA' && $sftype eq 'gene') {
1413 if ($feat->location->isa('Bio::Location::FuzzyLocationI')) {
1414 if ($feat->location->start_pos_type() ne 'EXACT') {
1415 $is_sfmin_partial = 'true';
1417 if ($feat->location->end_pos_type() ne 'EXACT') {
1418 $is_sfmax_partial = 'true';
1423 "srcfeature_id" => \
%srcf,
1425 "is_fmin_partial" => $is_sfmin_partial || 'false',
1427 "is_fmax_partial" => $is_sfmax_partial || 'false',
1428 "strand" => $sfstrand,
1429 "phase" => $sfphase,
1432 $sfhash{'featureloc'} = \
%sfl;
1437 undef(my @sfdbxrefs); #subfeature dbxrefs
1438 undef(my @sub_featureprops); #subfeature props
1439 undef(my @sub_featuresyns); #subfeature synonyms
1440 undef(my @sub_featurecvterms); #subfeature cvterms
1441 foreach my $tag ($feat->all_tags()) {
1442 #feature_dbxref for features
1443 if ($tag eq 'db_xref' or $tag eq 'dbxref' or $tag eq 'Dbxref') {
1444 my @t1 = $feat->each_tag_value($tag);
1445 #print "# of dbxref: @t1\n";
1446 for my $temp (@t1) {
1449 my $xref = $POSTMATCH;
1450 #print "db: $db; xref: $xref\n";
1452 "db_id" => {'name' => $db},
1453 "accession" => $xref,
1455 my %sfdbx = ('dbxref_id' => \
%acchash);
1456 push (@sfdbxrefs, \
%sfdbx);
1459 } elsif ($tag eq 'Alias') {
1460 @sub_featuresyns = $self->handle_Alias_tag($feat, @sub_featuresyns);
1461 } elsif ($tag eq 'Ontology_term') {
1462 @sub_featurecvterms = $self->handle_Ontology_tag($feat, @sub_featurecvterms);
1463 #featureprop for features, excluding GFF Name & Parent tags
1464 } elsif ($tag ne 'gene' && $tag ne 'symbol' && $tag ne 'Name' && $tag ne 'Parent') {
1465 next if ($tag eq 'parent_id');
1466 next if ($tag eq 'load_id');
1467 foreach my $val ($feat->each_tag_value($tag)) {
1468 my %prophash = undef;
1470 "type_id" => {'name' => $tag, 'cv_id' => {'name' => $tag_cv}},
1473 push(@sub_featureprops, \
%prophash);
1478 if ($feat->can('source')) {
1479 @sfdbxrefs = $self->handle_source($feat,@sfdbxrefs);
1482 if (@sub_featureprops) {
1483 $sfhash{'featureprop'} = \
@sub_featureprops;
1486 $sfhash{'feature_dbxref'} = \
@sfdbxrefs;
1488 if (@sub_featuresyns) {
1489 $sfhash{'feature_synonym'} = \
@sub_featuresyns;
1491 if (@sub_featurecvterms) {
1492 $sfhash{'feature_cvterm'} = \
@sub_featurecvterms;
1495 undef(my @ssfeatrel);
1496 if ($feat->has_tag('locus_tag')) {
1497 ($genename)= $feat->each_tag_value('locus_tag');
1498 } elsif ($feat->has_tag('gene')) {
1499 ($genename)= $feat->each_tag_value('gene');
1502 foreach my $sf ($feat->get_SeqFeatures()) {
1503 #print $sf->primary_tag, "\n";
1504 my $rref = $self->_subfeat2featrelhash($genename, $sftype, $sf, \
%srcf, $tag_cv, $isanalysis);
1505 if (defined $rref) {
1506 push(@ssfeatrel, $rref);
1511 $sfhash{'feature_relationship'} = \
@ssfeatrel;
1514 #subj-obj relationship type
1515 undef(my $reltypename);
1516 $reltypename = return_reltypename
($sftype);
1519 "subject_id" => \
%sfhash,
1520 "type_id" => { 'name' => $reltypename,
1521 'cv_id' => { 'name' => $cv_name{'relationship'} }},
1524 if ($seqtype eq 'mRNA' && $sftype eq 'gene') {
1532 #generate uniquename for feature as: <genename>-<feature-type>-<span> (foo-mRNA-10..1000)
1533 sub _genFeatUniqueName
{
1535 my $genename = shift;
1537 undef(my $uniquename);
1538 my $ftype = $feat->primary_tag;
1539 my $start = $feat->start;
1540 my $end = $feat->end;
1542 if ($feat->has_tag('locus_tag')) {
1543 ($genename) = $feat->each_tag_value("locus_tag");
1544 } elsif ($feat->has_tag('gene')) {
1545 ($genename) = $feat->each_tag_value("gene");
1548 $uniquename = $genename . '-' . $ftype . '-' . $start . "\.\." . $end;
1553 #create uniquename for pubs with no medline id and no FBrf#
1554 #use "<authors>, <year>, <type>" as the uniquename (same as miniref)
1555 #<authors> is <sole-author-surname> if one author,
1556 # or <first-author-surname> and <second-author-surname> if two,
1557 # or <first-author-surname> et al. if more
1558 #sub _CreatePubUname {
1561 # undef(my $pubuname);
1566 #get authors of a reference
1567 #returns ref to the array of author hashes
1568 sub _getRefAuthors
{
1572 my $temp = $ref->authors;
1578 if (index($temp, ' and ') > 0) {
1580 my $lastauthor = $POSTMATCH;
1581 @authors = split(/\, /, $PREMATCH);
1582 push (@authors, $lastauthor);
1584 @authors = split(/\, /, $temp);
1589 foreach $a (@authors) {
1591 #parse the author lastname and givennames
1594 if (index($a, ',') > 0) { #genbank format, last,f.m.
1595 ($last, $given) = split(/\,/, $a);
1596 } elsif (index($a, ' ') > 0) { #embl format, last f.m.
1597 ($last, $given) = split(/ /, $a);
1601 'givennames' => $given,
1603 push(@aut, {author_id
=> \
%au, arank
=> $i});
1609 #no authors, Bio::SeqIO::genbank doesn't pick up 'CONSRTM' line.
1616 #extract submission year from the citation of the submitted reference
1617 #genbank format for the submitted citation: JOURNAL Submitted (DD-MON-YYYY) submitter address
1618 sub _getSubmitYear
{
1620 my $citation = shift;
1622 if ($citation !~ /Submitted/) {
1623 $self->warn("not citation for a submitted reference. cannot extract submission year.");
1626 $citation =~ /Submitted \(\d\d-[a-zA-Z]{3}-\d{4}\)/;
1635 sub _getSubmitAddr
{
1640 my $citation = $ref->location;
1641 if ($citation !~ /Submitted/) {
1642 $self->warn("not citation for a submitted reference. cannot extract submission year.");
1645 $citation =~ /Submitted \(\d\d-[a-zA-Z]{3}-\d{4}\)/;
1650 'author_id' => {'surname' => substr($a, 0, 100)},
1659 =head2 suppress_residues
1661 Title : suppress_residues
1662 Usage : $obj->suppress_residues() #get existing value
1663 $obj->suppress_residues($newval) #set new value
1664 Function : Keep track of the flag to suppress printing of residues in the
1665 chadoxml file. The default it to allow all residues to go into the
1667 Returns : value of suppress_residues (a scalar)
1668 Args : new value of suppress_residues (to set)
1672 sub suppress_residues
{
1674 my $suppress_residues = shift if defined(@_);
1675 return $self->{'suppress_residues'} = $suppress_residues if defined($suppress_residues);
1676 return $self->{'suppress_residues'};
1679 =head2 allow_residues
1681 Title : allow_residues
1682 Usage : $obj->allow_residues() #get existing value
1683 $obj->allow_residues($feature_type) #set new value
1684 Function : Track the allow_residues type. This can be used in conjunction
1685 with the suppress_residues flag to only allow residues from a
1686 specific feature type to be printed in the xml file, for example,
1687 only printing chromosome residues. When suppress_residues is set to
1688 true, then only chromosome features would would go into the xml
1689 file. If suppress_residues is not set, this function has no effect
1690 (since the default is to put all residues in the xml file).
1691 Returns : value of allow_residues (string that corresponds to a feature type)
1692 Args : new value of allow_residues (to set)
1697 sub allow_residues
{
1699 my $allow_residues = shift if defined(@_);
1700 return $self->{'allow_residues'} = $allow_residues if defined($allow_residues);
1701 return $self->{'allow_residues'};
1704 =head2 return_ftype_hash
1706 Title : return_ftype_hash
1707 Usage : $obj->return_ftype_hash()
1708 Function : A simple hash where returning it has be factored out of the main
1709 code to allow subclasses to override it.
1710 Returns : A hash that indicates what the name of the SO term is and what
1711 the name of the Sequence Ontology is in the cv table.
1712 Args : The string that represents the SO term.
1717 sub return_ftype_hash
{
1720 my %ftype_hash = ( "name" => $ftype,
1721 "cv_id" => {"name" => $cv_name{'sequence'} });
1725 =head2 return_reltypename
1727 Title : return_reltypename
1728 Usage : $obj->return_reltypename
1729 Function : Return the appropriate relationship type name depending on the
1730 feature type (typically part_of, but derives_from for polypeptide).
1731 Returns : A relationship type name.
1732 Args : A SO type name.
1737 sub return_reltypename
{
1742 if ($sftype eq 'protein' || $sftype eq 'polypeptide') {
1743 $reltypename = 'derives_from';
1745 $reltypename = 'part_of';
1748 return $reltypename;
1754 Usage : $obj->next_seq
1758 Status : Not implemented (write only adaptor)
1763 my ($self, %argv) = @_;
1765 $self->throw('next_seq is not implemented; this is a write-only adapter.');
1769 =head2 _create_writer
1771 Title : _create_writer
1772 Usage : $obj->_create_writer
1773 Function : Creates XML::Writer object and writes start tag
1774 Returns : Nothing, though the writer persists as part of the chadoxml object
1780 sub _create_writer
{
1783 $self->{'writer'} = new XML
::Writer
(OUTPUT
=> $self->_fh,
1788 $self->{'writer'}->xmlDecl("UTF-8");
1789 $self->{'writer'}->comment("created by Peili Zhang, Flybase, Harvard University\n".
1790 "and Scott Cain, GMOD, Cold Spring Harbor Laboratory");
1793 $self->{'writer'}->startTag('chado');
1798 =head2 close_chadoxml
1800 Title : close_chadoxml
1801 Usage : $obj->close_chadoxml
1802 Function : Writes the closing xml tag
1809 sub close_chadoxml
{
1812 $self->{'writer'}->endTag('chado');
1816 =head2 handle_unreserved_tags
1818 Title : handle_unreserved_tags
1819 Usage : $obj->handle_unreserved_tags
1820 Function : Converts tag value pairs to xml-ready hashrefs
1821 Returns : The array containing the hashrefs
1822 Args : In order: the Seq or SeqFeature object, the key, and the hasharray
1827 sub handle_unreserved_tags
{
1833 my @values = $seq->attributes($key);
1834 for my $value (@values) {
1836 "type_id" => {'name' => $key,
1837 'cv_id' => { 'name' => $cv_name{'feature_property'} }
1841 push(@arr, \
%prophash);
1847 =head2 handle_Alias_tag
1849 Title : handle_Alias_tag
1850 Usage : $obj->handle_Alias_tag
1851 Function : Convert Alias values to synonym hash refs
1852 Returns : An array of synonym hash tags
1853 Args : The seq or seqFeature object and the synonym hash array
1858 sub handle_Alias_tag
{
1863 my @Aliases = $seq->attributes('Alias');
1864 for my $Alias (@Aliases) {
1866 "type_id" => { 'name' => 'exact',
1867 'cv_id' => { 'name' => 'synonym_type' } },
1869 "synonym_sgml" => $Alias,
1871 push(@arr, {'synonym_id' => \
%synhash,
1872 'pub_id' => {'uniquename' => 'null',
1873 'type_id' => { 'name' => 'null',
1885 =head2 handle_Ontology_tag
1887 Title : handle_Ontology_tag
1888 Usage : $obj->handle_Ontology_tag
1889 Function : Convert Ontology_term values to ontology term hash refs
1890 Returns : An array of ontology term hash refs
1891 Args : The seq or seqFeature object and the ontology term array
1896 sub handle_Ontology_tag
{
1901 my @terms = $seq->attributes('Ontology_term');
1902 for my $term (@terms) {
1904 if ($term =~ /(\S+):(\S+)/) {
1910 'db_id' => { 'name' => $db },
1916 push(@arr, {cvterm_id
=> $hashref});
1922 =head2 handle_dbxref
1924 Title : handle_dbxref
1925 Usage : $obj->handle_dbxref
1926 Function : Convert Dbxref values to dbxref hashref
1927 Returns : An array of dbxref hashrefs
1928 Args : A seq or seqFeature object and the dbxref array
1939 my @terms = $seq->attributes($tag);
1940 for my $term (@terms) {
1942 if ($term =~ /(\S+):(\S+)/) {
1946 if ($acc =~ /(\S+)\.(\S+)/) {
1952 'db_id' => { 'name' => $db },
1953 'accession' => $acc,
1954 'version' => $version,
1959 $self->throw("I don't know how to handle a dbxref like $term");
1961 push(@arr, {'dbxref_id' => $hashref});
1966 =head2 handle_source
1968 Title : handle_source
1969 Usage : $obj->handle_source
1982 my $source = $seq->source();
1983 return @arr unless $source;
1987 'db_id' => {'name' => 'GFF_source'},
1988 'accession' => $source,
1992 push(@arr, {'dbxref_id' => $hashref});
1999 Usage : $obj->_srcf_hash
2000 Function : Creates the srcfeature hash for use in featureloc hashes
2001 Returns : The srcfeature hash
2002 Args : The srcfeature name, the srcfeature type and a reference to the
2014 my %hash = ('uniquename' => $srcf,
2015 'organism_id' => $orgref,
2016 'type_id' => {'name' => $stype,
2018 {'name' => $cv_name{'sequence'} }},