This file is indexed.

/usr/share/perl5/Bio/Assembly/Scaffold.pm is in libbio-perl-perl 1.6.924-3.

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
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
#
# BioPerl module for Bio::Assembly::Scaffold
#
# Copyright by Robson F. de Souza
#
# You may distribute this module under the same terms as perl itself
#
# POD documentation - main docs before the code

=head1 NAME

Bio::Assembly::Scaffold - Perl module to hold and manipulate sequence assembly
data.

=head1 SYNOPSIS
# 
    # Module loading
    use Bio::Assembly::IO;

    # Assembly loading methods
    my $aio = Bio::Assembly::IO->new(-file=>"test.ace.1", -format=>'phrap');
    my $assembly = $aio->next_assembly;

    foreach my $contig ($assembly->all_contigs) {
        # do something... (see Bio::Assembly::Contig)
    }

=head1 DESCRIPTION

Bio::Assembly::Scaffold was developed to store and manipulate data
from sequence assembly programs like Phrap. It implements the
ScaffoldI interface and intends to be generic enough to be used by
Bio::Assembly::IO drivers written to programs other than Phrap.

=head1 FEEDBACK

=head2 Mailing Lists

User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to the
Bioperl mailing lists  Your participation is much appreciated.

  bioperl-l@bioperl.org                  - General discussion
  http://bioperl.org/wiki/Mailing_lists  - About the mailing lists

=head2 Support 

Please direct usage questions or support issues to the mailing list:

I<bioperl-l@bioperl.org>

rather than to the module maintainer directly. Many experienced and 
reponsive experts will be able look at the problem and quickly 
address it. Please include a thorough description of the problem 
with code and data examples if at all possible.

=head2 Reporting Bugs

Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution.  Bug reports can be submitted via the
web:

  https://github.com/bioperl/bioperl-live/issues

=head1 AUTHOR - Robson Francisco de Souza

rfsouza@citri.iq.usp.br

=head1 APPENDIX

The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _

=cut

package Bio::Assembly::Scaffold;

use strict;
use Bio::Annotation::Collection;

use base qw(Bio::Root::Root Bio::Assembly::ScaffoldI);

=head2 new ()

    Title   : new
    Usage   : $scaffold = new ( -id       => "assembly 1",
                                -source   => 'program_name',
                                -contigs  => \@contigs,
                                -singlets => \@singlets );
    Function: creates a new scaffold object
    Returns : Bio::Assembly::Scaffold
    Args    : -id       : [string] scaffold name
              -source   : [string] sequence assembly program
              -contigs  : reference to array of Bio::Assembly::Contig objects
              -singlets : reference to array of Bio::Assembly::Singlet objects


=cut

sub new {
  my($class, @args) = @_;
  my $self = $class->SUPER::new(@args);
  my ($id, $src, $contigs, $singlets) = $self->_rearrange(
      [qw(ID SOURCE CONTIGS SINGLETS)], @args);

  # Scaffold defaults
  $self->{'_id'} = 'NoName';
  $self->{'_source'} = 'Unknown';
  $self->{'_contigs'} = {};
  $self->{'_singlets'} = {};
  $self->{'_seqs'} = {};
  $self->{'_annotation'} = Bio::Annotation::Collection->new();

  # Import manual info
  $self->{'_id'} = $id if (defined $id);
  $self->{'_source'} = $src if (defined $src);
  
  # Add contigs and singlets to scaffold
  if (defined $contigs && ref($contigs = 'ARRAY')) {
    for my $contig (@{$contigs}) {
      if( ! ref $contig || ! $contig->isa('Bio::Assembly::Contig') ) {
        $self->throw("Bio::Assembly::Scaffold::new is unable to process non".
          "Bio::Assembly::Contig object [", ref($contig), "]");
      }
      $self->add_contig($contig);
    }
  }
  if (defined $singlets && ref($singlets = 'ARRAY')) {
    for my $singlet (@{$singlets}) {
      if( ! ref $singlet || ! $singlet->isa('Bio::Assembly::Singlet') ) {
        $self->throw("Bio::Assembly::Scaffold::new is unable to process non".
          "Bio::Assembly::Singlet object [", ref($singlet), "]");
      }
      $self->add_singlet($singlet);
    }
  }
  
  return $self;
}

