This file is indexed.

/usr/share/perl5/Bio/GMOD/SeqUtils.pm is in libchado-perl 1.23-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
=head1 NAME

  GMOD::Chado::SeqUtils  -- common sequence in/out/check methods for Chado DB

=head1 SYNOPSIS

 
=head1 SEE ALSO

  GMOD Chado sequence scripts for init_db, load_newseq, dump_seq, list_db .

  gmod_init_db.pl -- initialize a new database, adding organisms, intialize.sql,
     ontology data sets.
     
  gmod_load_newseq.pl -- add miscellaneous organism sequences, cDNA, EST, 
     microsatellites, etc. not located on genome.  Optionally 
     generate PublicID for these.

  gmod_dump_seq.pl -- output sequences selected by organism, publication (input file),
     seq type.
     
  gmod_list_db.pl  -- show feature statistics for chado db: # per organism, per seq type,
    per publication/infile, and checksum test for sequence duplications.


=head1 AUTHOR

  Don Gilbert, Feb 2004.

=head1 METHODS

=cut

package GMOD::Chado::SeqUtils;

use strict;

# use lib('/bio/biodb/common/perl/lib','/bio/biodb/common/system-local/perl/lib'); # test

use GMOD::Chado::LoadDBI;

use vars qw( 
  @dbparts 
  %cvterm
  %org_cache
  $nullcontact
  );

our $DEBUG;

use constant SequenceOntology => 'Sequence Ontology';
use constant IDCounter => 'PublicID:counter'; # dbIdCounter == # Db->name key

BEGIN {
  $DEBUG= 0 unless defined $DEBUG;
  @dbparts= qw(NAME HOST PORT USERNAME PASSWORD); #? get from Chado::LoadDBI ?
  %cvterm   = ();
  %org_cache = ();
}

sub new {
	my $that= shift;
	my $class= ref($that) || $that;
	my %fields = @_;  
	my $self = \%fields;
	bless $self, $class;
  $self->init();
	return $self;
}

sub init {
  my $self= shift;
  $self->{readwrite}= 0 unless defined $self->{readwrite};
  $self->{verbose}= 0 unless defined $self->{verbose};
  $self->{dochecksum}= 0 unless defined $self->{dochecksum};
  $self->{defline_species}= 1 unless defined $self->{defline_species};
  
  # $self->{autocv}= 0 unless defined $self->{autocv};
}


=item openChadoDB( %params )

  basically calls Chado::LoadDBI->init( %$dbvals )
  and setReadWrite flag, inits some values from db
  parameters:
    verbose => 1/0
    readwrite => 1/0, r/w, t/f
    dbvalues => \%dbvalues from getDatabaseOpenParams
    
=cut

sub openChadoDB {
  my $self = shift;
  my %opts = @_;  
  $self->{$_}= $opts{$_} foreach (keys %opts); 
  
  die "openChadoDB: call with dbvalues => \%dbvalues from getDatabaseOpenParams" 
    unless (ref $self->{dbvalues});
  GMOD::Chado::LoadDBI->init( %{$self->{dbvalues}} );
  
  # some useful values for readwrite only ?
  # ($nullpub)    = Bio::Chado::CDBI::Pub->search( miniref   => 'null' );
  ($nullcontact) = Bio::Chado::CDBI::Contact->search( name  => 'null' );
  $self->initAutoCvTable();
}



=item getDatabaseOpenParams()

 Runtime checks for Bio::Chado::CDBI::LoadDBI values of
   NAME HOST PORT USERNAME PASSWORD  [from getDatabaseParamKeys()]

 Checks %ENV for $GMOD_SERVICE_key, CHADO_DB_key,  e.g. 
  FLYBASE_DB_NAME = flybase-chado1
  FLYBASE_DB_PORT = 7404
    -- fallback to CHADO if GMOD_SERVICE is not defined
  CHADO_DB_NAME = chado-test 
  CHADO_DB_PORT = 7302
 Returns hash with these values, suitable for call to @ARG GetOptions()

  my %dbvals= getDatabaseOpenParams();
  
  my $ok= GetOptions(
    'dbname:s'  => \$dbvals{NAME},
    'name:s' => \$dbvals{NAME},
    'host:s' => \$dbvals{HOST},
    'port:s' => \$dbvals{PORT},
    'username:s' => \$dbvals{USERNAME},
    'password:s' => \$dbvals{PASSWORD},
    @otherOpts,
    );

=cut

sub getDatabaseParamKeys { my $self= shift; return @dbparts; } 

