lib/bio/PolyploidTools/ExonContainer.rb in bio-polyploid-tools-0.8.4 vs lib/bio/PolyploidTools/ExonContainer.rb in bio-polyploid-tools-0.8.5

- old
+ new

@@ -3,20 +3,21 @@ class ExonContainer attr_reader :parental_1_sam, :parental_2_sam attr_reader :parental_1_name, :parental_2_name, :gene_models_db attr_reader :chromosomes, :snp_map attr_reader :parents - attr_accessor :flanking_size , :primer_3_min_seq_length + attr_accessor :flanking_size , :primer_3_min_seq_length, :max_hits BASES = [:A, :C, :G, :T] #Sets the reference file for the gene models def initialize @parents=Hash.new @snp_map = Hash.new @snp_contigs @primer_3_min_seq_length = 50 + @max_hits = 10 end def gene_models(path) @gene_models_db = Bio::DB::Fasta::FastaFile.new({:fasta=>path}) @gene_models_db.index @@ -74,12 +75,15 @@ path = opts[:alig_path] chromosomes[name] = Bio::DB::Fasta::FastaFile.new({:fasta=>path}) end def add_snp(snp) + #TODO: add to the snp the maximum number of hits? + snp.max_hits = self.max_hits @snp_map[snp.gene] = Array.new unless @snp_map[snp.gene] @snp_map[snp.gene] << snp + end def add_snp_file(filename, chromosome, snp_in, original_name) File.open(filename) do | f | @@ -155,10 +159,11 @@ snp_array.each do |snp| string = "" begin primer_3_min_seq_length string = snp.primer_3_string( snp.chromosome, parental ) + #TODO: add tan error to the SNP this snp has more than max_hits. Or maybe inside the SNP file. #puts "print_primer_3_exons: #{string.size}" if string.size > 0 file.puts string added += 1 end @@ -203,9 +208,23 @@ $stderr.puts "Failed for the range #{record.query_start}-#{record.query_end} for position #{snp.position}" end end end end + end + end + end + remove_alignments_over_max_hits + end + + def remove_alignments_over_max_hits + @snp_map.each_pair do | gene, snp_array| + snp_array.each do |snp| + if snp.exon_list.size > max_hits + total_hits = snp.exon_list.size + snp.exon_list = {} + snp.repetitive = true + snp.errors << "The marker is in a repetitive region (#{total_hits} hits to reference)" end end end end \ No newline at end of file