=head1 Accessing general assembly data

=cut

=head2 id

    Title   : id
    Usage   : $assembly->id()
    Function: Get/Set assembly ID
    Returns : string or undef
    Args    : string

=cut

sub id {
    my ($self, $id) = @_;
    return $self->{'_id'} = $id if (defined $id);
    return $self->{'_id'};
}

=head2 annotation

    Title   : annotation
    Usage   : $assembly->annotation()
    Function: Get/Set assembly annotation object
    Returns : Bio::Annotation::Collection
    Args    : none

=cut

sub annotation {
    my ($self, $ref) = shift;
    $self->{'_annotation'} = $ref if (defined $ref);
    return $self->{'_annotation'};
}

=head2 get_nof_contigs

    Title   : get_nof_contigs
    Usage   : $assembly->get_nof_contigs()
    Function: Get the number of contigs included in the scaffold
    Returns : integer
    Args    : none

=cut

sub get_nof_contigs {
    my $self = shift;
    return scalar( $self->get_contig_ids() );
}

=head2 get_nof_contig_seqs

    Title   : get_nof_contig_seqs
    Usage   : $assembly->get_nof_contig_seqs()
    Function: Get the number of sequences included in contigs of the 
              scaffold (no consensus sequences or singlets)
    Returns : integer
    Args    : none

=cut

sub get_nof_contig_seqs {
    my $self = shift;

    my $nof_seqs = 0;
    foreach my $contig ($self->all_contigs) {
        $nof_seqs += scalar( $contig->get_seq_ids() );
    }

    return $nof_seqs;
}
# function alias for backward compatibility
*get_nof_sequences_in_contigs = \&get_nof_contig_seqs;


=head2 get_nof_singlets (get_nof_singlet_seqs)

    Title   : nof_singlets
    Usage   : $assembly->nof_singlets()
    Function: Get the number of singlets included in the assembly
    Returns : integer
    Args    : none

=cut

sub get_nof_singlets {
    my $self = shift;
    return scalar( $self->get_singlet_ids() );
}
*get_nof_singlet_seqs = \&get_nof_singlets;

=head2 get_all_seq_ids

    Title   : get_all_seq_ids
    Usage   : $assembly->get_all_seq_ids()
    Function: Get the ID of all sequences making up the scaffold
              (sequences from contigs and singlets, not consensus).
    Returns : array of strings
    Args    : none

=cut

sub get_all_seq_ids {
    my $self = shift;
    return keys %{ $self->{'_seqs'} };
}

=head2 get_nof_seqs

    Title   : get_nof_seqs
    Usage   : $assembly->get_nof_seqs()
    Function: Get total number of sequences making up the scaffold
              (sequences from contigs and singlets, not consensus).
    Returns : integer
    Args    : none

=cut

sub get_nof_seqs {
    my $self = shift;
    return scalar $self->get_all_seq_ids;
}

=head2 get_contig_seq_ids

    Title   : get_contig_seq_ids
    Usage   : $assembly->get_contig_seq_ids()
    Function: Get the ID of all sequences in contigs
    Returns : array of strings
    Args    : none

=cut

sub get_contig_seq_ids {
    my $self = shift;
    my @ids;
    for my $contig ( $self->all_contigs ) {
        push @ids, $contig->get_seq_ids;
    }
    return @ids;
}
# function alias for backward compatibility
*get_seq_ids = \&get_contig_seq_ids; 

=head2 get_contig_ids

    Title   : get_contig_ids
    Usage   : $assembly->get_contig_ids()
    Function: Access list of contig IDs from assembly
    Returns : an array, if there are any contigs in the
              assembly. An empty array otherwise
    Args    : none

