Method: Bio::Locations#to_s

Defined in:
lib/bio/location.rb

#to_sObject

String representation.

Note: In some cases, it fails to detect whether “complement(join(…))” or “join(complement(..))”, and whether “complement(order(…))” or “order(complement(..))”.


Returns

String



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
# File 'lib/bio/location.rb', line 511

def to_s
  return '' if @locations.empty?
  complement_join = false
  locs = @locations
  if locs.size >= 2 and locs.inject(true) do |flag, loc|
      # check if each location is complement
      (flag && (loc.strand == -1) && !loc.xref_id)
    end and locs.inject(locs[0].from) do |pos, loc|
      if pos then
        (pos >= loc.from) ? loc.from : false
      else
        false
      end
    end then
    locs = locs.reverse
    complement_join = true
  end
  locs = locs.collect do |loc|
    lt = loc.lt ? '<' : ''
    gt = loc.gt ? '>' : ''
    str = if loc.from == loc.to then
            "#{lt}#{gt}#{loc.from.to_i}"
          elsif loc.carat then
            "#{lt}#{loc.from.to_i}^#{gt}#{loc.to.to_i}"
          else
            "#{lt}#{loc.from.to_i}..#{gt}#{loc.to.to_i}"
          end
    if loc.xref_id and !loc.xref_id.empty? then
      str = "#{loc.xref_id}:#{str}"
    end
    if loc.strand == -1 and !complement_join then
      str = "complement(#{str})"
    end
    if loc.sequence then
      str = "replace(#{str},\"#{loc.sequence}\")"
    end
    str
  end
  if locs.size >= 2 then
    op = (self.operator || 'join').to_s
    result = "#{op}(#{locs.join(',')})"
  else
    result = locs[0]
  end
  if complement_join then
    result = "complement(#{result})"
  end
  result
end