Skip to content

Commit

Permalink
Report error if all columns get removed
Browse files Browse the repository at this point in the history
  • Loading branch information
martinghunt committed Apr 28, 2016
1 parent 3fe8933 commit 4f0caff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions ariba/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def _gather_output_rows(self):

@classmethod
def _filter_clusters(cls, rows):
'''Removes any cluster where every sample has assembled == "no"'''
'''Removes any cluster where every sample has assembled == "no".
Returns tuple: (filtered rows, number of remaining columns)'''
found_a_yes = set()
first_filename = True
all_clusters = set()
Expand All @@ -131,7 +132,6 @@ def _filter_clusters(cls, rows):

if rows[filename][cluster]['assembled'] == 'yes':
found_a_yes.add(cluster)
break

first_filename = False

Expand All @@ -141,7 +141,7 @@ def _filter_clusters(cls, rows):
for cluster in to_delete:
del rows[filename][cluster]

return rows
return rows, len(found_a_yes)


@classmethod
Expand Down Expand Up @@ -253,6 +253,11 @@ def run(self):
self._check_files_exist()
self.samples = self._load_input_files(self.filenames, self.min_id)
self.rows = self._gather_output_rows()
self.rows, remaining_clusters = Summary._filter_clusters(self.rows)
if remaining_clusters == 0:
print('No clusters found that are present in any sample. Will not write any output files', file=sys.stderr)
sys.exit(1)

Summary._write_csv(self.filenames, self.rows, self.outprefix + '.csv', phandango=False)

if len(self.samples) > 1:
Expand Down
2 changes: 1 addition & 1 deletion ariba/tests/summary_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_filter_clusters(self):
}

got = summary.Summary._filter_clusters(rows)
self.assertEqual(expected, got)
self.assertEqual((expected, 3), got)


def test_write_csv(self):
Expand Down

0 comments on commit 4f0caff

Please sign in to comment.