sub getDatabaseOpenParams {
  my $self= shift; 
  my %dbvals= map { $_ => '' } @dbparts;

  ## check %ENV -  first service_db keys, default to chado_db =  flybase, eugenes, daphnia, etc.
  my @service_db= ('CHADO_DB'); # what service is calling us ?
  unshift(@service_db, $ENV{'GMOD_SERVICE'}.'_DB')  if (defined $ENV{'GMOD_SERVICE'}); 
  unshift(@service_db, $ENV{'ARGOS_SERVICE'}.'_DB')  if (defined $ENV{'ARGOS_SERVICE'}); 

  foreach my $service_db (@service_db) {
    foreach my $part (@dbparts) {
      next if ($dbvals{$part});  
      my $v= $ENV{$service_db.'_'.uc($part)};
      $dbvals{$part}= $v if ($v);
      }
    }
  return %dbvals;
}


=item getSeqType($seqtype, $ontology)

 return Bio::Chado::CDBI::Cvterm matching seqtype from ontology. 
 Supports use of SO seq types

=cut
 
sub getSeqType {
  my ($self, $seqtype, $ontname)= @_;
  my $type_id= undef;
  my $sotype = undef;
  $ontname = SequenceOntology unless($ontname);
  
  return $cvterm{$seqtype} if ($cvterm{$seqtype});
  
  my @sotype =  Bio::Chado::CDBI::Cvterm->search( name => $seqtype ) 
             || Bio::Chado::CDBI::Cvterm->search_like( name => "%$seqtype%" );  
  
  unless(@sotype) {
    print STDERR "Seq type=$seqtype not found. Please choose a type from $ontname";
    return undef;
    }
  elsif (@sotype > 1) {
    print STDERR "These terms from $ontname match '$seqtype'.\n";
    print STDERR "  ",$_->name,"\n" foreach (@sotype);
    # allow user choice here..
    print STDERR "Choose Sequence type? \n"; #? STDERR?
    chomp( $seqtype = <STDIN> );
    foreach my $sot (@sotype) {
      if ($sot->name eq $seqtype) { $sotype= $sot; last; }
      }
    return undef unless($sotype);
    }
  else { $sotype= shift @sotype; }
     
  $sotype = $sotype->first() 
    if defined( $sotype ) and $sotype->isa('Class::DBI::Iterator');

  my ($socv) = Bio::Chado::CDBI::Cv->search( name => $ontname );
  unless ($socv) {
    print STDERR "Ontology $ontname is not loaded; using $seqtype";
    $self->cache_cvterm($seqtype);
    }
  elsif( $sotype->cv_id == $socv->id) {  
    print "Using seq type=".$sotype->name." from $ontname\n" if $self->{verbose};
    $cvterm{$seqtype}= $sotype;
    }
  else {
    print STDERR "$seqtype is not listed in $ontname";
    return undef;
    }

  return $cvterm{$seqtype};
}



sub initAutoCvTable {
  my ( $self ) = @_;
  ($self->{autocv}) = Bio::Chado::CDBI::Cv->search( name => 'autocreated' );
  
  if(!$self->{autocv} && $self->{readwrite}) {   
    ($self->{autocv}) = Bio::Chado::CDBI::Cv->find_or_create( {
      name       => 'autocreated',
      definition => "auto created by $0",
      } );
  }
}

=item cache_cvterm( $name [, $cv] )

 Look for $name in Bio::Chado::CDBI::Cvterm.
 If not found and readwrite, add to cvterm table, with cv->id (autocv default)
 Store in hash for frequent reuse.
 return Bio::Chado::CDBI::Cvterm  

=cut

sub cache_cvterm {
  my ( $self, $name, $cv ) = @_;
  return unless $name;  
  $cv= $self->{autocv} unless($cv);

  unless (defined $cvterm{$name}) {
    my ($term) =
       Bio::Chado::CDBI::Cvterm->search( name => $name )
    || Bio::Chado::CDBI::Cvterm->search( name => ucfirst($name) );
    
    if ( $term ) {
      $term = $term->first() if defined( $term ) and $term->isa('Class::DBI::Iterator');
      } 
    elsif ($self->{readwrite} && $cv) {
      $term = Bio::Chado::CDBI::Cvterm->find_or_create( {
              name       => $name,
              cv_id      => $cv->id,
              definition => "auto created by $0",
              } ) ;
      warn "unable to create a '$name' entry in the cvterm table"
        unless($term);
      }
    $cvterm{$name} = $term; 
    }
    
  return $cvterm{$name}; 
}




=item getOrganism( $organism, $quiet)

 return Bio::Chado::CDBI::Organism matching common name, abbreviation (best) or genus.
 Prompts for choice if ! $quiet

=cut

