Class: Bio::PolyploidTools::ArmMap

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/PolyploidTools/Marker.rb

Overview

The map hast to come sorted.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeArmMap

Returns a new instance of ArmMap.



81
82
83
# File 'lib/bio/PolyploidTools/Marker.rb', line 81

def initialize
  @markers = Hash.new
end

Instance Attribute Details

#chromosomeObject

Returns the value of attribute chromosome.



80
81
82
# File 'lib/bio/PolyploidTools/Marker.rb', line 80

def chromosome
  @chromosome
end

#global_reference(reference) ⇒ Object (readonly)

Returns the value of attribute global_reference.



79
80
81
# File 'lib/bio/PolyploidTools/Marker.rb', line 79

def global_reference
  @global_reference
end

#markersObject (readonly)

Returns the value of attribute markers.



79
80
81
# File 'lib/bio/PolyploidTools/Marker.rb', line 79

def markers
  @markers
end

#reference(reference) ⇒ Object (readonly)

Returns the value of attribute reference.



79
80
81
# File 'lib/bio/PolyploidTools/Marker.rb', line 79

def reference
  @reference
end

Instance Method Details

#align_markers(output) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/bio/PolyploidTools/Marker.rb', line 85

def align_markers(output)
  Bio::Blat.align(@reference.fasta_path, @fasta_markers, output) do |hit|
    marker = markers[hit.query_id]
    best = marker.best_hit
    unless marker.best_hit 
      markers[hit.query_id].best_hit = hit
    else
      marker.best_hit = hit if hit.score > marker.best_hit.score
    end
  end
end


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/bio/PolyploidTools/Marker.rb', line 97

def print_fasta_contigs_for_markers(contigs_file)
  
  contigs = Set.new
  markers.each do |k, marker|

    if marker.best_hit
      contigs << marker.best_hit.target_id
    end
  end
  
  fasta=File.open(contigs_file, "w")
    contigs.each do |contig_id|
         reg = @reference.index.region_for_entry(contig_id)
       fasta.puts ">#{contig_id}\n#{@reference.fetch_sequence(reg.get_full_region)}"
    end
  fasta.close
end


138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/bio/PolyploidTools/Marker.rb', line 138

def print_fasta_contigs_from_reference(filename)
  if File.exist?(filename) 
    reference(filename)
    return
  end

  #puts "loaded"

  fasta=File.open(filename, "w")

  Bio::FlatFile.auto( @global_reference.fasta_path) do |ff|
    ff.each do |f|
      chr_reg = arm_selection_embl(f.entry_id)
      if chr_reg == chromosome
        fasta.puts f.entry
      end
    end
  end
  fasta.close
  reference(filename)
end


118
119
120
121
122
123
124
125
126
# File 'lib/bio/PolyploidTools/Marker.rb', line 118

def print_fasta_markers(filename)
  @fasta_markers = filename
  fasta=File.open(filename, "w")

  markers.each do |k, marker|
    fasta.puts marker.to_fasta 
  end
  fasta.close
end


161
162
163
164
165
166
167
# File 'lib/bio/PolyploidTools/Marker.rb', line 161

def print_map_with_contigs(filename)
  file = File.open(filename, "w")
  markers.values.sort { |x,y| x.map_order <=> y.map_order }.each do | marker |
    file.puts marker.to_csv
  end 
  file.close
end