lib/iroki/biom.rb in iroki-0.0.19 vs lib/iroki/biom.rb in iroki-0.0.20
- old
+ new
@@ -14,10 +14,14 @@
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Iroki. If not, see <http://www.gnu.org/licenses/>.
+def count_or_rel_abund? str
+ str.match /\A[01]?.?[0-9]+\Z/
+end
+
module Iroki
class Biom < File
attr_accessor :single_group
def parse
@@ -29,15 +33,27 @@
self.each_line.with_index do |line, idx|
unless line.start_with? "#"
lineno += 1
sample, *the_counts = line.chomp.split "\t"
+ abort_if sample.nil? || sample.empty? || sample =~ / +/,
+ "Line #{idx+1} has no sample"
+
+ the_counts.flatten.each do |count|
+ abort_unless count_or_rel_abund?(count),
+ "The value '#{count}' in the biom file " +
+ "was not a count or relative abundance"
+ end
+
if lineno.zero?
first_line_count = the_counts.count
else
abort_unless first_line_count == the_counts.count,
- "The biom file has rows with different " +
- "numbers of columns"
+ "Line number #{idx+1} (#{line.inspect}) in the " +
+ "biom file has #{the_counts.count} " +
+ "columns when it should have " +
+ "#{first_line_count} columns like the " +
+ "first row does."
end
samples << sample
if the_counts.length == 1