From 54603568acab5d6f0ada03fc693235b8071107fb Mon Sep 17 00:00:00 2001 From: martinahansen Date: Sat, 28 May 2011 21:24:18 +0000 Subject: [PATCH] added multithreading to find_adaptor git-svn-id: http://biopieces.googlecode.com/svn/trunk@1438 74ccb610-7750-0410-82ae-013aeee3265d --- bp_bin/find_adaptor | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/bp_bin/find_adaptor b/bp_bin/find_adaptor index 78e633a..85377e4 100755 --- a/bp_bin/find_adaptor +++ b/bp_bin/find_adaptor @@ -37,10 +37,9 @@ require 'maasha/fasta' class PatScanError < StandardError; end; class PatScan - def initialize(options, tmpdir, file_pattern, file_patscan, cpus) + def initialize(options, tmpdir, file_pattern, cpus) @options = options @file_pattern = file_pattern - @file_patscan = file_patscan @cpus = cpus @files_fasta = Dir.glob(File.join(tmpdir, "*.fna")) @@ -110,17 +109,21 @@ class PatScan end def parse_results + files_result = Dir.glob(File.join(tmpdir, "*.out")) + matches = {} - Fasta.open(@file_patscan, mode='r') do |ios| - ios.each do |entry| - if entry.seq_name =~ /^(\d+):\[(\d+),(\d+)\]$/ - name = $1.to_i - start = $2.to_i - 1 - stop = $3.to_i - 1 - matches[name] = [start, stop - start + 1] unless matches.has_key? name - else - raise "Failed to parse sequence name: #{entry.seq_name}" + files_result.each do |file| + Fasta.open(file, mode='r') do |ios| + ios.each do |entry| + if entry.seq_name =~ /^(\d+):\[(\d+),(\d+)\]$/ + name = $1.to_i + start = $2.to_i - 1 + stop = $3.to_i - 1 + matches[name] = [start, stop - start + 1] unless matches.has_key? name + else + raise "Failed to parse sequence name: #{entry.seq_name}" + end end end end @@ -217,7 +220,6 @@ options = Biopieces.options_parse(ARGV, casts) tmpdir = "Tyt" # DEBUG TODO file_records = File.join(tmpdir, "data.stream") file_pattern = File.join(tmpdir, "pattern.txt") -file_patscan = File.join(tmpdir, "patscan.out") number_file = 0 number_seq = 0 @@ -250,9 +252,8 @@ Biopieces.open(options[:stream_in], file_records) do |input, output| out_fa.close if out_fa.respond_to? :close end -patscan = PatScan.new(options, tmpdir, file_pattern, file_patscan, options[:cpus]) +patscan = PatScan.new(options, tmpdir, file_pattern, options[:cpus]) patscan.run -exit matches = patscan.parse_results number_seq = 0 -- 2.39.2