lib/bio/fastqc/data.rb in bio-fastqc-0.8.0 vs lib/bio/fastqc/data.rb in bio-fastqc-0.8.2
- old
+ new
@@ -3,34 +3,39 @@
require 'zip'
module Bio
module FastQC
class Data
- class << self
- def read(file)
- read_zipfile(file)
- rescue Zip::Error
- read_flatfile(file)
+ class << self
+ def read(file)
+ read_zipfile(file)
+ rescue Zip::Error
+ read_flatfile(file)
rescue Errno::EISDIR
read_dir(file)
- end
+ end
- def read_zipfile(file)
- Zip::File.open(file) do |zipfile|
- zipfile.glob('*/fastqc_data.txt').first.get_input_stream.read
- end
- end
+ def read_zipfile(file)
+ Zip::File.open(file) do |zipfile|
+ d = zipfile.glob('*/fastqc_data.txt').first
+ filenotfound(file) if !d
+ d.get_input_stream.read
+ end
+ end
- def read_flatfile(file)
- open(file).read
- end
+ def read_flatfile(file)
+ open(file).read
+ end
- def read_dir(file)
- open(File.join(file, "fastqc_data.txt")).read
- rescue Errno::ENOENT
- puts "FastQC data file fastqc_data.txt not found"
- exit
- end
- end
- end
+ def read_dir(file)
+ open(File.join(file, "fastqc_data.txt")).read
+ rescue Errno::ENOENT
+ filenotfound(file)
+ end
+
+ def filenotfound(file)
+ raise "FastQC data file fastqc_data.txt not found, input file: #{file}"
+ end
+ end
+ end
end
end