=cut

sub get_contig_ids {
    my $self = shift;

    return wantarray
        ? sort keys %{$self->{'_contigs'}}
        : scalar keys %{$self->{'_contigs'}};
}

=head2 get_singlet_ids (get_singlet_seq_ids)

    Title   : get_singlet_ids
    Usage   : $assembly->get_singlet_ids()
    Function: Access list of singlet IDs from assembly
    Returns : array of strings if there are any singlets
              otherwise an empty array
    Args    : none

=cut

sub get_singlet_ids {
    my $self = shift;

    return wantarray
        ? sort keys %{$self->{'_singlets'}}
        : scalar keys %{$self->{'_singlets'}};
}
*get_singlet_seq_ids = \&get_singlet_ids;

=head2 get_seq_by_id

    Title   : get_seq_by_id
    Usage   : $assembly->get_seq_by_id($id)
    Function: Get a reference for an sequence making up the scaffold 
              (from a contig or singlet, not consensus)
    Returns : a Bio::LocatableSeq object
              undef if sequence $id is not found in the scaffold
    Args    : [string] sequence identifier (id)

=cut

sub get_seq_by_id {
    my $self = shift;
    my $seqID = shift;

    return unless (exists $self->{'_seqs'}{$seqID});

    return $self->{'_seqs'}{$seqID}->get_seq_by_name($seqID);
}

=head2 get_contig_by_id

    Title   : get_contig_by_id
    Usage   : $assembly->get_contig_by_id($id)
    Function: Get a reference for a contig
    Returns : a Bio::Assembly::Contig object or undef
    Args    : [string] contig unique identifier (ID)

=cut

sub get_contig_by_id {
    my $self = shift;
    my $contigID = shift;

    return unless (exists $self->{'_contigs'}{$contigID});

    return $self->{'_contigs'}{$contigID};
}

=head2 get_singlet_by_id

    Title   : get_singlet_by_id
    Usage   : $assembly->get_singlet_by_id()
    Function: Get a reference for a singlet
    Returns : Bio::Assembly::Singlet object or undef
    Args    : [string] a singlet ID

=cut

sub get_singlet_by_id {
    my $self = shift;

    my $singletID = shift;

    return unless (exists $self->{'_singlets'}{$singletID});

    return $self->{'_singlets'}{$singletID};
}

=head1 Modifier methods

=cut

=head2 add_contig

    Title   : add_contig
    Usage   : $assembly->add_contig($contig)
    Function: Add a contig to the assembly
    Returns : 1 on success
    Args    : a Bio::Assembly::Contig object
          order (optional)

=cut

sub add_contig {
    my ($self, $contig) = @_;

    # Input check
    if( !ref $contig || ! $contig->isa('Bio::Assembly::Contig') ) {
        $self->throw("Bio::Assembly::Scaffold::add_contig is unable to process".
            " non Bio::Assembly::Contig object [", ref($contig), "]");
    }
    
    # Create and attribute contig ID
    my $contigID  = $contig->id();
    if( !defined $contigID ) {
        $contigID = 'Unknown_' . ($self->get_nof_contigs() + 1);
        $contig->id($contigID);
        $self->warn("Attributing ID $contigID to unnamed Bio::Assembly::Contig".
            " object.");
    }

    # Adding contig to scaffold
    $self->warn("Replacing contig $contigID with a new contig object")
        if (exists $self->{'_contigs'}{$contigID});
    $self->{'_contigs'}{$contigID} = $contig;
    $contig->assembly($self); # weak circular reference

    # Put contig sequences in the list of sequences belonging to the scaffold
    foreach my $seqID ($contig->get_seq_ids()) {
        if (exists $self->{'_seqs'}{$seqID} &&
            not($self->{'_seqs'}{$seqID} eq $contig) ) {
            $self->warn( "Sequence $seqID already assigned to object ".
                $self->{'_seqs'}{$seqID}->id().". Moving to contig $contigID");
        }
        $self->{'_seqs'}{$seqID} = $contig;
    }
    
    return 1;
}

