2 # BioPerl module for Bio::SeqIO::chadoxml
4 # Peili Zhang <peili@morgan.harvard.edu>
6 # You may distribute this module under the same terms as perl itself
8 # POD documentation - main docs before the code
12 Bio::SeqIO::chadoxml - chadoxml sequence output stream
16 It is probably best not to use this object directly, but
17 rather go through the SeqIO handler system:
19 $writer = Bio::SeqIO->new(-file => ">chado.xml",
20 -format => 'chadoxml');
22 # assume you already have Sequence or SeqFeature objects
23 $writer->write_seq($seq_obj);
25 #after writing all seqs
26 $writer->close_chadoxml();
32 This object can transform Bio::Seq objects to chadoxml flat
33 file databases (for chadoxml DTD, see
34 http://gmod.cvs.sourceforge.net/gmod/schema/chado/dat/chado.dtd).
36 This is currently a write-only module.
38 $seqio = Bio::SeqIO->new(-file => '>outfile.xml',
40 -suppress_residues => 1,
41 -allow_residues => 'chromosome',
44 # we have a Bio::Seq object $seq which is a gene located on
45 # chromosome arm 'X', to be written out to chadoxml
46 # before converting to chadoxml, $seq object B<must> be transformed
47 # so that all the coordinates in $seq are against the source
48 # feature to be passed into Bio::SeqIO::chadoxml->write_seq()
49 # -- chromosome arm X in the example below.
51 $seqio->write_seq(-seq=>$seq,
53 -species => 'sapiens',
56 -src_feat_type=>'chromosome_arm',
59 -data_source=>'GenBank');
61 The chadoxml output of Bio::SeqIO::chadoxml-E<gt>write_seq() method can be
62 passed to the loader utility in XORT package
63 (http://gmod.cvs.sourceforge.net/gmod/schema/XMLTools/XORT/)
64 to be loaded into chado.
66 This object is currently implemented to work with sequence and
67 annotation data from whole genome projects deposited in GenBank. It
68 may not be able to handle all different types of data from all
71 In converting a Bio::Seq object into chadoxml, a top-level feature is
72 created to represent the object and all sequence features inside the
73 Bio::Seq object are treated as subfeatures of the top-level
74 feature. The Bio::SeqIO::chadoxml object calls
75 Bio::SeqFeature::Tools::Unflattener to unflatten the flat feature list
76 contained in the subject Bio::Seq object, to build gene model
77 containment hierarchy conforming to chado central dogma model: gene
78 --E<gt> mRNA --E<gt> exons and protein.
80 Destination of data in the subject Bio::Seq object $seq is as following:
82 *$seq->display_id: name of the top-level feature;
84 *$seq->accession_number: if defined, uniquename and
85 feature_dbxref of the top-level
86 feature if not defined,
87 $seq->display_id is used as the
88 uniquename of the top-level feature;
90 *$seq->molecule: transformed to SO type, used as the feature
91 type of the top-level feature if -seq_so_type
92 argument is supplied, use the supplied SO type
93 as the feature type of the top-level feature;
95 *$seq->species: organism of the top-level feature;
97 *$seq->seq: residues of the top-level feature;
99 *$seq->is_circular, $seq->division: feature_cvterm;
101 *$seq->keywords, $seq->desc, comments: featureprop;
103 *references: pub and feature_pub;
104 medline/pubmed ids: pub_dbxref;
107 *feature "source" span: featureloc for top-level feature;
109 *feature "source" db_xref: feature_dbxref for top-level feature;
111 *feature "source" other tags: featureprop for top-level feature;
113 *subfeature 'symbol' or 'label' tag: feature uniquename, if
114 none of these is present, the chadoxml object
115 generates feature uniquenames as:
116 <gene>-<feature_type>-<span>
117 (e.g. foo-mRNA--1000..3000);
119 *gene model: feature_relationship built based on the
120 containment hierarchy;
122 *feature span: featureloc;
124 *feature accession numbers: feature_dbxref;
126 *feature tags (except db_xref, symbol and gene): featureprop;
128 Things to watch out for:
130 *chado schema change: this version works with the chado
131 version tagged chado_1_01 in GMOD CVS.
133 *feature uniquenames: especially important if using XORT
134 loader to do incremental load into
135 chado. may need pre-processing of the
136 source data to put the correct
137 uniquenames in place.
139 *pub uniquenames: chadoxml->write_seq() has the FlyBase policy
140 on pub uniquenames hard-coded, it assigns
141 pub uniquenames in the following way: for
142 journals and books, use ISBN number; for
143 published papers, use MEDLINE ID; for
144 everything else, use FlyBase unique
145 identifier FBrf#. need to modify the code to
146 implement your policy. look for the comments
149 *for pubs possibly existing in chado but with no knowledge of
150 its uniquename:put "op" as "match", then need to run the
151 output chadoxml through a special filter that
152 talks to chado database and tries to find the
153 pub by matching with the provided information
154 instead of looking up by the unique key. after
155 matching, the filter also resets the "match"
156 operation to either "force" (default), or
157 "lookup", or "insert", or "update". the
158 "match" operation is for a special FlyBase use
159 case. please modify to work according to your
162 *chado initialization for loading:
164 cv & cvterm: in the output chadoxml, all cv's and
165 cvterm's are lookup only. Therefore,
166 before using XORT loader to load the
167 output into chado, chado must be
168 pre-loaded with all necessary CVs and
169 CVterms, including "SO" , "property
170 type", "relationship type", "pub type",
171 "pubprop type", "pub relationship type",
172 "sequence topology", "GenBank feature
173 qualifier", "GenBank division". A pub by
174 the uniquename 'nullpub' of type 'null
175 pub' needs to be inserted.
181 User feedback is an integral part of the evolution of this and other
182 Bioperl modules. Send your comments and suggestions preferably to one
183 of the Bioperl mailing lists. Your participation is much appreciated.
185 bioperl-l@bioperl.org - General discussion
186 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
190 Please direct usage questions or support issues to the mailing list:
192 I<bioperl-l@bioperl.org>
194 rather than to the module maintainer directly. Many experienced and
195 reponsive experts will be able look at the problem and quickly
196 address it. Please include a thorough description of the problem
197 with code and data examples if at all possible.
199 =head2 Reporting Bugs
201 Report bugs to the Bioperl bug tracking system to help us keep track
202 the bugs and their resolution.
203 Bug reports can be submitted via the web:
205 https://github.com/bioperl/bioperl-live/issues
207 =head1 AUTHOR - Peili Zhang
209 Email peili@morgan.harvard.edu
213 The rest of the documentation details each of the object
214 methods. Internal methods are usually preceded with a _
218 # Let the code begin...
220 package Bio
::SeqIO
::chadoxml
;
230 use Bio
::Seq
::RichSeq
;
231 use Bio
::SeqIO
::FTHelper
;
233 use Bio
::Seq
::SeqFactory
;
234 use Bio
::Factory
::SequenceStreamI
;
235 use Bio
::SeqFeature
::Generic
;
236 use Bio
::Annotation
::Collection
;
237 use Bio
::Annotation
::Comment
;
238 use Bio
::Annotation
::Reference
;
239 use Bio
::Annotation
::DBLink
;
240 use Bio
::SeqFeature
::Tools
::Unflattener
;
243 undef(my %finaldatahash); #data from Bio::Seq object stored in a hash
244 undef(my %datahash); #data from Bio::Seq object stored in a hash
246 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';
249 "cvterm.cv_id" => "cv",
250 "cvterm.dbxref_id" => "dbxref",
251 "dbxref.db_id" => "db",
252 "feature.type_id" => "cvterm",
253 "feature.organism_id" => "organism",
254 "feature.dbxref_id" => "dbxref",
255 "featureprop.type_id" => "cvterm",
256 "feature_pub.pub_id" => "pub",
257 "feature_cvterm.cvterm_id" => "cvterm",
258 "feature_cvterm.pub_id" => "pub",
259 "feature_cvterm.feature_id" => "feature",
260 "feature_dbxref.dbxref_id" => "dbxref",
261 "feature_relationship.object_id" => "feature",
262 "feature_relationship.subject_id" => "feature",
263 "feature_relationship.type_id" => "cvterm",
264 "featureloc.srcfeature_id" => "feature",
265 "pub.type_id" => "cvterm",
266 "pub_dbxref.dbxref_id" => "dbxref",
267 "pub_author.author_id" => "author",
268 "pub_relationship.obj_pub_id" => "pub",
269 "pub_relationship.subj_pub_id" => "pub",
270 "pub_relationship.type_id" => "cvterm",
271 "pubprop.type_id" => "cvterm",
272 "feature_synonym.feature_id" => "feature",
273 "feature_synonym.synonym_id" => "synonym",
274 "feature_synonym.pub_id" => "pub",
275 "synonym.type_id" => "cvterm",
279 'relationship' => 'relationship',
280 'sequence' => 'sequence',
281 'feature_property' => 'feature_property',
284 my %feattype_args2so = (
285 "aberr" => "aberration_junction",
286 # "conflict" => "sequence_difference",
287 # "polyA_signal" => "polyA_signal_sequence",
288 "variation" => "sequence_variant",
289 "mutation1" => "point_mutation", #for single-base mutation
290 "mutation2" => "sequence_variant", #for multi-base mutation
291 "rescue" => "rescue_fragment",
292 # "rfrag" => "restriction_fragment",
293 "protein_bind" => "protein_binding_site",
294 "misc_feature" => "region",
295 # "prim_transcript" => "primary_transcript",
296 "CDS" => "polypeptide",
297 "reg_element" => "regulatory_region",
298 "seq_variant" => "sequence_variant",
299 "mat_peptide" => "mature_peptide",
300 "sig_peptide" => "signal_peptide",
305 use base
qw(Bio::SeqIO);
309 my($self,%args) = @_;
311 $self->SUPER::_initialize
(%args);
312 unless( defined $self->sequence_factory ) {
313 $self->sequence_factory(Bio
::Seq
::SeqFactory
->new
314 (-verbose
=> $self->verbose(),
315 -type
=> 'Bio::Seq::RichSeq'));
317 #optional arguments that can be passed in
318 $self->suppress_residues($args{'-suppress_residues'})
319 if defined $args{'-suppress_residues'};
321 $self->allow_residues($args{'-allow_residues'})
322 if defined $args{'-allow_residues'};
329 Usage : $stream->write_seq(-seq=>$seq, -seq_so_type=>$seqSOtype,
330 -src_feature=>$srcfeature,
331 -src_feat_type=>$srcfeattype,
332 -nounflatten=>0 or 1,
333 -is_analysis=>'true' or 'false',
334 -data_source=>$datasource)
335 Function: writes the $seq object (must be seq) into chadoxml.
336 Returns : 1 for success and 0 for error
337 Args : A Bio::Seq object $seq, optional $seqSOtype, $srcfeature,
338 $srcfeattype, $nounflatten, $is_analysis and $data_source.
340 When $srcfeature (a string, the uniquename of the source feature) is given, the
341 location and strand information of the top-level feature against the source
342 feature will be derived from the sequence feature called 'source' of the $seq
343 object, a featureloc record is generated for the top -level feature on
344 $srcfeature. when $srcfeature is given, $srcfeattype must also be present. All
345 feature coordinates in $seq should be against $srcfeature. $seqSOtype is the
346 optional SO term to use as the type of the top-level feature. For example, a
347 GenBank data file for a Drosophila melanogaster genome scaffold has the molecule
348 type of "DNA", when converting to chadoxml, a $seqSOtype argument of
349 "golden_path_region" can be supplied to save the scaffold as a feature of type
350 "golden_path_region" in chadoxml, instead of "DNA". a feature with primary tag
351 of 'source' must be present in the sequence feature list of $seq, to decribe the
352 whole sequence record.
354 In the current implementation:
362 A top-level feature of type $seq-E<gt>alphabet is generated for the whole GenBank
363 record, features listed are unflattened for DNA records to build gene model
364 feature graph, and for the other types of records all features in $seq are
365 treated as subfeatures of the top-level feature.
371 If a 'gene' feature is present, it B<must> have a /symbol or /label tag to
372 contain the uniquename of the gene. a top-level feature of type 'gene' is
373 generated. the mRNA is written as a subfeature of the top-level gene feature,
374 and the other sequence features listed in $seq are treated as subfeatures of the
382 my $usage = <<EOUSAGE;
383 Bio::SeqIO::chadoxml->write_seq()
384 Usage : \$stream->write_seq(-seq=>\$seq,
385 -seq_so_type=>\$SOtype,
386 -src_feature=>\$srcfeature,
387 -src_feat_type=>\$srcfeattype,
388 -nounflatten=>0 or 1,
389 -is_analysis=>'true' or 'false',
390 -data_source=>\$datasource)
391 Args : \$seq : a Bio::Seq object
392 \$SOtype : the SO term to use as the feature type of
393 the \$seq record, optional
394 \$srcfeature : unique name of the source feature, a string
395 containing at least one alphabetical letter
397 \$srcfeattype : feature type of \$srcfeature. one of SO terms.
399 when \$srcfeature is given, \$srcfeattype becomes mandatory,
400 \$datasource : source of the sequence annotation data,
401 e.g. 'GenBank' or 'GFF'.
404 my ($self,@args) = @_;
406 my ($seq, $seq_so_type, $srcfeature, $srcfeattype, $nounflatten, $isanalysis, $datasource, $genus, $species) =
407 $self->_rearrange([qw(SEQ
418 #print "$seq_so_type, $srcfeature, $srcfeattype\n";
420 if( !defined $seq ) {
421 $self->throw("Attempting to write with no seq!");
424 if( ! ref $seq || ! $seq->isa('Bio::Seq::RichSeqI') ) {
425 ## FIXME $self->warn(" $seq is not a RichSeqI compliant module. Attempting to dump, but may fail!");
428 # try to get the srcfeature from the seqFeature object
429 # for this to work, the user has to pass in the srcfeature type
431 if ($seq->can('seq_id')) {
432 $srcfeature=$seq->seq_id if ($seq->seq_id ne $seq->display_name);
436 #$srcfeature, when provided, should contain at least one alphabetical letter
437 if (defined $srcfeature)
439 if ($srcfeature =~ /[a-zA-Z]/)
443 $self->throw( $usage );
446 #check for mandatory $srcfeattype
447 if (! defined $srcfeattype)
449 $self->throw( $usage );
450 #$srcfeattype must be a string of non-whitespace characters
452 if ($srcfeattype =~ /\S+/) {
455 $self->throw( $usage );
460 # variables local to write_seq()
463 undef(my @top_featureprops);
464 undef(my @featuresyns);
465 undef(my @top_featurecvterms);
466 my $name = $seq->display_id if $seq->can('display_id');
467 $name = $seq->display_name if $seq->can('display_name');
468 undef(my @feature_cvterms);
475 undef(my @references);
476 undef(my @feature_pubs);
478 my $location = undef;
483 my $volumeissue = undef;
487 # my $miniref= undef;
488 my $uniquename = undef;
494 my $subfeatcnt = undef;
495 undef(my @top_featrels);
496 undef (my %srcfhash);
498 local($^W
) = 0; # supressing warnings about uninitialized fields.
500 if (!$name && $seq->can('attributes') ) {
501 ($name) = $seq->attributes('Alias');
504 if ($seq->can('accession_number') && defined $seq->accession_number && $seq->accession_number ne 'unknown') {
505 $uniquename = $seq->accession_number;
506 } elsif ($seq->can('accession') && defined $seq->accession && $seq->accession ne 'unknown') {
507 $uniquename = $seq->accession;
508 } elsif ($seq->can('attributes')) {
509 ($uniquename) = $seq->attributes('load_id');
513 my $len = $seq->length();
519 if (!$seq->can('molecule') || ! defined ($gb_type = $seq->molecule()) ) {
520 $gb_type = $seq->can('alphabet') ?
$seq->alphabet : 'DNA';
522 $gb_type = 'DNA' if $ftype eq 'dna';
523 $gb_type = 'RNA' if $ftype eq 'rna';
525 if(length $seq_so_type > 0) {
526 if (defined $seq_so_type) {
527 $ftype = $seq_so_type;
530 $ftype = ($seq->type =~ /(.*):/)
542 my %ftype_hash = $self->return_ftype_hash($ftype);
545 %organism = ("genus"=>$genus, "species" => $species);
548 my $spec = $seq->species();
549 if (!defined $spec) {
550 $self->throw("$seq does not know what organism it is from, which is required by chado. cannot proceed!\n");
552 %organism = ("genus"=>$spec->genus(), "species" => $spec->species());
557 if (!$self->suppress_residues ||
558 ($self->suppress_residues && $self->allow_residues eq $ftype)) {
559 $residues = $seq->seq->isa('Bio::PrimarySeq')
567 #set is_analysis flag for gene model features
569 if ($ftype eq 'gene' || $ftype eq 'mRNA' || $ftype eq 'exon' || $ftype eq 'protein' || $ftype eq 'polypeptide') {
570 $isanal = $isanalysis;
571 $isanal = 'false' if !defined $isanal;
576 "uniquename" => $uniquename,
578 "residues" => $residues,
579 "type_id" => \
%ftype_hash,
580 "organism_id" => \
%organism,
581 "is_analysis" => $isanal || 'false',
584 if (defined $srcfeature) {
585 %srcfhash = $self->_srcf_hash($srcfeature,
590 if ($seq->can('phase')) {
591 $phase = $seq->phase;
594 if ($seq->can('strand')) {
595 $strand = $seq->strand;
598 "srcfeature_id" => \
%srcfhash,
599 "fmin" => $seq->start - 1,
605 $datahash{'featureloc'} = \
%fl;
610 #if $srcfeature is not given, use the Bio::Seq object itself as the srcfeature for featureloc's
611 if (!defined $srcfeature) {
612 $srcfeature = $uniquename;
613 $srcfeattype = $ftype;
616 #default data source is 'GenBank'
617 if (!defined $datasource) {
618 $datasource = 'GenBank';
621 if ($datasource =~ /GenBank/i) {
622 #sequence topology as feature_cvterm
623 if ($seq->can('is_circular') && $seq->is_circular) {
625 "cvterm_id" => {'name' => 'circular',
627 'name' => 'sequence topology',
630 "pub_id" => {'uniquename' => 'nullpub',
632 'name' => 'null pub',
641 "cvterm_id" => { 'name' => 'linear',
643 'name' => 'sequence topology',
646 "pub_id" => {'uniquename' => 'nullpub',
648 'name' => 'null pub',
656 push(@feature_cvterms, \
%sthash);
658 #division as feature_cvterm
659 if ($seq->can('division') && defined $seq->division()) {
660 $div = $seq->division();
662 "cvterm_id" => {'name' => $div,
664 'name' => 'GenBank division'}},
665 "pub_id" => {'uniquename' => 'nullpub',
667 'name' => 'null pub',
669 'name'=> 'pub type'},
672 push(@feature_cvterms, \
%dvhash);
675 $datahash{'feature_cvterm'} = \
@feature_cvterms;
676 } # closes if GenBank
680 if ($seq->can('desc') && defined $seq->desc()) {
681 $temp = $seq->desc();
684 "type_id" => {'name' => 'description',
687 $cv_name{'feature_property'}
693 push(@top_featureprops, \
%prophash);
697 if ($seq->can('keywords')) {
698 $temp = $seq->keywords();
700 if (defined $temp && $temp ne '.' && $temp ne '') {
702 "type_id" => {'name' => 'keywords',
705 $cv_name{'feature_property'}
711 push(@top_featureprops, \
%prophash);
716 if ($seq->can('annotation')) {
717 $ann = $seq->annotation();
718 foreach my $comment ($ann->get_Annotations('comment')) {
719 $temp = $comment->as_text();
720 #print "fcomment: $temp\n";
722 "type_id" => {'name' => 'comment',
725 $cv_name{'feature_property'}
731 push(@top_featureprops, \
%prophash);
735 my @top_dbxrefs = ();
736 #feature object from Bio::DB::SeqFeature::Store
737 if ($seq->can('attributes')) {
738 my %attributes = $seq->attributes;
739 for my $key (keys %attributes) {
740 next if ($key eq 'parent_id');
741 next if ($key eq 'load_id');
743 if ($key eq 'Alias') {
744 @featuresyns = $self->handle_Alias_tag($seq,@featuresyns);
747 ###FIXME deal with Dbxref, Ontology_term,source,
748 elsif ($key eq 'Ontology_term') {
749 @top_featurecvterms = $self->handle_Ontology_tag($seq,@top_featurecvterms);
752 elsif ($key eq 'dbxref' or $key eq 'Dbxref') {
753 @top_dbxrefs = $self->handle_dbxref($seq, $key, @top_dbxrefs);
756 elsif ($key =~ /^[a-z]/) {
758 = $self->handle_unreserved_tags($seq,$key,@top_featureprops);
762 $datahash{'feature_synonym'} = \
@featuresyns;
764 if ($seq->can('source')) {
765 @top_dbxrefs = $self->handle_source($seq,@top_dbxrefs);
768 #accession and version as feature_dbxref
769 if ($seq->can('accession_number') && defined $seq->accession_number && $seq->accession_number ne 'unknown') {
770 my $db = $self->_guess_acc_db($seq, $seq->accession_number);
772 "db_id" => {'name' => $db},
773 "accession" => $seq->accession_number,
774 "version" => $seq->seq_version,
776 my %fdbx = ('dbxref_id' => \
%acchash);
777 push(@top_dbxrefs, \
%fdbx);
780 if( $seq->isa('Bio::Seq::RichSeqI') && defined $seq->get_secondary_accessions() ) {
781 my @secacc = $seq->get_secondary_accessions();
783 foreach $acc (@secacc) {
785 "db_id" => {'name' => 'GB'},
788 my %fdbx = ('dbxref_id' => \
%acchash);
789 push(@top_dbxrefs, \
%fdbx);
794 if( $seq->isa('Bio::Seq::RichSeqI') && defined ($seq->pid)) {
796 #print "reftype: ", ref($id), "\n";
798 #if (ref($id) eq 'HASH') {
800 "db_id" => {'name' => 'GI'},
803 my %fdbx = ('dbxref_id' => \
%acchash);
804 push (@top_dbxrefs, \
%fdbx);
807 #REFERENCES as feature_pub
810 @references = $ann->get_Annotations('reference');
811 foreach $ref (@references) {
813 $refhash = $ref->hash_tree();
814 $location = $ref->location || $refhash->{'location'};
815 #print "location: $location\n";
817 #get FBrf#, special for FlyBase SEAN loading
818 if (index($location, ' ==') >= 0) {
820 #print "match: $MATCH\n";
821 #print "prematch: $PREMATCH\n";
822 #print "postmatch: $POSTMATCH\n";
824 $location = $POSTMATCH;
825 $location =~ s/^\s//;
828 #print "location: $location\n";
829 #unpublished reference
830 if ($location =~ /Unpublished/) {
831 $pubtype = 'unpublished';
833 "title" => $ref->title || $refhash->{'title'},
834 #"miniref" => substr($location, 0, 255),
835 #"uniquename" => $fbrf,
836 "type_id" => {'name' => $pubtype, 'cv_id' => {'name' =>'pub type'}}
840 elsif ($location =~ /Submitted/) {
841 $pubtype = 'submitted';
844 "title" => $ref->title || $refhash->{'title'},
845 #"miniref" => substr($location, 0, 255),
846 #"uniquename" => $fbrf,
847 "type_id" => {'name' => $pubtype, 'cv_id' => {'name' =>'pub type'}}
851 $pyear = $self->_getSubmitYear($location);
852 if (defined $pyear) {
853 $pubhash{'pyear'} = $pyear;
857 #published journal paper
858 elsif ($location =~ /\D+\s\d+\s\((\d+|\d+-\d+)\),\s(\d+-\d+|\d+--\d+)\s\(\d\d\d\d\)$/) {
861 #parse location to get journal, volume, issue, pages & year
862 $location =~ /\(\d\d\d\d\)$/;
865 my $stuff = $PREMATCH;
866 $year =~ s/\(//; #remove the leading parenthesis
867 $year =~ s/\)//; #remove the trailing parenthesis
869 $stuff =~ /,\s(\d+-\d+|\d+--\d+)\s$/;
873 $pages =~ s/^, //; #remove the leading comma and space
874 $pages =~ s/ $//; #remove the last space
876 $stuff =~ /\s\d+\s\((\d+|\d+-\d+)\)$/;
878 $volumeissue = $MATCH;
879 $journal = $PREMATCH;
880 $volumeissue =~ s/^ //; #remove the leading space
881 $volumeissue =~ /\((\d+|\d+-\d+)\)$/;
884 $issue =~ s/^\(//; #remove the leading parentheses
885 $issue =~ s/\)$//; #remove the last parentheses
886 $volume =~ s/^\s//; #remove the leading space
887 $volume =~ s/\s$//; #remove the last space
890 "title" => $ref->title || $refhash->{'title'},
895 #"miniref" => substr($location, 0, 255),
897 #"uniquename" => $fbrf,
898 "type_id" => {'name' => $pubtype, 'cv_id' => {'name' =>'pub type'}},
899 "pub_relationship" => {
901 'uniquename' => $journal,
903 #'miniref' => substr($journal, 0, 255),
904 'type_id' =>{'name' => 'journal',
906 {'name' => 'pub type'
909 #'pubprop' =>{'value'=> $journal,
910 # 'type_id'=>{'name' => 'abbreviation', 'cv_id' => {'name' => 'pubprop type'}},
914 'name' => 'published_in',
916 'name' => 'pub relationship type'},
926 "title" => $ref->title || $refhash->{'title'},
930 'cv_id' => {'name' =>'pub type'}
936 my $autref = $self->_getRefAuthors($ref);
937 if (defined $autref) {
938 $pubhash{'pub_author'} = $autref;
940 # if no author and is type 'submitted' and has submitter address, use the first 100 characters of submitter address as the author lastname.
942 if ($pubtype eq 'submitted') {
943 my $autref = $self->_getSubmitAddr($ref);
944 if (defined $autref) {
945 $pubhash{'pub_author'} = $autref;
950 #$ref->comment as pubprop
951 #print "ref comment: ", $ref->comment, "\n";
952 #print "ref comment: ", $refhash->{'comment'}, "\n";
953 if (defined $ref->comment || defined $refhash->{'comment'}) {
954 my $comnt = $ref->comment || $refhash->{'comment'};
955 #print "remark: ", $comnt, "\n";
956 $pubhash{'pubprop'} = {
957 "type_id" => {'name' => 'comment', 'cv_id' => {'name' => 'pubprop type'}},
963 undef(my @pub_dbxrefs);
965 push(@pub_dbxrefs, {dbxref_id
=> {accession
=> $fbrf, db_id
=> {'name' => 'FlyBase'}}});
967 if (defined ($temp = $ref->medline)) {
968 push(@pub_dbxrefs, {dbxref_id
=> {accession
=> $temp, db_id
=> {'name' => 'MEDLINE'}}});
969 #use medline # as the pub's uniquename
970 $pubhash{'uniquename'} = $temp;
972 if (defined ($temp = $ref->pubmed)) {
973 push(@pub_dbxrefs, {dbxref_id
=> {accession
=> $temp, db_id
=> {'name' => 'PUBMED'}}});
975 $pubhash{'pub_dbxref'} = \
@pub_dbxrefs;
977 #if the pub uniquename is not defined or blank, put its FBrf# as its uniquename
978 #this is unique to FlyBase
979 #USERS OF THIS MODULE: PLEASE MODIFY HERE TO IMPLEMENT YOUR POLICY
980 # ON PUB UNIQUENAME!!!
981 if (!defined $pubhash{'uniquename'} || $pubhash{'uniquename'} eq '') {
983 $pubhash{'uniquename'} = $fbrf;
986 # $pubhash{'uniquename'} = $self->_CreatePubUname($ref);
990 #add to collection of references
991 #if the pub covers the entire sequence of the top-level feature, add it to feature_pubs
992 if (($ref->start == 1 && $ref->end == $len) || (!defined $ref->start && !defined $ref->end)) {
993 push(@feature_pubs, {"pub_id" => \
%pubhash});
995 #the pub is about a sub-sequence of the top-level feature
996 #create a feature for the sub-sequence and add pub as its feature_pub
997 #featureloc of this sub-sequence is against the top-level feature, in interbase coordinates.
1000 'uniquename' => $uniquename . ':' . $ref->start . "\.\." . $ref->end,
1001 'organism_id' =>\
%organism,
1002 'type_id' =>{'name' =>'region', 'cv_id' => {'name' => $cv_name{'sequence'} }},
1005 'uniquename' => $uniquename,
1006 'organism_id' =>\
%organism,
1009 'srcfeature_id' => \
%parfsrcf,
1010 'fmin' => $ref->start - 1,
1011 'fmax' => $ref->end,
1013 $parf{'featureloc'} = \
%parfloc;
1014 $parf{'feature_pub'} = {'pub_id' => \
%pubhash};
1016 'subject_id' => \
%parf,
1017 'type_id' => { 'name' => 'partof', 'cv_id' => { 'name' => $cv_name{'relationship'}}},
1019 push(@top_featrels, \
%ffr);
1022 $datahash{'feature_pub'} = \
@feature_pubs;
1025 ##construct srcfeature hash for use in featureloc
1026 if (defined $srcfeature) {
1027 %srcfhash = $self->_srcf_hash($srcfeature,
1031 # "object_id" => \%srcfhash,
1032 # "type_id" => { 'name' => 'partof', 'cv_id' => { 'name' => 'relationship type'}},
1035 # push (@top_featrels, \%fr);
1038 #unflatten the seq features in $seq if $seq is a gene or a DNA sequence
1039 if (($gb_type eq 'gene' || $gb_type eq 'DNA') &&
1041 my $u = Bio
::SeqFeature
::Tools
::Unflattener
->new;
1042 $u->unflatten_seq(-seq
=>$seq, -use_magic
=>1);
1045 my @top_sfs = $seq->get_SeqFeatures;
1046 #print $#top_sfs, "\n";
1050 if ($datasource =~ /GenBank/i) {
1051 $tag_cv = 'GenBank feature qualifier';
1052 } elsif ($datasource =~ /GFF/i) {
1053 $tag_cv = 'feature_property';
1055 $tag_cv = $cv_name{'feature_property'};
1059 foreach $feat (@top_sfs) {
1060 #$feat = $top_sfs[$si];
1062 my $prim_tag = $feat->primary_tag;
1063 #print $prim_tag, "\n";
1065 # get all qualifiers of the 'source' feature, load these as top_featureprops of the top level feature
1066 if ($prim_tag eq 'source') {
1067 foreach $tag ($feat->all_tags()) {
1069 if ($tag eq 'db_xref'
1071 or $tag eq 'dbxref') {
1072 my @t1 = $feat->each_tag_value($tag);
1073 foreach $temp (@t1) {
1074 $temp =~ /([^:]*?):(.*)/;
1077 #PRE/POST very inefficent
1078 #my $db = $PREMATCH;
1079 #my $xref = $POSTMATCH;
1081 "db_id" => {'name' => $db},
1082 "accession" => $xref,
1084 my %fdbx = ('dbxref_id' => \
%acchash);
1085 push (@top_dbxrefs, \
%fdbx);
1088 } elsif ($tag eq 'Ontology_term') {
1089 my @t1 = $feat->each_tag_value($tag);
1090 foreach $temp (@t1) {
1093 #other tags as featureprop
1094 } elsif ($tag ne 'gene') {
1095 my %prophash = undef;
1097 "type_id" => {'name' => $tag, 'cv_id' => {'name' => $tag_cv}},
1098 "value" => join(' ',$feat->each_tag_value($tag)),
1100 push(@top_featureprops, \
%prophash);
1104 if ($feat->can('source')) {
1105 my $source = $feat->source();
1106 @top_dbxrefs = $self->handle_source($feat, @top_dbxrefs);
1109 #featureloc for the top-level feature
1116 $fmin = $feat->start - 1;
1118 $strand = $feat->strand;
1120 if ($feat->can('phase')) {
1121 $phase = $feat->phase;
1125 "srcfeature_id" => \
%srcfhash,
1128 "strand" => $strand,
1132 $datahash{'featureloc'} = \
%fl;
1134 #delete 'source' feature from @top_sfs
1135 splice(@top_sfs, $si, 1);
1138 #close loop over top_sfs
1141 #the top-level features other than 'source'
1142 foreach $feat (@top_sfs) {
1143 #print $feat->primary_tag, "\n";
1145 my $r = $self->_subfeat2featrelhash($name, $ftype, $feat, \
%srcfhash, $tag_cv, $isanalysis);
1147 if (!($ftype eq 'mRNA' && $feat->primary_tag eq 'gene')) {
1149 push(@top_featrels, \
%fr);
1151 %finaldatahash = %$r;
1156 $datahash{'feature_dbxref'} = \
@top_dbxrefs;
1159 if (@top_featureprops) {
1160 $datahash{'featureprop'} = \
@top_featureprops;
1163 if (@top_featrels) {
1164 $datahash{'feature_relationship'} = \
@top_featrels;
1167 if (@top_featurecvterms) {
1168 $datahash{'feature_cvterm'} = \
@top_featurecvterms;
1171 if ($ftype eq 'mRNA' && %finaldatahash) {
1172 $finaldatahash{'feature_relationship'} = {
1173 'subject_id' => \
%datahash,
1174 'type_id' => { 'name' => 'partof', 'cv_id' => { 'name' => $cv_name{'relationship'} }},
1177 %finaldatahash = %datahash;
1180 my $mainTag = 'feature';
1181 $self->_hash2xml(undef, $mainTag, \
%finaldatahash);
1188 my $isMatch = undef;
1201 my $root = shift if (@_);
1202 #print "ult: $ult\n";
1203 if (!defined $self->{'writer'}) {
1205 $self->_create_writer();
1211 #if pub record of type 'journal', form the 'ref' attribute for special pub lookup
1212 #requires that the journal name itself is also stored as a pubprop record for the journal with value equal
1213 #to the journal name and type of 'abbreviation'.
1214 if ($ult eq 'pub' && $mh{'type_id'}->{'name'} eq 'journal') {
1215 $self->{'writer'}->startTag($ult, 'ref' => $mh{'title'} . ':journal:abbreviation');
1218 #special pub match if pub uniquename not known
1219 elsif ($ult eq 'pub' && !defined $mh{'uniquename'}) {
1220 $self->{'writer'}->startTag($ult, 'op' => 'match');
1221 #set the match flag, all the sub tags should also have "op"="match"
1225 #if cvterm or cv, lookup only
1226 elsif (($ult eq 'cvterm') || ($ult eq 'cv')) {
1227 $self->{'writer'}->startTag($ult, 'op' => 'lookup');
1230 #if nested tables of match table, match too
1232 $self->{'writer'}->startTag($ult, 'op' => 'match');
1236 $self->{'writer'}->startTag($ult);
1239 #first loop to produce xml for all the table columns
1240 foreach $key (keys %mh)
1242 #print "key: $key\n";
1245 if (index($chadotables, $xx) < 0 && index($chadotables, $yy) < 0)
1248 $self->{'writer'}->startTag($key, 'op' => 'match');
1250 $self->{'writer'}->startTag($key);
1253 my $x = $ult . '.' . $key;
1254 #the column is a foreign key
1255 if (defined $fkey{$x})
1259 $self->_hash2xml($isMatch, $nt, $sh, 0);
1262 #print "$key: $mh{$key}\n";
1263 $self->{'writer'}->characters($mh{$key});
1265 $self->{'writer'}->endTag($key);
1269 #second loop to produce xml for all the nested tables
1270 foreach $key (keys %mh)
1272 #print "key: $key\n";
1276 if (index($chadotables, $xx) > 0 || index($chadotables, $yy) > 0)
1278 #$writer->startTag($key);
1280 #print "$key: ", ref($ntref), "\n";
1281 if (ref($ntref) =~ 'HASH') {
1282 $self->_hash2xml($isMatch, $key, $ntref, 0);
1283 } elsif (ref($ntref) =~ 'ARRAY') {
1284 #print "array dim: ", $#$ntref, "\n";
1285 foreach $ref (@
$ntref) {
1287 $self->_hash2xml($isMatch, $key, $ref, 0);
1290 #$writer->endTag($key);
1295 $self->{'writer'}->endTag($ult);
1298 # $self->{'writer'}->endTag('chado');
1306 #print "acc: $acc\n";
1308 if ($acc =~ /^NM_\d{6}/ || $acc =~ /^NP_\d{6}/ || $acc =~ /^NT_\d{6}/ || $acc =~ /^NC_\d{6}/) {
1310 } elsif ($acc =~ /^XM_\d{6}/ || $acc =~ /^XP_\d{6}/ || $acc =~ /^XR_\d{6}/) {
1312 } elsif ($acc =~ /^[a-zA-Z]{1,2}\d{5,6}/) {
1314 } elsif ($seq->molecule() eq 'protein' && $acc =~ /^[a-zA-z]\d{5}/) {
1316 } elsif ($seq->molecule() eq 'protein' && $acc =~ /^\d{6,7}[a-zA-Z]/) {
1318 } elsif ($acc =~ /\d+/ && $acc !~ /[a-zA-Z]/) {
1320 } elsif ($acc =~ /^CG\d+/ || $acc =~ /^FB[a-z][a-z]\d+/) {
1327 sub _subfeat2featrelhash
{
1329 my $genename = shift;
1330 my $seqtype = shift;
1333 my %srcf = %$r; #srcfeature hash for featureloc.srcfeature_id
1335 my $isanalysis = shift;
1337 my $prim_tag = $feat->primary_tag;
1339 my $sfunique = undef; #subfeature uniquename
1340 my $sfname = undef; #subfeature name
1341 my $sftype = undef; #subfeature type
1343 if ($feat->has_tag('symbol')) {
1344 ($sfunique) = $feat->each_tag_value("symbol");
1345 } elsif ($feat->has_tag('label')) {
1346 ($sfunique) = $feat->each_tag_value("label");
1348 #$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.");
1349 #generate feature unique name as <genename>-<feature-type>-<span>
1350 $sfunique = $self->_genFeatUniqueName($genename, $feat);
1353 if ($feat->has_tag('Name')) {
1354 ($sfname) = $feat->each_tag_value("Name");
1357 #feature type translation
1358 if (defined $feattype_args2so{$prim_tag}) {
1359 $sftype = $feattype_args2so{$prim_tag};
1361 $sftype = $prim_tag;
1364 if ($prim_tag eq 'mutation') {
1365 if ($feat->start == $feat->end) {
1366 $sftype = $feattype_args2so{'mutation1'};
1368 $sftype = $feattype_args2so{'mutation2'};
1372 #set is_analysis flag for gene model features
1374 if ($sftype eq 'gene' || $sftype eq 'mRNA' || $sftype eq 'exon' || $sftype eq 'protein' || $sftype eq 'polypeptide') {
1375 $isanal = $isanalysis;
1380 "uniquename" => $sfunique,
1381 "organism_id" => \
%organism,
1382 "type_id" => { 'name' => $sftype, 'cv_id' => { 'name' => $cv_name{'sequence'} }},
1383 "is_analysis" => $isanal || 'false',
1386 #make a copy of %sfhash for passing to this method when recursively called
1388 # "name" => $sfname,
1389 # "uniquename" => $sfunique,
1390 # "organism_id" => \%organism,
1391 # "type_id" => { 'name' => $sftype, 'cv_id' => { 'name' => 'SO'}},
1394 #featureloc for subfeatures
1397 undef(my $is_sfmin_partial);
1398 undef(my $is_sfmax_partial);
1399 undef(my $sfstrand);
1401 $sfmin = $feat->start - 1;
1402 $sfmax = $feat->end;
1403 $sfstrand = $feat->strand();
1405 if ($feat->can('phase')) {
1406 $sfphase = $feat->phase;
1409 #if the gene feature in an mRNA record, cannot use its coordinates, omit featureloc
1410 if ($seqtype eq 'mRNA' && $sftype eq 'gene') {
1412 if ($feat->location->isa('Bio::Location::FuzzyLocationI')) {
1413 if ($feat->location->start_pos_type() ne 'EXACT') {
1414 $is_sfmin_partial = 'true';
1416 if ($feat->location->end_pos_type() ne 'EXACT') {
1417 $is_sfmax_partial = 'true';
1422 "srcfeature_id" => \
%srcf,
1424 "is_fmin_partial" => $is_sfmin_partial || 'false',
1426 "is_fmax_partial" => $is_sfmax_partial || 'false',
1427 "strand" => $sfstrand,
1428 "phase" => $sfphase,
1431 $sfhash{'featureloc'} = \
%sfl;
1436 undef(my @sfdbxrefs); #subfeature dbxrefs
1437 undef(my @sub_featureprops); #subfeature props
1438 undef(my @sub_featuresyns); #subfeature synonyms
1439 undef(my @sub_featurecvterms); #subfeature cvterms
1440 foreach my $tag ($feat->all_tags()) {
1441 #feature_dbxref for features
1442 if ($tag eq 'db_xref' or $tag eq 'dbxref' or $tag eq 'Dbxref') {
1443 my @t1 = $feat->each_tag_value($tag);
1444 #print "# of dbxref: @t1\n";
1445 for my $temp (@t1) {
1448 my $xref = $POSTMATCH;
1449 #print "db: $db; xref: $xref\n";
1451 "db_id" => {'name' => $db},
1452 "accession" => $xref,
1454 my %sfdbx = ('dbxref_id' => \
%acchash);
1455 push (@sfdbxrefs, \
%sfdbx);
1458 } elsif ($tag eq 'Alias') {
1459 @sub_featuresyns = $self->handle_Alias_tag($feat, @sub_featuresyns);
1460 } elsif ($tag eq 'Ontology_term') {
1461 @sub_featurecvterms = $self->handle_Ontology_tag($feat, @sub_featurecvterms);
1462 #featureprop for features, excluding GFF Name & Parent tags
1463 } elsif ($tag ne 'gene' && $tag ne 'symbol' && $tag ne 'Name' && $tag ne 'Parent') {
1464 next if ($tag eq 'parent_id');
1465 next if ($tag eq 'load_id');
1466 foreach my $val ($feat->each_tag_value($tag)) {
1467 my %prophash = undef;
1469 "type_id" => {'name' => $tag, 'cv_id' => {'name' => $tag_cv}},
1472 push(@sub_featureprops, \
%prophash);
1477 if ($feat->can('source')) {
1478 @sfdbxrefs = $self->handle_source($feat,@sfdbxrefs);
1481 if (@sub_featureprops) {
1482 $sfhash{'featureprop'} = \
@sub_featureprops;
1485 $sfhash{'feature_dbxref'} = \
@sfdbxrefs;
1487 if (@sub_featuresyns) {
1488 $sfhash{'feature_synonym'} = \
@sub_featuresyns;
1490 if (@sub_featurecvterms) {
1491 $sfhash{'feature_cvterm'} = \
@sub_featurecvterms;
1494 undef(my @ssfeatrel);
1495 if ($feat->has_tag('locus_tag')) {
1496 ($genename)= $feat->each_tag_value('locus_tag');
1497 } elsif ($feat->has_tag('gene')) {
1498 ($genename)= $feat->each_tag_value('gene');
1501 foreach my $sf ($feat->get_SeqFeatures()) {
1502 #print $sf->primary_tag, "\n";
1503 my $rref = $self->_subfeat2featrelhash($genename, $sftype, $sf, \
%srcf, $tag_cv, $isanalysis);
1504 if (defined $rref) {
1505 push(@ssfeatrel, $rref);
1510 $sfhash{'feature_relationship'} = \
@ssfeatrel;
1513 #subj-obj relationship type
1514 undef(my $reltypename);
1515 $reltypename = return_reltypename
($sftype);
1518 "subject_id" => \
%sfhash,
1519 "type_id" => { 'name' => $reltypename,
1520 'cv_id' => { 'name' => $cv_name{'relationship'} }},
1523 if ($seqtype eq 'mRNA' && $sftype eq 'gene') {
1531 #generate uniquename for feature as: <genename>-<feature-type>-<span> (foo-mRNA-10..1000)
1532 sub _genFeatUniqueName
{
1534 my $genename = shift;
1536 undef(my $uniquename);
1537 my $ftype = $feat->primary_tag;
1538 my $start = $feat->start;
1539 my $end = $feat->end;
1541 if ($feat->has_tag('locus_tag')) {
1542 ($genename) = $feat->each_tag_value("locus_tag");
1543 } elsif ($feat->has_tag('gene')) {
1544 ($genename) = $feat->each_tag_value("gene");
1547 $uniquename = $genename . '-' . $ftype . '-' . $start . "\.\." . $end;
1552 #create uniquename for pubs with no medline id and no FBrf#
1553 #use "<authors>, <year>, <type>" as the uniquename (same as miniref)
1554 #<authors> is <sole-author-surname> if one author,
1555 # or <first-author-surname> and <second-author-surname> if two,
1556 # or <first-author-surname> et al. if more
1557 #sub _CreatePubUname {
1560 # undef(my $pubuname);
1565 #get authors of a reference
1566 #returns ref to the array of author hashes
1567 sub _getRefAuthors
{
1571 my $temp = $ref->authors;
1577 if (index($temp, ' and ') > 0) {
1579 my $lastauthor = $POSTMATCH;
1580 @authors = split(/\, /, $PREMATCH);
1581 push (@authors, $lastauthor);
1583 @authors = split(/\, /, $temp);
1588 foreach $a (@authors) {
1590 #parse the author lastname and givennames
1593 if (index($a, ',') > 0) { #genbank format, last,f.m.
1594 ($last, $given) = split(/\,/, $a);
1595 } elsif (index($a, ' ') > 0) { #embl format, last f.m.
1596 ($last, $given) = split(/ /, $a);
1600 'givennames' => $given,
1602 push(@aut, {author_id
=> \
%au, arank
=> $i});
1608 #no authors, Bio::SeqIO::genbank doesn't pick up 'CONSRTM' line.
1615 #extract submission year from the citation of the submitted reference
1616 #genbank format for the submitted citation: JOURNAL Submitted (DD-MON-YYYY) submitter address
1617 sub _getSubmitYear
{
1619 my $citation = shift;
1621 if ($citation !~ /Submitted/) {
1622 $self->warn("not citation for a submitted reference. cannot extract submission year.");
1625 $citation =~ /Submitted \(\d\d-[a-zA-Z]{3}-\d{4}\)/;
1634 sub _getSubmitAddr
{
1639 my $citation = $ref->location;
1640 if ($citation !~ /Submitted/) {
1641 $self->warn("not citation for a submitted reference. cannot extract submission year.");
1644 $citation =~ /Submitted \(\d\d-[a-zA-Z]{3}-\d{4}\)/;
1649 'author_id' => {'surname' => substr($a, 0, 100)},
1658 =head2 suppress_residues
1660 Title : suppress_residues
1661 Usage : $obj->suppress_residues() #get existing value
1662 $obj->suppress_residues($newval) #set new value
1663 Function : Keep track of the flag to suppress printing of residues in the
1664 chadoxml file. The default it to allow all residues to go into the
1666 Returns : value of suppress_residues (a scalar)
1667 Args : new value of suppress_residues (to set)
1671 sub suppress_residues
{
1673 my $suppress_residues = shift if @_;
1674 return $self->{'suppress_residues'} = $suppress_residues if defined($suppress_residues);
1675 return $self->{'suppress_residues'};
1678 =head2 allow_residues
1680 Title : allow_residues
1681 Usage : $obj->allow_residues() #get existing value
1682 $obj->allow_residues($feature_type) #set new value
1683 Function : Track the allow_residues type. This can be used in conjunction
1684 with the suppress_residues flag to only allow residues from a
1685 specific feature type to be printed in the xml file, for example,
1686 only printing chromosome residues. When suppress_residues is set to
1687 true, then only chromosome features would would go into the xml
1688 file. If suppress_residues is not set, this function has no effect
1689 (since the default is to put all residues in the xml file).
1690 Returns : value of allow_residues (string that corresponds to a feature type)
1691 Args : new value of allow_residues (to set)
1696 sub allow_residues
{
1698 my $allow_residues = shift if @_;
1699 return $self->{'allow_residues'} = $allow_residues if defined($allow_residues);
1700 return $self->{'allow_residues'};
1703 =head2 return_ftype_hash
1705 Title : return_ftype_hash
1706 Usage : $obj->return_ftype_hash()
1707 Function : A simple hash where returning it has be factored out of the main
1708 code to allow subclasses to override it.
1709 Returns : A hash that indicates what the name of the SO term is and what
1710 the name of the Sequence Ontology is in the cv table.
1711 Args : The string that represents the SO term.
1716 sub return_ftype_hash
{
1719 my %ftype_hash = ( "name" => $ftype,
1720 "cv_id" => {"name" => $cv_name{'sequence'} });
1724 =head2 return_reltypename
1726 Title : return_reltypename
1727 Usage : $obj->return_reltypename
1728 Function : Return the appropriate relationship type name depending on the
1729 feature type (typically part_of, but derives_from for polypeptide).
1730 Returns : A relationship type name.
1731 Args : A SO type name.
1736 sub return_reltypename
{
1741 if ($sftype eq 'protein' || $sftype eq 'polypeptide') {
1742 $reltypename = 'derives_from';
1744 $reltypename = 'part_of';
1747 return $reltypename;
1753 Usage : $obj->next_seq
1757 Status : Not implemented (write only adaptor)
1762 my ($self, %argv) = @_;
1764 $self->throw('next_seq is not implemented; this is a write-only adapter.');
1768 =head2 _create_writer
1770 Title : _create_writer
1771 Usage : $obj->_create_writer
1772 Function : Creates XML::Writer object and writes start tag
1773 Returns : Nothing, though the writer persists as part of the chadoxml object
1779 sub _create_writer
{
1782 $self->{'writer'} = XML
::Writer
->new(OUTPUT
=> $self->_fh,
1787 $self->{'writer'}->xmlDecl("UTF-8");
1788 $self->{'writer'}->comment("created by Peili Zhang, Flybase, Harvard University\n".
1789 "and Scott Cain, GMOD, Cold Spring Harbor Laboratory");
1792 $self->{'writer'}->startTag('chado');
1797 =head2 close_chadoxml
1799 Title : close_chadoxml
1800 Usage : $obj->close_chadoxml
1801 Function : Writes the closing xml tag
1808 sub close_chadoxml
{
1811 $self->{'writer'}->endTag('chado');
1815 =head2 handle_unreserved_tags
1817 Title : handle_unreserved_tags
1818 Usage : $obj->handle_unreserved_tags
1819 Function : Converts tag value pairs to xml-ready hashrefs
1820 Returns : The array containing the hashrefs
1821 Args : In order: the Seq or SeqFeature object, the key, and the hasharray
1826 sub handle_unreserved_tags
{
1832 my @values = $seq->attributes($key);
1833 for my $value (@values) {
1835 "type_id" => {'name' => $key,
1836 'cv_id' => { 'name' => $cv_name{'feature_property'} }
1840 push(@arr, \
%prophash);
1846 =head2 handle_Alias_tag
1848 Title : handle_Alias_tag
1849 Usage : $obj->handle_Alias_tag
1850 Function : Convert Alias values to synonym hash refs
1851 Returns : An array of synonym hash tags
1852 Args : The seq or seqFeature object and the synonym hash array
1857 sub handle_Alias_tag
{
1862 my @Aliases = $seq->attributes('Alias');
1863 for my $Alias (@Aliases) {
1865 "type_id" => { 'name' => 'exact',
1866 'cv_id' => { 'name' => 'synonym_type' } },
1868 "synonym_sgml" => $Alias,
1870 push(@arr, {'synonym_id' => \
%synhash,
1871 'pub_id' => {'uniquename' => 'null',
1872 'type_id' => { 'name' => 'null',
1884 =head2 handle_Ontology_tag
1886 Title : handle_Ontology_tag
1887 Usage : $obj->handle_Ontology_tag
1888 Function : Convert Ontology_term values to ontology term hash refs
1889 Returns : An array of ontology term hash refs
1890 Args : The seq or seqFeature object and the ontology term array
1895 sub handle_Ontology_tag
{
1900 my @terms = $seq->attributes('Ontology_term');
1901 for my $term (@terms) {
1903 if ($term =~ /(\S+):(\S+)/) {
1909 'db_id' => { 'name' => $db },
1915 push(@arr, {cvterm_id
=> $hashref});
1921 =head2 handle_dbxref
1923 Title : handle_dbxref
1924 Usage : $obj->handle_dbxref
1925 Function : Convert Dbxref values to dbxref hashref
1926 Returns : An array of dbxref hashrefs
1927 Args : A seq or seqFeature object and the dbxref array
1938 my @terms = $seq->attributes($tag);
1939 for my $term (@terms) {
1941 if ($term =~ /(\S+):(\S+)/) {
1945 if ($acc =~ /(\S+)\.(\S+)/) {
1951 'db_id' => { 'name' => $db },
1952 'accession' => $acc,
1953 'version' => $version,
1958 $self->throw("I don't know how to handle a dbxref like $term");
1960 push(@arr, {'dbxref_id' => $hashref});
1965 =head2 handle_source
1967 Title : handle_source
1968 Usage : $obj->handle_source
1981 my $source = $seq->source();
1982 return @arr unless $source;
1986 'db_id' => {'name' => 'GFF_source'},
1987 'accession' => $source,
1991 push(@arr, {'dbxref_id' => $hashref});
1998 Usage : $obj->_srcf_hash
1999 Function : Creates the srcfeature hash for use in featureloc hashes
2000 Returns : The srcfeature hash
2001 Args : The srcfeature name, the srcfeature type and a reference to the
2013 my %hash = ('uniquename' => $srcf,
2014 'organism_id' => $orgref,
2015 'type_id' => {'name' => $stype,
2017 {'name' => $cv_name{'sequence'} }},