sub getOrganism {
  my ($self, $organism, $quiet)= @_;
  return undef unless($organism);
  my $chadorg= $org_cache{$organism};
  return $chadorg if $chadorg;

  my $iter = Bio::Chado::CDBI::Organism->search( common_name => lc($organism) )
    || Bio::Chado::CDBI::Organism->search( abbreviation => ucfirst($organism) )
    || Bio::Chado::CDBI::Organism->search( genus => $organism  );

  if ($iter) { 
    if ( $iter->count == 1 ) { #? || quiet
      $chadorg = $iter->first();  
    } elsif (!$quiet) {
      print STDERR "The organism '$organism' matches these:\n";
      for (my $org = $iter->first; ($org) ; $org= $iter->next) {
        print STDERR "  ".$org->genus." ".$org->species."/".$org->abbreviation."/".$org->common_name."\n"; 
        }
      print STDERR "Select organism? (abbreviation): \n";
      chomp( $organism = <STDIN> );
      for (my $org = $iter->first; ($org) ; $org= $iter->next) {
        if ($org->abbreviation() eq $organism) { $chadorg= $org; last; }
        }
      }
    }
    
  else { 
    print STDERR "The organism '$organism' could not be found.\n";
    unless($quiet) {
      print STDERR "Available organisms:\n";
      $iter = Bio::Chado::CDBI::Organism->retrieve_all;
      for (my $org = $iter->first; ($org) ; $org= $iter->next) {
        print STDERR "  ".$org->genus." ".$org->species."/".$org->abbreviation."/".$org->common_name."\n"; 
        }
      print STDERR "Select organism? (abbreviation): \n";
      chomp( $organism = <STDIN> );
      for (my $org = $iter->first; ($org) ; $org= $iter->next) {
        if ($org->abbreviation() eq $organism) { $chadorg= $org; last; }
        }
      }
    }
  if ($chadorg) {
    $org_cache{$organism}= $chadorg;
    print "Working with ".$chadorg->genus." ".$chadorg->species.".\n";
    }
  return $chadorg;
}



=pod
                                                                                
=item getSynonyms($chado_feature)
                                                                                
fetch synonym values, returns (wantarray) ? list : first
                                                                                
=cut

sub getSynonyms {
  my ($self, $chado_feature)   = @_;
  my @ftsyn  = Bio::Chado::CDBI::Feature_Synonym->search(
              feature_id => $chado_feature->id,
              # pub_id     => $pub->id,
              );
  if (wantarray) {
    my @names= ();
    push @names, $_->synonym->name() foreach (@ftsyn);
    return @names; 
    }
  else {
    return (@ftsyn) ? $ftsyn[0]->synonym->name() : undef;
    }
}



=pod
                                                                                
=item getPubFeatures($pub)
                                                                                
 return features given $pub->id (OUTFILE reference)
                                                                               
=cut

sub getPubFeatures {
  my ($self, $pub)   = @_;
  my @allfeats= ();
  my @fpub = Bio::Chado::CDBI::Feature_Pub->search(
      pub_id     => $pub->id,
      { order_by=>'feature_id' },
      );
  # print "getPubFeatures ".$pub->id." n= ".scalar(@fpub)."\n"  if $self->{verbose};

  push @allfeats, $_->feature_id foreach (@fpub);
  return @allfeats;     
}



=pod
                                                                                
=item getFeaturePubs($feat)
                                                                                
 return pubs given $feat->feature_id  
                                                                               
=cut

sub getFeaturePubs {
  my ($self, $ft)   = @_;
  my @items= ();
  my @fpub = Bio::Chado::CDBI::Feature_Pub->search(
      feature_id     => $ft->id,
      { order_by=>'pub_id' },
      );
  push @items, $_->pub_id foreach (@fpub);
  return @items;     
}


=item getDbxrefs($chado_feature)

  @dbxrefs is array of DbName:DbAccession
  
=cut

sub getDbxrefs {
  my ($self, $chado_feature)   = @_;
  my @dbxrefs= ();
  
  my @feature_dbxref = Bio::Chado::CDBI::Feature_Dbxref->search(
    feature_id => $chado_feature->id,
    );

  foreach my $d (@feature_dbxref) {
    next unless $d->dbxref_id;
    my $acc= $d->dbxref_id->accession;
    my $db = $d->dbxref_id->db_id->name; ## cache this one
    push(@dbxrefs, "$db:$acc");
    }
    
  return @dbxrefs;     
}



=pod

=item getProperties($chado_feature)

get property values from the featureprop table.
%props is hash of property name => value
 -- need bag, not hash - many vals per name
 
=cut

