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 L<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 Current implementation:
338 1. for non-mRNA records,
339 a top-level feature of type $seq->alphabet is
340 generated for the whole GenBank record, features listed
341 are unflattened for DNA records to build gene model
342 feature graph, and for the other types of records all
343 features in $seq are treated as subfeatures of the top-level
346 if a 'gene' feature is present, it B<must> have a /symbol
347 or /label tag to contain the uniquename of the gene. a top-
348 level feature of type 'gene' is generated. the mRNA is written
349 as a subfeature of the top-level gene feature, and the other
350 sequence features listed in $seq are treated as subfeatures
352 Returns : 1 for success and 0 for error
355 Args : A Bio::Seq object $seq, optional $seqSOtype, $srcfeature,
356 $srcfeattype, $nounflatten, $is_analysis and $data_source.
357 when $srcfeature (a string, the uniquename of the source
358 feature) is given, the location and strand information of
359 the top-level feature against the source feature will be
360 derived from the sequence feature called 'source' of the
361 $seq object, a featureloc record is generated for the top
362 -level feature on $srcfeature. when $srcfeature is given,
363 $srcfeattype must also be present. All feature coordinates
364 in $seq should be against $srcfeature. $seqSOtype is the
365 optional SO term to use as the type of the top-level feature.
366 For example, a GenBank data file for a Drosophila melanogaster
367 genome scaffold has the molecule type of "DNA", when
368 converting to chadoxml, a $seqSOtype argument of
369 "golden_path_region" can be supplied to save the scaffold
370 as a feature of type "golden_path_region" in chadoxml, instead
371 of "DNA". a feature with primary tag of 'source' must be
372 present in the sequence feature list of $seq, to decribe the
373 whole sequence record.
379 my $usage = <<EOUSAGE;
380 Bio::SeqIO::chadoxml->write_seq()
381 Usage : \$stream->write_seq(-seq=>\$seq,
382 -seq_so_type=>\$SOtype,
383 -src_feature=>\$srcfeature,
384 -src_feat_type=>\$srcfeattype,
385 -nounflatten=>0 or 1,
386 -is_analysis=>'true' or 'false',
387 -data_source=>\$datasource)
388 Args : \$seq : a Bio::Seq object
389 \$SOtype : the SO term to use as the feature type of
390 the \$seq record, optional
391 \$srcfeature : unique name of the source feature, a string
392 containing at least one alphabetical letter
394 \$srcfeattype : feature type of \$srcfeature. one of SO terms.
396 when \$srcfeature is given, \$srcfeattype becomes mandatory,
397 \$datasource : source of the sequence annotation data,
398 e.g. 'GenBank' or 'GFF'.
401 my ($self,@args) = @_;
403 my ($seq, $seq_so_type, $srcfeature, $srcfeattype, $nounflatten, $isanalysis, $datasource, $genus, $species) =
404 $self->_rearrange([qw(SEQ
415 #print "$seq_so_type, $srcfeature, $srcfeattype\n";
417 if( !defined $seq ) {
418 $self->throw("Attempting to write with no seq!");
421 if( ! ref $seq || ! $seq->isa('Bio::Seq::RichSeqI') ) {
422 ## FIXME $self->warn(" $seq is not a RichSeqI compliant module. Attempting to dump, but may fail!");
425 # try to get the srcfeature from the seqFeature object
426 # for this to work, the user has to pass in the srcfeature type
428 if ($seq->can('seq_id')) {
429 $srcfeature=$seq->seq_id if ($seq->seq_id ne $seq->display_name);
433 #$srcfeature, when provided, should contain at least one alphabetical letter
434 if (defined $srcfeature)
436 if ($srcfeature =~ /[a-zA-Z]/)
440 $self->throw( $usage );
443 #check for mandatory $srcfeattype
444 if (! defined $srcfeattype)
446 $self->throw( $usage );
447 #$srcfeattype must be a string of non-whitespace characters
449 if ($srcfeattype =~ /\S+/) {
452 $self->throw( $usage );
457 # variables local to write_seq()
460 undef(my @top_featureprops);
461 undef(my @featuresyns);
462 undef(my @top_featurecvterms);
463 my $name = $seq->display_id if $seq->can('display_id');
464 $name = $seq->display_name if $seq->can('display_name');
465 undef(my @feature_cvterms);
472 undef(my @references);
473 undef(my @feature_pubs);
475 my $location = undef;
480 my $volumeissue = undef;
484 # my $miniref= undef;
485 my $uniquename = undef;
491 my $subfeatcnt = undef;
492 undef(my @top_featrels);
493 undef (my %srcfhash);
495 local($^W
) = 0; # supressing warnings about uninitialized fields.
497 if (!$name && $seq->can('attributes') ) {
498 ($name) = $seq->attributes('Alias');
501 if ($seq->can('accession_number') && defined $seq->accession_number && $seq->accession_number ne 'unknown') {
502 $uniquename = $seq->accession_number;
503 } elsif ($seq->can('accession') && defined $seq->accession && $seq->accession ne 'unknown') {
504 $uniquename = $seq->accession;
505 } elsif ($seq->can('attributes')) {
506 ($uniquename) = $seq->attributes('load_id');
510 my $len = $seq->length();
516 if (!$seq->can('molecule') || ! defined ($gb_type = $seq->molecule()) ) {
517 $gb_type = $seq->can('alphabet') ?
$seq->alphabet : 'DNA';
519 $gb_type = 'DNA' if $ftype eq 'dna';
520 $gb_type = 'RNA' if $ftype eq 'rna';
522 if(length $seq_so_type > 0) {
523 if (defined $seq_so_type) {
524 $ftype = $seq_so_type;
527 $ftype = ($seq->type =~ /(.*):/)
539 my %ftype_hash = $self->return_ftype_hash($ftype);
542 %organism = ("genus"=>$genus, "species" => $species);
545 my $spec = $seq->species();
546 if (!defined $spec) {
547 $self->throw("$seq does not know what organism it is from, which is required by chado. cannot proceed!\n");
549 %organism = ("genus"=>$spec->genus(), "species" => $spec->species());
554 if (!$self->suppress_residues ||
555 ($self->suppress_residues && $self->allow_residues eq $ftype)) {
556 $residues = $seq->seq->isa('Bio::PrimarySeq')
564 #set is_analysis flag for gene model features
566 if ($ftype eq 'gene' || $ftype eq 'mRNA' || $ftype eq 'exon' || $ftype eq 'protein' || $ftype eq 'polypeptide') {
567 $isanal = $isanalysis;
568 $isanal = 'false' if !defined $isanal;
573 "uniquename" => $uniquename,
575 "residues" => $residues,
576 "type_id" => \
%ftype_hash,
577 "organism_id" => \
%organism,
578 "is_analysis" => $isanal || 'false',
581 if (defined $srcfeature) {
582 %srcfhash = $self->_srcf_hash($srcfeature,
587 if ($seq->can('phase')) {
588 $phase = $seq->phase;
591 if ($seq->can('strand')) {
592 $strand = $seq->strand;
595 "srcfeature_id" => \
%srcfhash,
596 "fmin" => $seq->start - 1,
602 $datahash{'featureloc'} = \
%fl;
607 #if $srcfeature is not given, use the Bio::Seq object itself as the srcfeature for featureloc's
608 if (!defined $srcfeature) {
609 $srcfeature = $uniquename;
610 $srcfeattype = $ftype;
613 #default data source is 'GenBank'
614 if (!defined $datasource) {
615 $datasource = 'GenBank';
618 if ($datasource =~ /GenBank/i) {
619 #sequence topology as feature_cvterm
620 if ($seq->can('is_circular') && $seq->is_circular) {
622 "cvterm_id" => {'name' => 'circular',
624 'name' => 'sequence topology',
627 "pub_id" => {'uniquename' => 'nullpub',
629 'name' => 'null pub',
638 "cvterm_id" => { 'name' => 'linear',
640 'name' => 'sequence topology',
643 "pub_id" => {'uniquename' => 'nullpub',
645 'name' => 'null pub',
653 push(@feature_cvterms, \
%sthash);
655 #division as feature_cvterm
656 if ($seq->can('division') && defined $seq->division()) {
657 $div = $seq->division();
659 "cvterm_id" => {'name' => $div,
661 'name' => 'GenBank division'}},
662 "pub_id" => {'uniquename' => 'nullpub',
664 'name' => 'null pub',
666 'name'=> 'pub type'},
669 push(@feature_cvterms, \
%dvhash);
672 $datahash{'feature_cvterm'} = \
@feature_cvterms;
673 } # closes if GenBank
677 if ($seq->can('desc') && defined $seq->desc()) {
678 $temp = $seq->desc();
681 "type_id" => {'name' => 'description',
684 $cv_name{'feature_property'}
690 push(@top_featureprops, \
%prophash);
694 if ($seq->can('keywords')) {
695 $temp = $seq->keywords();
697 if (defined $temp && $temp ne '.' && $temp ne '') {
699 "type_id" => {'name' => 'keywords',
702 $cv_name{'feature_property'}
708 push(@top_featureprops, \
%prophash);
713 if ($seq->can('annotation')) {
714 $ann = $seq->annotation();
715 foreach my $comment ($ann->get_Annotations('comment')) {
716 $temp = $comment->as_text();
717 #print "fcomment: $temp\n";
719 "type_id" => {'name' => 'comment',
722 $cv_name{'feature_property'}
728 push(@top_featureprops, \
%prophash);
732 my @top_dbxrefs = ();
733 #feature object from Bio::DB::SeqFeature::Store
734 if ($seq->can('attributes')) {
735 my %attributes = $seq->attributes;
736 for my $key (keys %attributes) {
737 next if ($key eq 'parent_id');
738 next if ($key eq 'load_id');
740 if ($key eq 'Alias') {
741 @featuresyns = $self->handle_Alias_tag($seq,@featuresyns);
744 ###FIXME deal with Dbxref, Ontology_term,source,
745 elsif ($key eq 'Ontology_term') {
746 @top_featurecvterms = $self->handle_Ontology_tag($seq,@top_featurecvterms);
749 elsif ($key eq 'dbxref' or $key eq 'Dbxref') {
750 @top_dbxrefs = $self->handle_dbxref($seq, $key, @top_dbxrefs);
753 elsif ($key =~ /^[a-z]/) {
755 = $self->handle_unreserved_tags($seq,$key,@top_featureprops);
759 $datahash{'feature_synonym'} = \
@featuresyns;
761 if ($seq->can('source')) {
762 @top_dbxrefs = $self->handle_source($seq,@top_dbxrefs);
765 #accession and version as feature_dbxref
766 if ($seq->can('accession_number') && defined $seq->accession_number && $seq->accession_number ne 'unknown') {
767 my $db = $self->_guess_acc_db($seq, $seq->accession_number);
769 "db_id" => {'name' => $db},
770 "accession" => $seq->accession_number,
771 "version" => $seq->seq_version,
773 my %fdbx = ('dbxref_id' => \
%acchash);
774 push(@top_dbxrefs, \
%fdbx);
777 if( $seq->isa('Bio::Seq::RichSeqI') && defined $seq->get_secondary_accessions() ) {
778 my @secacc = $seq->get_secondary_accessions();
780 foreach $acc (@secacc) {
782 "db_id" => {'name' => 'GB'},
785 my %fdbx = ('dbxref_id' => \
%acchash);
786 push(@top_dbxrefs, \
%fdbx);
791 if( $seq->isa('Bio::Seq::RichSeqI') && defined ($seq->pid)) {
793 #print "reftype: ", ref($id), "\n";
795 #if (ref($id) eq 'HASH') {
797 "db_id" => {'name' => 'GI'},
800 my %fdbx = ('dbxref_id' => \
%acchash);
801 push (@top_dbxrefs, \
%fdbx);
804 #REFERENCES as feature_pub
807 @references = $ann->get_Annotations('reference');
808 foreach $ref (@references) {
810 $refhash = $ref->hash_tree();
811 $location = $ref->location || $refhash->{'location'};
812 #print "location: $location\n";
814 #get FBrf#, special for FlyBase SEAN loading
815 if (index($location, ' ==') >= 0) {
817 #print "match: $MATCH\n";
818 #print "prematch: $PREMATCH\n";
819 #print "postmatch: $POSTMATCH\n";
821 $location = $POSTMATCH;
822 $location =~ s/^\s//;
825 #print "location: $location\n";
826 #unpublished reference
827 if ($location =~ /Unpublished/) {
828 $pubtype = 'unpublished';
830 "title" => $ref->title || $refhash->{'title'},
831 #"miniref" => substr($location, 0, 255),
832 #"uniquename" => $fbrf,
833 "type_id" => {'name' => $pubtype, 'cv_id' => {'name' =>'pub type'}}
837 elsif ($location =~ /Submitted/) {
838 $pubtype = 'submitted';
841 "title" => $ref->title || $refhash->{'title'},
842 #"miniref" => substr($location, 0, 255),
843 #"uniquename" => $fbrf,
844 "type_id" => {'name' => $pubtype, 'cv_id' => {'name' =>'pub type'}}
848 $pyear = $self->_getSubmitYear($location);
849 if (defined $pyear) {
850 $pubhash{'pyear'} = $pyear;
854 #published journal paper
855 elsif ($location =~ /\D+\s\d+\s\((\d+|\d+-\d+)\),\s(\d+-\d+|\d+--\d+)\s\(\d\d\d\d\)$/) {
858 #parse location to get journal, volume, issue, pages & year
859 $location =~ /\(\d\d\d\d\)$/;
862 my $stuff = $PREMATCH;
863 $year =~ s/\(//; #remove the leading parenthesis
864 $year =~ s/\)//; #remove the trailing parenthesis
866 $stuff =~ /,\s(\d+-\d+|\d+--\d+)\s$/;
870 $pages =~ s/^, //; #remove the leading comma and space
871 $pages =~ s/ $//; #remove the last space
873 $stuff =~ /\s\d+\s\((\d+|\d+-\d+)\)$/;
875 $volumeissue = $MATCH;
876 $journal = $PREMATCH;
877 $volumeissue =~ s/^ //; #remove the leading space
878 $volumeissue =~ /\((\d+|\d+-\d+)\)$/;
881 $issue =~ s/^\(//; #remove the leading parentheses
882 $issue =~ s/\)$//; #remove the last parentheses
883 $volume =~ s/^\s//; #remove the leading space
884 $volume =~ s/\s$//; #remove the last space
887 "title" => $ref->title || $refhash->{'title'},
892 #"miniref" => substr($location, 0, 255),
894 #"uniquename" => $fbrf,
895 "type_id" => {'name' => $pubtype, 'cv_id' => {'name' =>'pub type'}},
896 "pub_relationship" => {
898 'uniquename' => $journal,
900 #'miniref' => substr($journal, 0, 255),
901 'type_id' =>{'name' => 'journal',
903 {'name' => 'pub type'
906 #'pubprop' =>{'value'=> $journal,
907 # 'type_id'=>{'name' => 'abbreviation', 'cv_id' => {'name' => 'pubprop type'}},
911 'name' => 'published_in',
913 'name' => 'pub relationship type'},
923 "title" => $ref->title || $refhash->{'title'},
927 'cv_id' => {'name' =>'pub type'}
933 my $autref = $self->_getRefAuthors($ref);
934 if (defined $autref) {
935 $pubhash{'pub_author'} = $autref;
937 # if no author and is type 'submitted' and has submitter address, use the first 100 characters of submitter address as the author lastname.
939 if ($pubtype eq 'submitted') {
940 my $autref = $self->_getSubmitAddr($ref);
941 if (defined $autref) {
942 $pubhash{'pub_author'} = $autref;
947 #$ref->comment as pubprop
948 #print "ref comment: ", $ref->comment, "\n";
949 #print "ref comment: ", $refhash->{'comment'}, "\n";
950 if (defined $ref->comment || defined $refhash->{'comment'}) {
951 my $comnt = $ref->comment || $refhash->{'comment'};
952 #print "remark: ", $comnt, "\n";
953 $pubhash{'pubprop'} = {
954 "type_id" => {'name' => 'comment', 'cv_id' => {'name' => 'pubprop type'}},
960 undef(my @pub_dbxrefs);
962 push(@pub_dbxrefs, {dbxref_id
=> {accession
=> $fbrf, db_id
=> {'name' => 'FlyBase'}}});
964 if (defined ($temp = $ref->medline)) {
965 push(@pub_dbxrefs, {dbxref_id
=> {accession
=> $temp, db_id
=> {'name' => 'MEDLINE'}}});
966 #use medline # as the pub's uniquename
967 $pubhash{'uniquename'} = $temp;
969 if (defined ($temp = $ref->pubmed)) {
970 push(@pub_dbxrefs, {dbxref_id
=> {accession
=> $temp, db_id
=> {'name' => 'PUBMED'}}});
972 $pubhash{'pub_dbxref'} = \
@pub_dbxrefs;
974 #if the pub uniquename is not defined or blank, put its FBrf# as its uniquename
975 #this is unique to FlyBase
976 #USERS OF THIS MODULE: PLEASE MODIFY HERE TO IMPLEMENT YOUR POLICY
977 # ON PUB UNIQUENAME!!!
978 if (!defined $pubhash{'uniquename'} || $pubhash{'uniquename'} eq '') {
980 $pubhash{'uniquename'} = $fbrf;
983 # $pubhash{'uniquename'} = $self->_CreatePubUname($ref);
987 #add to collection of references
988 #if the pub covers the entire sequence of the top-level feature, add it to feature_pubs
989 if (($ref->start == 1 && $ref->end == $len) || (!defined $ref->start && !defined $ref->end)) {
990 push(@feature_pubs, {"pub_id" => \
%pubhash});
992 #the pub is about a sub-sequence of the top-level feature
993 #create a feature for the sub-sequence and add pub as its feature_pub
994 #featureloc of this sub-sequence is against the top-level feature, in interbase coordinates.
997 'uniquename' => $uniquename . ':' . $ref->start . "\.\." . $ref->end,
998 'organism_id' =>\
%organism,
999 'type_id' =>{'name' =>'region', 'cv_id' => {'name' => $cv_name{'sequence'} }},
1002 'uniquename' => $uniquename,
1003 'organism_id' =>\
%organism,
1006 'srcfeature_id' => \
%parfsrcf,
1007 'fmin' => $ref->start - 1,
1008 'fmax' => $ref->end,
1010 $parf{'featureloc'} = \
%parfloc;
1011 $parf{'feature_pub'} = {'pub_id' => \
%pubhash};
1013 'subject_id' => \
%parf,
1014 'type_id' => { 'name' => 'partof', 'cv_id' => { 'name' => $cv_name{'relationship'}}},
1016 push(@top_featrels, \
%ffr);
1019 $datahash{'feature_pub'} = \
@feature_pubs;
1022 ##construct srcfeature hash for use in featureloc
1023 if (defined $srcfeature) {
1024 %srcfhash = $self->_srcf_hash($srcfeature,
1028 # "object_id" => \%srcfhash,
1029 # "type_id" => { 'name' => 'partof', 'cv_id' => { 'name' => 'relationship type'}},
1032 # push (@top_featrels, \%fr);
1035 #unflatten the seq features in $seq if $seq is a gene or a DNA sequence
1036 if (($gb_type eq 'gene' || $gb_type eq 'DNA') &&
1038 my $u = Bio
::SeqFeature
::Tools
::Unflattener
->new;
1039 $u->unflatten_seq(-seq
=>$seq, -use_magic
=>1);
1042 my @top_sfs = $seq->get_SeqFeatures;
1043 #print $#top_sfs, "\n";
1047 if ($datasource =~ /GenBank/i) {
1048 $tag_cv = 'GenBank feature qualifier';
1049 } elsif ($datasource =~ /GFF/i) {
1050 $tag_cv = 'feature_property';
1052 $tag_cv = $cv_name{'feature_property'};
1056 foreach $feat (@top_sfs) {
1057 #$feat = $top_sfs[$si];
1059 my $prim_tag = $feat->primary_tag;
1060 #print $prim_tag, "\n";
1062 # get all qualifiers of the 'source' feature, load these as top_featureprops of the top level feature
1063 if ($prim_tag eq 'source') {
1064 foreach $tag ($feat->all_tags()) {
1066 if ($tag eq 'db_xref'
1068 or $tag eq 'dbxref') {
1069 my @t1 = $feat->each_tag_value($tag);
1070 foreach $temp (@t1) {
1071 $temp =~ /([^:]*?):(.*)/;
1074 #PRE/POST very inefficent
1075 #my $db = $PREMATCH;
1076 #my $xref = $POSTMATCH;
1078 "db_id" => {'name' => $db},
1079 "accession" => $xref,
1081 my %fdbx = ('dbxref_id' => \
%acchash);
1082 push (@top_dbxrefs, \
%fdbx);
1085 } elsif ($tag eq 'Ontology_term') {
1086 my @t1 = $feat->each_tag_value($tag);
1087 foreach $temp (@t1) {
1090 #other tags as featureprop
1091 } elsif ($tag ne 'gene') {
1092 my %prophash = undef;
1094 "type_id" => {'name' => $tag, 'cv_id' => {'name' => $tag_cv}},
1095 "value" => join(' ',$feat->each_tag_value($tag)),
1097 push(@top_featureprops, \
%prophash);
1101 if ($feat->can('source')) {
1102 my $source = $feat->source();
1103 @top_dbxrefs = $self->handle_source($feat, @top_dbxrefs);
1106 #featureloc for the top-level feature
1113 $fmin = $feat->start - 1;
1115 $strand = $feat->strand;
1117 if ($feat->can('phase')) {
1118 $phase = $feat->phase;
1122 "srcfeature_id" => \
%srcfhash,
1125 "strand" => $strand,
1129 $datahash{'featureloc'} = \
%fl;
1131 #delete 'source' feature from @top_sfs
1132 splice(@top_sfs, $si, 1);
1135 #close loop over top_sfs
1138 #the top-level features other than 'source'
1139 foreach $feat (@top_sfs) {
1140 #print $feat->primary_tag, "\n";
1142 my $r = $self->_subfeat2featrelhash($name, $ftype, $feat, \
%srcfhash, $tag_cv, $isanalysis);
1144 if (!($ftype eq 'mRNA' && $feat->primary_tag eq 'gene')) {
1146 push(@top_featrels, \
%fr);
1148 %finaldatahash = %$r;
1153 $datahash{'feature_dbxref'} = \
@top_dbxrefs;
1156 if (@top_featureprops) {
1157 $datahash{'featureprop'} = \
@top_featureprops;
1160 if (@top_featrels) {
1161 $datahash{'feature_relationship'} = \
@top_featrels;
1164 if (@top_featurecvterms) {
1165 $datahash{'feature_cvterm'} = \
@top_featurecvterms;
1168 if ($ftype eq 'mRNA' && %finaldatahash) {
1169 $finaldatahash{'feature_relationship'} = {
1170 'subject_id' => \
%datahash,
1171 'type_id' => { 'name' => 'partof', 'cv_id' => { 'name' => $cv_name{'relationship'} }},
1174 %finaldatahash = %datahash;
1177 my $mainTag = 'feature';
1178 $self->_hash2xml(undef, $mainTag, \
%finaldatahash);
1185 my $isMatch = undef;
1198 my $root = shift if (@_);
1199 #print "ult: $ult\n";
1200 if (!defined $self->{'writer'}) {
1202 $self->_create_writer();
1208 #if pub record of type 'journal', form the 'ref' attribute for special pub lookup
1209 #requires that the journal name itself is also stored as a pubprop record for the journal with value equal
1210 #to the journal name and type of 'abbreviation'.
1211 if ($ult eq 'pub' && $mh{'type_id'}->{'name'} eq 'journal') {
1212 $self->{'writer'}->startTag($ult, 'ref' => $mh{'title'} . ':journal:abbreviation');
1215 #special pub match if pub uniquename not known
1216 elsif ($ult eq 'pub' && !defined $mh{'uniquename'}) {
1217 $self->{'writer'}->startTag($ult, 'op' => 'match');
1218 #set the match flag, all the sub tags should also have "op"="match"
1222 #if cvterm or cv, lookup only
1223 elsif (($ult eq 'cvterm') || ($ult eq 'cv')) {
1224 $self->{'writer'}->startTag($ult, 'op' => 'lookup');
1227 #if nested tables of match table, match too
1229 $self->{'writer'}->startTag($ult, 'op' => 'match');
1233 $self->{'writer'}->startTag($ult);
1236 #first loop to produce xml for all the table columns
1237 foreach $key (keys %mh)
1239 #print "key: $key\n";
1242 if (index($chadotables, $xx) < 0 && index($chadotables, $yy) < 0)
1245 $self->{'writer'}->startTag($key, 'op' => 'match');
1247 $self->{'writer'}->startTag($key);
1250 my $x = $ult . '.' . $key;
1251 #the column is a foreign key
1252 if (defined $fkey{$x})
1256 $self->_hash2xml($isMatch, $nt, $sh, 0);
1259 #print "$key: $mh{$key}\n";
1260 $self->{'writer'}->characters($mh{$key});
1262 $self->{'writer'}->endTag($key);
1266 #second loop to produce xml for all the nested tables
1267 foreach $key (keys %mh)
1269 #print "key: $key\n";
1273 if (index($chadotables, $xx) > 0 || index($chadotables, $yy) > 0)
1275 #$writer->startTag($key);
1277 #print "$key: ", ref($ntref), "\n";
1278 if (ref($ntref) =~ 'HASH') {
1279 $self->_hash2xml($isMatch, $key, $ntref, 0);
1280 } elsif (ref($ntref) =~ 'ARRAY') {
1281 #print "array dim: ", $#$ntref, "\n";
1282 foreach $ref (@
$ntref) {
1284 $self->_hash2xml($isMatch, $key, $ref, 0);
1287 #$writer->endTag($key);
1292 $self->{'writer'}->endTag($ult);
1295 # $self->{'writer'}->endTag('chado');
1303 #print "acc: $acc\n";
1305 if ($acc =~ /^NM_\d{6}/ || $acc =~ /^NP_\d{6}/ || $acc =~ /^NT_\d{6}/ || $acc =~ /^NC_\d{6}/) {
1307 } elsif ($acc =~ /^XM_\d{6}/ || $acc =~ /^XP_\d{6}/ || $acc =~ /^XR_\d{6}/) {
1309 } elsif ($acc =~ /^[a-zA-Z]{1,2}\d{5,6}/) {
1311 } elsif ($seq->molecule() eq 'protein' && $acc =~ /^[a-zA-z]\d{5}/) {
1313 } elsif ($seq->molecule() eq 'protein' && $acc =~ /^\d{6,7}[a-zA-Z]/) {
1315 } elsif ($acc =~ /\d+/ && $acc !~ /[a-zA-Z]/) {
1317 } elsif ($acc =~ /^CG\d+/ || $acc =~ /^FB[a-z][a-z]\d+/) {
1324 sub _subfeat2featrelhash
{
1326 my $genename = shift;
1327 my $seqtype = shift;
1330 my %srcf = %$r; #srcfeature hash for featureloc.srcfeature_id
1332 my $isanalysis = shift;
1334 my $prim_tag = $feat->primary_tag;
1336 my $sfunique = undef; #subfeature uniquename
1337 my $sfname = undef; #subfeature name
1338 my $sftype = undef; #subfeature type
1340 if ($feat->has_tag('symbol')) {
1341 ($sfunique) = $feat->each_tag_value("symbol");
1342 } elsif ($feat->has_tag('label')) {
1343 ($sfunique) = $feat->each_tag_value("label");
1345 #$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.");
1346 #generate feature unique name as <genename>-<feature-type>-<span>
1347 $sfunique = $self->_genFeatUniqueName($genename, $feat);
1350 if ($feat->has_tag('Name')) {
1351 ($sfname) = $feat->each_tag_value("Name");
1354 #feature type translation
1355 if (defined $feattype_args2so{$prim_tag}) {
1356 $sftype = $feattype_args2so{$prim_tag};
1358 $sftype = $prim_tag;
1361 if ($prim_tag eq 'mutation') {
1362 if ($feat->start == $feat->end) {
1363 $sftype = $feattype_args2so{'mutation1'};
1365 $sftype = $feattype_args2so{'mutation2'};
1369 #set is_analysis flag for gene model features
1371 if ($sftype eq 'gene' || $sftype eq 'mRNA' || $sftype eq 'exon' || $sftype eq 'protein' || $sftype eq 'polypeptide') {
1372 $isanal = $isanalysis;
1377 "uniquename" => $sfunique,
1378 "organism_id" => \
%organism,
1379 "type_id" => { 'name' => $sftype, 'cv_id' => { 'name' => $cv_name{'sequence'} }},
1380 "is_analysis" => $isanal || 'false',
1383 #make a copy of %sfhash for passing to this method when recursively called
1385 # "name" => $sfname,
1386 # "uniquename" => $sfunique,
1387 # "organism_id" => \%organism,
1388 # "type_id" => { 'name' => $sftype, 'cv_id' => { 'name' => 'SO'}},
1391 #featureloc for subfeatures
1394 undef(my $is_sfmin_partial);
1395 undef(my $is_sfmax_partial);
1396 undef(my $sfstrand);
1398 $sfmin = $feat->start - 1;
1399 $sfmax = $feat->end;
1400 $sfstrand = $feat->strand();
1402 if ($feat->can('phase')) {
1403 $sfphase = $feat->phase;
1406 #if the gene feature in an mRNA record, cannot use its coordinates, omit featureloc
1407 if ($seqtype eq 'mRNA' && $sftype eq 'gene') {
1409 if ($feat->location->isa('Bio::Location::FuzzyLocationI')) {
1410 if ($feat->location->start_pos_type() ne 'EXACT') {
1411 $is_sfmin_partial = 'true';
1413 if ($feat->location->end_pos_type() ne 'EXACT') {
1414 $is_sfmax_partial = 'true';
1419 "srcfeature_id" => \
%srcf,
1421 "is_fmin_partial" => $is_sfmin_partial || 'false',
1423 "is_fmax_partial" => $is_sfmax_partial || 'false',
1424 "strand" => $sfstrand,
1425 "phase" => $sfphase,
1428 $sfhash{'featureloc'} = \
%sfl;
1433 undef(my @sfdbxrefs); #subfeature dbxrefs
1434 undef(my @sub_featureprops); #subfeature props
1435 undef(my @sub_featuresyns); #subfeature synonyms
1436 undef(my @sub_featurecvterms); #subfeature cvterms
1437 foreach my $tag ($feat->all_tags()) {
1438 #feature_dbxref for features
1439 if ($tag eq 'db_xref' or $tag eq 'dbxref' or $tag eq 'Dbxref') {
1440 my @t1 = $feat->each_tag_value($tag);
1441 #print "# of dbxref: @t1\n";
1442 for my $temp (@t1) {
1445 my $xref = $POSTMATCH;
1446 #print "db: $db; xref: $xref\n";
1448 "db_id" => {'name' => $db},
1449 "accession" => $xref,
1451 my %sfdbx = ('dbxref_id' => \
%acchash);
1452 push (@sfdbxrefs, \
%sfdbx);
1455 } elsif ($tag eq 'Alias') {
1456 @sub_featuresyns = $self->handle_Alias_tag($feat, @sub_featuresyns);
1457 } elsif ($tag eq 'Ontology_term') {
1458 @sub_featurecvterms = $self->handle_Ontology_tag($feat, @sub_featurecvterms);
1459 #featureprop for features, excluding GFF Name & Parent tags
1460 } elsif ($tag ne 'gene' && $tag ne 'symbol' && $tag ne 'Name' && $tag ne 'Parent') {
1461 next if ($tag eq 'parent_id');
1462 next if ($tag eq 'load_id');
1463 foreach my $val ($feat->each_tag_value($tag)) {
1464 my %prophash = undef;
1466 "type_id" => {'name' => $tag, 'cv_id' => {'name' => $tag_cv}},
1469 push(@sub_featureprops, \
%prophash);
1474 if ($feat->can('source')) {
1475 @sfdbxrefs = $self->handle_source($feat,@sfdbxrefs);
1478 if (@sub_featureprops) {
1479 $sfhash{'featureprop'} = \
@sub_featureprops;
1482 $sfhash{'feature_dbxref'} = \
@sfdbxrefs;
1484 if (@sub_featuresyns) {
1485 $sfhash{'feature_synonym'} = \
@sub_featuresyns;
1487 if (@sub_featurecvterms) {
1488 $sfhash{'feature_cvterm'} = \
@sub_featurecvterms;
1491 undef(my @ssfeatrel);
1492 if ($feat->has_tag('locus_tag')) {
1493 ($genename)= $feat->each_tag_value('locus_tag');
1494 } elsif ($feat->has_tag('gene')) {
1495 ($genename)= $feat->each_tag_value('gene');
1498 foreach my $sf ($feat->get_SeqFeatures()) {
1499 #print $sf->primary_tag, "\n";
1500 my $rref = $self->_subfeat2featrelhash($genename, $sftype, $sf, \
%srcf, $tag_cv, $isanalysis);
1501 if (defined $rref) {
1502 push(@ssfeatrel, $rref);
1507 $sfhash{'feature_relationship'} = \
@ssfeatrel;
1510 #subj-obj relationship type
1511 undef(my $reltypename);
1512 $reltypename = return_reltypename
($sftype);
1515 "subject_id" => \
%sfhash,
1516 "type_id" => { 'name' => $reltypename,
1517 'cv_id' => { 'name' => $cv_name{'relationship'} }},
1520 if ($seqtype eq 'mRNA' && $sftype eq 'gene') {
1528 #generate uniquename for feature as: <genename>-<feature-type>-<span> (foo-mRNA-10..1000)
1529 sub _genFeatUniqueName
{
1531 my $genename = shift;
1533 undef(my $uniquename);
1534 my $ftype = $feat->primary_tag;
1535 my $start = $feat->start;
1536 my $end = $feat->end;
1538 if ($feat->has_tag('locus_tag')) {
1539 ($genename) = $feat->each_tag_value("locus_tag");
1540 } elsif ($feat->has_tag('gene')) {
1541 ($genename) = $feat->each_tag_value("gene");
1544 $uniquename = $genename . '-' . $ftype . '-' . $start . "\.\." . $end;
1549 #create uniquename for pubs with no medline id and no FBrf#
1550 #use "<authors>, <year>, <type>" as the uniquename (same as miniref)
1551 #<authors> is <sole-author-surname> if one author,
1552 # or <first-author-surname> and <second-author-surname> if two,
1553 # or <first-author-surname> et al. if more
1554 #sub _CreatePubUname {
1557 # undef(my $pubuname);
1562 #get authors of a reference
1563 #returns ref to the array of author hashes
1564 sub _getRefAuthors
{
1568 my $temp = $ref->authors;
1574 if (index($temp, ' and ') > 0) {
1576 my $lastauthor = $POSTMATCH;
1577 @authors = split(/\, /, $PREMATCH);
1578 push (@authors, $lastauthor);
1580 @authors = split(/\, /, $temp);
1585 foreach $a (@authors) {
1587 #parse the author lastname and givennames
1590 if (index($a, ',') > 0) { #genbank format, last,f.m.
1591 ($last, $given) = split(/\,/, $a);
1592 } elsif (index($a, ' ') > 0) { #embl format, last f.m.
1593 ($last, $given) = split(/ /, $a);
1597 'givennames' => $given,
1599 push(@aut, {author_id
=> \
%au, arank
=> $i});
1605 #no authors, Bio::SeqIO::genbank doesn't pick up 'CONSRTM' line.
1612 #extract submission year from the citation of the submitted reference
1613 #genbank format for the submitted citation: JOURNAL Submitted (DD-MON-YYYY) submitter address
1614 sub _getSubmitYear
{
1616 my $citation = shift;
1618 if ($citation !~ /Submitted/) {
1619 $self->warn("not citation for a submitted reference. cannot extract submission year.");
1622 $citation =~ /Submitted \(\d\d-[a-zA-Z]{3}-\d{4}\)/;
1631 sub _getSubmitAddr
{
1636 my $citation = $ref->location;
1637 if ($citation !~ /Submitted/) {
1638 $self->warn("not citation for a submitted reference. cannot extract submission year.");
1641 $citation =~ /Submitted \(\d\d-[a-zA-Z]{3}-\d{4}\)/;
1646 'author_id' => {'surname' => substr($a, 0, 100)},
1656 =head2 suppress_residues
1662 $obj->suppress_residues() #get existing value
1663 $obj->suppress_residues($newval) #set new value
1667 Keep track of the flag to suppress printing of residues in the chadoxml file.
1668 The default it to allow all residues to go into the file.
1672 value of suppress_residues (a scalar)
1676 new value of suppress_residues (to set)
1682 sub suppress_residues
{
1684 my $suppress_residues = shift if defined(@_);
1685 return $self->{'suppress_residues'} = $suppress_residues if defined($suppress_residues);
1686 return $self->{'suppress_residues'};
1689 =head2 allow_residues
1695 $obj->allow_residues() #get existing value
1696 $obj->allow_residues($feature_type) #set new value
1700 Track the allow_residues type. This can be used in conjunction with the
1701 suppress_residues flag to only allow residues from a specific feature type
1702 to be printed in the xml file, for example, only printing chromosome
1703 residues. When suppress_residues is set to true, then only chromosome
1704 features would would go into the xml file. If suppress_residues is not
1705 set, this function has no effect (since the default is to put all residues
1710 value of allow_residues (a string that corresponds to a feature type)
1714 new value of allow_residues (to set)
1720 sub allow_residues
{
1722 my $allow_residues = shift if defined(@_);
1723 return $self->{'allow_residues'} = $allow_residues if defined($allow_residues);
1724 return $self->{'allow_residues'};
1727 =head2 return_ftype_hash
1733 $obj->return_ftype_hash()
1737 A simple hash where returning it has be factored out of the main
1738 code to allow subclasses to override it.
1742 A hash that indicates what the name of the SO term is and what
1743 the name of the Sequence Ontology is in the cv table.
1747 The string that represents the SO term.
1753 sub return_ftype_hash
{
1756 my %ftype_hash = ( "name" => $ftype,
1757 "cv_id" => {"name" => $cv_name{'sequence'} });
1761 =head2 return_reltypename
1767 $obj->return_reltypename()
1771 Return the appropriate relationship type name depending on the
1772 feature type (typically part_of, but derives_from for polypeptide).
1776 A relationship type name.
1786 sub return_reltypename
{
1791 if ($sftype eq 'protein' || $sftype eq 'polypeptide') {
1792 $reltypename = 'derives_from';
1794 $reltypename = 'part_of';
1797 return $reltypename;
1810 Not implemented--this is a write-only adapter.
1821 my ($self, %argv) = @_;
1823 $self->throw('next_seq is not implemented; this is a write-only adapter.');
1828 =head2 _create_writer
1834 $obj->_create_writer()
1838 Creates XML::Writer object and writes start tag
1842 Nothing, though the writer persists as part of the chadoxml object
1852 sub _create_writer
{
1855 $self->{'writer'} = new XML
::Writer
(OUTPUT
=> $self->_fh,
1860 $self->{'writer'}->xmlDecl("UTF-8");
1861 $self->{'writer'}->comment("created by Peili Zhang, Flybase, Harvard University\n".
1862 "and Scott Cain, GMOD, Cold Spring Harbor Laboratory");
1865 $self->{'writer'}->startTag('chado');
1870 =head2 close_chadoxml
1876 $obj->close_chadoxml()
1880 Writes the closing xml tag
1894 sub close_chadoxml
{
1897 $self->{'writer'}->endTag('chado');
1901 =head2 handle_unreserved_tags
1907 $obj->handle_unreserved_tags()
1911 Converts tag value pairs to xml-ready hashrefs
1915 The array containing the hashrefs
1919 In order: the Seq or SeqFeature object, the key, and the hasharray
1925 sub handle_unreserved_tags
{
1931 my @values = $seq->attributes($key);
1932 for my $value (@values) {
1934 "type_id" => {'name' => $key,
1935 'cv_id' => { 'name' => $cv_name{'feature_property'} }
1939 push(@arr, \
%prophash);
1945 =head2 handle_Alias_tag
1951 $obj->handle_Alias_tag()
1955 Convert Alias values to synonym hash refs
1959 An array of synonym hash tags
1963 The seq or seqFeature object and the synonym hash array
1969 sub handle_Alias_tag
{
1974 my @Aliases = $seq->attributes('Alias');
1975 for my $Alias (@Aliases) {
1977 "type_id" => { 'name' => 'exact',
1978 'cv_id' => { 'name' => 'synonym_type' } },
1980 "synonym_sgml" => $Alias,
1982 push(@arr, {'synonym_id' => \
%synhash,
1983 'pub_id' => {'uniquename' => 'null',
1984 'type_id' => { 'name' => 'null',
1996 =head2 handle_Ontology_tag
2002 $obj->handle_Ontology_tag ()
2006 Convert Ontology_term values to ontology term hash refs
2010 An array of ontology term hash refs
2014 The seq or seqFeature object and the ontology term array
2020 sub handle_Ontology_tag
{
2025 my @terms = $seq->attributes('Ontology_term');
2026 for my $term (@terms) {
2028 if ($term =~ /(\S+):(\S+)/) {
2034 'db_id' => { 'name' => $db },
2040 push(@arr, {cvterm_id
=> $hashref});
2046 =head2 handle_dbxref
2052 $obj->handle_dbxref()
2056 Convert Dbxref values to dbxref hashref
2060 An array of dbxref hashrefs
2064 A seq or seqFeature object and the dbxref array
2076 my @terms = $seq->attributes($tag);
2077 for my $term (@terms) {
2079 if ($term =~ /(\S+):(\S+)/) {
2083 if ($acc =~ /(\S+)\.(\S+)/) {
2089 'db_id' => { 'name' => $db },
2090 'accession' => $acc,
2091 'version' => $version,
2096 $self->throw("I don't know how to handle a dbxref like $term");
2098 push(@arr, {'dbxref_id' => $hashref});
2103 =head2 handle_source
2109 $obj->handle_source()
2126 my $source = $seq->source();
2127 return @arr unless $source;
2131 'db_id' => {'name' => 'GFF_source'},
2132 'accession' => $source,
2136 push(@arr, {'dbxref_id' => $hashref});
2150 Creates the srcfeature hash for use in featureloc hashes
2158 The srcfeature name, the srcfeature type and a reference to the
2171 my %hash = ('uniquename' => $srcf,
2172 'organism_id' => $orgref,
2173 'type_id' => {'name' => $stype,
2175 {'name' => $cv_name{'sequence'} }},