Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,21 @@ pub fn load_gbassembly_info(input_csv: String) -> Result<(Vec<GBAssemblyData>, u
// Check column names
let header = rdr.headers()?;
let expected_header = vec!["accession", "name"];
if header != expected_header {
return Err(anyhow!(
"Invalid column names in CSV file. Columns should be: {:?}",
expected_header
));

for h in expected_header.iter() {
if !header.iter().any(|e| *h == e) {
return Err(anyhow!(
"Missing column name '{}' in CSV file. Columns should be: {:?}",
h,
expected_header
));
}
}

for h in header.iter() {
if !expected_header.iter().any(|e| h == *e) {
eprintln!("WARNING: extra column '{}' in CSV file. Ignoring.", h);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried this accepts input CSVs that contain all columns, but not in the right order. The input code currently uses column indexes, not column names, to read the CSV. This has been on my long list to improve, will make an issue for it now.

For this PR, we could just check for the full expected header first, then allow extra columns? Lmk if you want me to take this on.

}

for result in rdr.records() {
Expand Down
28 changes: 27 additions & 1 deletion tests/test_gbsketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,32 @@ def test_gbsketch_bad_acc(runtmp):
assert sig.md5sum() == ss3.md5sum()


def test_gbsketch_extra_column(runtmp, capfd):
acc_csv = get_test_data('acc.csv')
acc_mod = runtmp.output('acc_mod.csv')

with open(acc_csv, 'r') as inF, open(acc_mod, 'w') as outF:
lines = inF.readlines()
for line in lines:
outF.write(line.strip() + ',extra\n')

output = runtmp.output('simple.zip')
failed = runtmp.output('failed.csv')
ch_fail = runtmp.output('checksum_dl_failed.csv')

runtmp.sourmash('scripts', 'gbsketch', acc_mod, '-o', output,
'--failed', failed, '-r', '3', '--checksum-fail', ch_fail,
'--param-str', "dna,k=31,scaled=1000", '-p', "protein,k=10,scaled=200")

assert os.path.exists(output)
assert not runtmp.last_result.out # stdout should be empty
captured = capfd.readouterr()
print(captured.err)
print(f"looking for path: {output}")

assert "WARNING: extra column 'extra' in CSV file. Ignoring." in captured.err


def test_gbsketch_missing_accfile(runtmp, capfd):
acc_csv = runtmp.output('acc1.csv')
output = runtmp.output('simple.zip')
Expand Down Expand Up @@ -405,7 +431,7 @@ def test_gbsketch_empty_accfile(runtmp, capfd):

captured = capfd.readouterr()
print(captured.err)
assert 'Error: Invalid column names in CSV file. Columns should be: ["accession", "name"]' in captured.err
assert "Error: Missing column name 'accession' in CSV file." in captured.err


def test_gbsketch_bad_acc_fail(runtmp, capfd):
Expand Down
Loading