sub getProperties {
  my ($self, $chado_feature)   = @_;
  my %props= ();

   my @featureprop = Bio::Chado::CDBI::Featureprop->search(
      feature_id => $chado_feature->id,
      );
    
  foreach my $p (@featureprop) {
    next unless $p->type_id;
    my $tpid= $p->type_id;
    my $tpname= $self->{type_id}{$tpid};
    unless($tpname) { $self->{type_id}{$tpid}= $tpname= $tpid->name; }

    #my $tpname= $p->type_id->name;
    $props{$tpname} .= "," if ($props{$tpname});
    $props{$tpname} .= $p->value;
    }
    
  return %props;     
}


=item dumpSequences($outh, @chado_features)

  Write sequences to $outh from Bio::Chado::CDBI::Features.
  Includes seq_type, synonyms, feature_properties, feature_dbxrefs on defline
  Only fasta dump now.  E.g.
  
  >WFcd0000100 len=567;type=cDNA_clone;synonym=P1-E62000FW40325,WFBid100;contact=JColbo
  urne;library=CGBvntr;date=Jan2004;taxon=D.pulicaria;clone=P1-E62000FW40325;strain=Mar
  ieLake,Oregon
  GCGGGAGNCCGGTATATTGCAGAGTGGCATTATGGCCGNGAAGCAGTNGT
  ATCAACGCANAGTGGCCATTATGGCCGGGAAGCAGTGGTATCAACGCACG
  
  ## this is SLOW for 15K seq-feature database ...
  .. use iterator, not @feaure array ..
  .. cache common values ..
  
=cut

sub dumpSequences {
  my ($self, $outh, $chado_features)= @_;
  my $i   = 0;
  # print "dumpSequences n= ".scalar(@chado_features)."\n"  if $self->{verbose};
    
  if (!defined($chado_features)) {
    warn "Need Bio::Chado::CDBI::Feature param"; 
    return -1;
    }
  elsif ($chado_features->isa('Class::DBI::Iterator')) {
    for (my $ft = $chado_features->first; ($ft) ; $ft= $chado_features->next) {
      my $res = $ft->residues;
      my $defline= $self->getFeatureDefline($ft);
      print $outh $defline,"\n";
      
      $res =~ s/(.{1,50})/$1\n/g;
      print $outh $res,"\n";   
      $i++;
      }
    return $i;
    }
    
  my @fts=();
  if (ref $chado_features =~ /ARRAY/) {
    @fts= @$chado_features;
    }
  elsif ($chado_features->isa('Bio::Chado::CDBI::Feature')) {
    @fts= ($chado_features);
    }
  foreach my $ft (@fts) {
    my $res = $ft->residues;
    my $defline= $self->getFeatureDefline($ft);
    print $outh $defline,"\n";

    $res =~ s/(.{1,50})/$1\n/g;
    print $outh $res,"\n";   
    
    $i++;
    }
     
  return $i;
}


=item getFeatureDefline($chado_feature)

  return basic >fasta string of chado_feature information 

=cut

sub getFeatureDefline {
  my ($self, $chado_feature)= @_;
  #should we bother w/ Bio::Seq construction -> SeqIO::writeseq(seq); ?

  my $name= $chado_feature->name;
  my $len = $chado_feature->seqlen;
  my $defline= ">$name len=$len";

  my $tpid= $chado_feature->type_id;
  my $tpname= $self->{type_id}{$tpid};
  unless($tpname) { $self->{type_id}{$tpid}= $tpname= $tpid->name; }
  $defline .= "; type=" . $tpname; ## $tpid->name $ cache this
  
  my @synonyms= $self->getSynonyms($chado_feature);
  $defline .= "; synonym=".join(",",@synonyms) if @synonyms;

  my %props= $self->getProperties($chado_feature);

  if ($self->{defline_species}) { 
    #?? always/sometimes add species=$org->genus." ".$org->species;
    my $org= $chado_feature->organism_id;
    
    # my $ospp= $org->species;
    # my $species= $org->genus." ".$org->species;

    my $ospp= $self->{spponly}{$org};
    unless($ospp) { $self->{spponly}{$org}= $ospp= $org->species; }

    my $species= $self->{species}{$org};
    unless($species) { $self->{species}{$org}= $species= $org->genus." ".$org->species; }
    
    foreach (qw(taxon species organism)) {
      my $spp= $props{$_}; 
      if ($spp && $spp =~ /$ospp/i) { delete $props{$_}; } #what - do both?; ignore this?
      }
      
    $defline .= "; species=".$species;
    }
  
  $defline .= "; ".join("; ", (map{ "$_=$props{$_}"} sort keys %props))  
    if %props;

  my @dbxrefs= $self->getDbxrefs($chado_feature);
  $defline .= "; dbxref=".join(",",@dbxrefs) if @dbxrefs;
  
  if ($self->{dochecksum}) { # only if really want
    my $check= $chado_feature->md5checksum; ## add if not 0
    $defline .= "; checksum=$check" if ($check);
    }
  
  return $defline;
}