=head2 add_singlet

    Title   : add_singlet
    Usage   : $assembly->add_singlet($seq)
    Function: Add a singlet to the assembly
    Returns : 1 on success
    Args    : a Bio::Assembly::Singlet object
              order (optional)

=cut

sub add_singlet {
    my ($self, $singlet) = @_;

    # Input check
    if ( !ref $singlet || ! $singlet->isa('Bio::Assembly::Singlet') ) {
        $self->throw("Bio::Assembly::Scaffold::add_singlet is unable to process".
            " non Bio::Assembly::Singlet object [", ref($singlet), "]");
    }
    
    # Create and attribute singlet ID
    my $singletID = $singlet->id();
    if( !defined $singletID ) {
        $singletID = 'Unknown_' . ($self->get_nof_singlets() + 1);
        $singlet->id($singletID);
        $self->warn("Attributing ID $singletID to unnamed Bio::Assembly::".
            "Singlet object.");
    }
    
    # Adding singlet to scaffold
    $self->warn("Replacing singlet $singletID with a new singlet object")
        if (exists $self->{'_singlets'}{$singletID});
    $self->{'_singlets'}{$singletID} = $singlet;
    $singlet->assembly($self); # weak circular reference

    # Put singlet sequence in the list of sequences belonging to the scaffold
    my $seqID = $singlet->seqref->id();
    if (exists $self->{'_seqs'}{$seqID} &&
        not($self->{'_seqs'}{$seqID} eq $singlet) ) {
        $self->warn( "Sequence $seqID already assigned to object ".
            $self->{'_seqs'}{$seqID}->id().". Moving to singlet $singletID");
    }
    $self->{'_seqs'}{$seqID} = $singlet;

    return 1;
}

=head2 update_seq_list

    Title   : update_seq_list
    Usage   : $assembly->update_seq_list()
    Function: 

              Synchronizes the assembly registry for sequences in
              contigs and contig actual aligned sequences content. You
              probably want to run this after you remove/add a
              sequence from/to a contig in the assembly.

    Returns : 1 for success
    Args    : none 

=cut

sub update_seq_list {
    my $self = shift;
    
    $self->{'_seqs'} = {};

    # Put sequences in contigs in list of sequences belonging to the scaffold
    foreach my $contig ($self->all_contigs) {
        my $contigID = $contig->id();
        foreach my $seqID ($contig->get_seq_ids) {
            if (exists $self->{'_seqs'}{$seqID} &&
                not($self->{'_seqs'}{$seqID} eq $contig) ) {
                $self->warn( "Sequence $seqID already assigned to object ".
                    $self->{'_seqs'}{$seqID}->id().". Moving to contig $contigID");
            }
            $self->{'_seqs'}{$seqID} = $contig;
        }
    }
    
    # Put singlet sequences in the list of sequences belonging to the scaffold
    foreach my $singlet ($self->all_singlets) {
        my $singletID = $singlet->id();
        my $seqID     = $singlet->seqref->id();
        if (exists $self->{'_seqs'}{$seqID} &&
            not($self->{'_seqs'}{$seqID} eq $singlet) ) {
            $self->warn( "Sequence $seqID already assigned to object ".
                $self->{'_seqs'}{$seqID}->id().". Moving to singlet $singletID");
        }
        $self->{'_seqs'}{$seqID} = $singlet;
    }

    return 1;
}

=head2 remove_contigs

    Title   : remove_contigs
    Usage   : $assembly->remove_contigs(1..4)
    Function: Remove contig from assembly object
    Returns : an array of removed Bio::Assembly::Contig
              objects
    Args    : an array of contig IDs 

    See function get_contig_ids() above

=cut

