bin/homokaryot_primers.rb in bio-polyploid-tools-0.4.5 vs bin/homokaryot_primers.rb in bio-polyploid-tools-0.4.6

- old
+ new

@@ -19,18 +19,26 @@ def add_snp_file(filename, chromosome, snp_in, original_name) flanking_size = 100 File.open(filename) do | f | f.each_line do | line | + if ARGV.size == 1 #List with Sequence + snp = Bio::PolyploidTools::SNPSequence.parse(line) + snp.use_reference = false + elsif ARGV.size == 2 #List and fasta file snp = Bio::PolyploidTools::SNP.parse(line) + snp.use_reference = true + end + #snp = Bio::PolyploidTools::SNP.parse(line) + # puts snp.gene snp.flanking_size = flanking_size if snp.position > 0 snp.container = self snp.chromosome = chromosome snp.snp_in = snp_in snp.original_name = original_name - snp.use_reference = true + snp.container = self @snp_map[snp.gene] = Array.new unless @snp_map[snp.gene] @snp_map[snp.gene] << snp end end @@ -93,10 +101,11 @@ f.each_line do | line | # p line.chomp! snp = nil if ARGV.size == 1 #List with Sequence snp = Bio::PolyploidTools::SNPSequence.parse(line) + elsif ARGV.size == 2 #List and fasta file snp = Bio::PolyploidTools::SNP.parse(line) region = fasta_reference_db.index.region_for_entry(snp.gene).get_full_region snp.template_sequence = fasta_reference_db.fetch_sequence(region) else @@ -110,16 +119,35 @@ raise Bio::DB::Exonerate::ExonerateException.new "All the snps should come from the same chromosome" if chromosome != snp.chromosome end end +output_folder="#{snp_file}_primer_design_#{Time.now.strftime('%Y%m%d-%H%M%S')}/" +Dir.mkdir(output_folder) +seqs_file= output_folder + "sequences.fa" +written_seqs = Set.new +reference_file = seqs_file unless reference_file + + +file = File.open(seqs_file, "w") +snps.each do |snp| + unless written_seqs.include?(snp.gene) + written_seqs << snp.gene + file.puts snp.to_fasta + end +end +file.close + + container = HomokaryotContainer.new container.add_parental({:name=>snp_in}) container.add_parental({:name=>original_name}) -container.gene_models(reference_file) +container.gene_models(reference_file) if reference_file -output_folder="#{snp_file}_primer_design_#{Time.now.strftime('%Y%m%d-%H%M%S')}/" -Dir.mkdir(output_folder) + + + + primer_3_input="#{output_folder}primer_3_input_temp" primer_3_output="#{output_folder}primer_3_output_temp" container.add_snp_file(snp_file, "PST130", snp_in, original_name) primer_3_config=File.expand_path(File.dirname(__FILE__) + '/../conf/primer3_config') output_primers="#{output_folder}primers.csv" \ No newline at end of file