#? *defline = &getFeatureDefline;


=item lastPublicId($idtag, [$lastid])

  Get [Set] last public id number for given idtag

=cut

sub lastPublicId {
  my($self, $idtag, $idclass, $lastid)= @_;

  my ($iddb) = Bio::Chado::CDBI::Db->search( name => IDCounter ); # $dbIdCounter  
  if (!$iddb && $self->{readwrite}) {  
    ($iddb) = Bio::Chado::CDBI::Db->find_or_create( {
          name       =>  IDCounter,
          description => "database id counters created by $0",
          contact_id => $nullcontact, #??
          # urlprefix => $idtag,   #?
          # url => $url, 
        } ) ;
    $iddb->dbi_commit if $iddb;  
    }

  #? save idbx
  my ($idbx) = Bio::Chado::CDBI::Dbxref->search( accession => $idtag , db_id => $iddb->id);
  $idbx = $idbx->first()  
    if defined($idbx) and $idbx->isa('Class::DBI::Iterator');

  if($idbx) {
    if (defined $lastid && $self->{readwrite}) { 
      $idbx->version($lastid); 
      $idbx->update(); $idbx->dbi_commit(); 
      print "Put last id for $idtag = $lastid\n" if ($self->{verbose});
      }
    else { 
      $lastid= $idbx->version();  
      print "Get last id for $idtag = $lastid\n" if ($self->{verbose});
      }
  } else {
    $lastid= 0;
    if ( $self->{readwrite} ) {
      $idbx=  Bio::Chado::CDBI::Dbxref->find_or_create( {
                accession  => $idtag,
                version    => $lastid,  # our data !
                db_id      => $iddb->id,
                description => "id counter for $idclass by $0",
            } );
      $idbx->dbi_commit if $idbx; 
      print "New last id for $idtag = $lastid\n" if ($self->{verbose});
      }
    }
  return $lastid;
}


=item listPublicIds($outhandle)

list public id counters
 
=cut

sub listPublicIds {
  my ($self, $outhandle)= @_;
  print $outhandle "\nPublic ID counter\n";
  print $outhandle join("\t",qw(ID_Tag Last_ID Description)),"\n";
  my ($iddb) = Bio::Chado::CDBI::Db->search( name => IDCounter );
  if ($iddb) {
    my $iter = Bio::Chado::CDBI::Dbxref->search( db_id => $iddb->id);
    for (my $idbx= $iter->first(); ($idbx); $idbx= $iter->next()) {
       my $idtag = $idbx->accession();
       my $lastid= $idbx->version();  
       my $desc  = $idbx->description();
       print $outhandle  join("\t", $idtag, $lastid, $desc),"\n";
       }
    }
  print $outhandle "-"x60,"\n\n";  
}


=item listDupChecksums( $outhandle, [$feature_iterator])

checks thru features md5checksum for duplicates and lists any
if feature_iterator is null, checks all Bio::Chado::CDBI::Feature 
 
=cut

sub listDupChecksums {
  my ($self, $outhandle, $iter)= @_;
  print $outhandle "\nDuplicate checksums\n";
  print $outhandle 
    join("\t",qw(Name____ Length Seq_type Synonym Feat_id Publication Checksum)),"\n";
  
  my %checks=();
  $iter = Bio::Chado::CDBI::Feature->retrieve_all unless($iter);
  for (my $fit = $iter->first; ($fit) ; $fit= $iter->next) {
    my $ck= $fit->md5checksum;
    next unless($ck);
    $checks{$ck}++;
    }
    
  foreach my $ck (keys %checks) {
    next unless ($checks{$ck}>1);
    $iter= Bio::Chado::CDBI::Feature->search( md5checksum => $ck  );
    for (my $fit = $iter->first; ($fit) ; $fit= $iter->next) {
      my $syn= $self->getSynonyms($fit);
      my @pub= $self->getFeaturePubs($fit); 
      my $pub= (@pub ? "'".$pub[0]->title()."'" : '');
      print $outhandle join("\t", $fit->name, $fit->seqlen,
            $fit->type_id->name, $syn, $fit->feature_id, $pub, $ck), 
            "\n";
      }
    }
  print $outhandle "-"x60,"\n\n";  
}


1;