sub remove_contigs {
    my ($self, @args) = @_;

    my @ret = ();
    foreach my $contigID (@args) {
        foreach my $seqID ($self->get_contig_by_id($contigID)->get_seq_ids()) {
            delete $self->{'_seqs'}{$seqID};
        }
        push(@ret, $self->{'_contigs'}{$contigID});
        delete $self->{'_contigs'}{$contigID};
    }

    return @ret;
}

=head2 remove_singlets

    Title   : remove_singlets
    Usage   : $assembly->remove_singlets(@singlet_ids)
    Function: Remove singlet from assembly object
    Returns : the Bio::Assembly::Singlet objects removed
    Args    : a list of singlet IDs

    See function get_singlet_ids() above

=cut

sub remove_singlets {
    my ($self,@args) = @_;

    my @ret = ();
    foreach my $singletID (@args) {
        push(@ret,$self->{'_singlets'}{$singletID});
        delete $self->{'_singlets'}{$singletID};
    }

    return @ret;
}

=head2 remove_features_collection

    Title   : remove_features_collection
    Usage   : $assembly->remove_features_collection()
    Function: Removes the collection of features associated to every
              contig and singlet of the scaffold. This can be useful
              to save some memory (when contig and singlet features are
              not needed).
    Returns   : none
    Argument  : none

=cut

sub remove_features_collection {
    my ($self) = @_;
    for my $obj ( $self->all_contigs, $self->all_singlets ) {
        $obj->remove_features_collection;
    }
    return;
}


=head1 Contig and singlet selection methods

=cut

=head2 select_contigs

    Title   : select_contigs
    Usage   : $assembly->select_contigs(@list)
    Function: Select an array of contigs from the assembly
    Returns : an array of Bio::Assembly::Contig objects
    Args    : an array of contig ids

    See function get_contig_ids() above

=cut

sub select_contigs {
    my ($self,@args) = @_;

    my @contigs = ();
    foreach my $contig (@args) {
    unless (exists $self->{'_contigs'}{$contig}) {
        $self->warn("$contig contig not found. Ignoring...");
        next;
    }
    push(@contigs, $self->{'_contigs'}{$contig});
    }

    return @contigs;
}

=head2 select_singlets

    Title   : select_singlets
    Usage   : $assembly->select_singlets(@list)
    Function: Selects an array of singlets from the assembly
    Returns : an array of Bio::Assembly::Singlet objects
    Args    : an array of singlet ids

    See function get_singlet_ids() above

=cut

sub select_singlets {
    my ($self,@args) = @_;

    my @singlets = ();
    foreach my $singlet (@args) {
    unless (exists $self->{'_singlets'}{$singlet}) {
        $self->warn("$singlet singlet not found. Ignoring...");
        next;
    }
    push(@singlets, $self->{'_singlets'}{$singlet});
    }

    return @singlets;
}

=head2 all_contigs

    Title   : all_contigs
    Usage   : my @contigs = $assembly->all_contigs
    Function: 

              Returns a list of all contigs in this assembly.  Contigs
              are both clusters and alignments of one or more reads,
              with an associated consensus sequence.

    Returns : array of Bio::Assembly::Contig (in lexical id order)
    Args    : none

=cut

sub all_contigs {
    my ($self) = @_;

    my @contigs = ();
    foreach my $contig (sort { $a cmp $b } keys %{ $self->{'_contigs'} }) {
        push(@contigs, $self->{'_contigs'}{$contig});
    }

    return @contigs;
}

=head2 all_singlets

    Title   : all_singlets
    Usage   : my @singlets = $assembly->all_singlets
    Function: 

              Returns a list of all singlets in this assembly.
          Singlets are isolated reads, without non-vector
          matches to any other read in the assembly.

    Returns : array of Bio::Assembly::Singlet objects (in lexical order by id)
    Args    : none

=cut

sub all_singlets {
    my ($self) = @_;

    my @singlets = ();
    foreach my $singlet (sort { $a cmp $b } keys %{ $self->{'_singlets'} }) {
    push(@singlets, $self->{'_singlets'}{$singlet});
    }

    return @singlets;
}


1;