Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMP: Do no allow duplicate records in DNAFASTAFormat #220

Merged
merged 4 commits into from
Aug 21, 2019
Merged
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions q2_types/feature_data/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class DNAFASTAFormat(model.TextFileFormat):
def _validate_lines(self, max_lines):
FASTADNAValidator = re.compile(r'[ACGTURYKMSWBDHVN]+\r?\n?')
last_line_was_ID = False
ids = set()
Oddant1 marked this conversation as resolved.
Show resolved Hide resolved

with open(str(self), 'rb') as fh:
try:
Expand All @@ -161,6 +162,11 @@ def _validate_lines(self, max_lines):
raise ValidationError('Multiple consecutive IDs '
'starting on line '
f'{line_number-1!r}')
if line in ids:
Copy link
Contributor

Choose a reason for hiding this comment

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

One problem with this is that it treats the entire header line as the ID. I believe that we need to treat everything between the > and the first instance of whitespace ( , if any) as the ID. Characters after the space are part of the record's description field, and are not subject to the ID uniqueness rules.

@ebolyen, can you please confirm this for me?

Copy link
Member

Choose a reason for hiding this comment

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

Yep, that is correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @ebolyen! @Oddant1, now would be a good time to fix the error message on https://github.com/qiime2/q2-types/pull/220/files#diff-c7c5016b403f1d6d2fb45764b58ae9d6R153 to indicate this situation, too (technically the ID doesn't start with >, the refline for the record starts with >.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are they allowed to have a space immediately after the >? We don't currently check for that at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the most comprehensive resource is here:

http://scikit-bio.org/docs/0.5.5/generated/skbio.io.format.fasta.html#module-skbio.io.format.fasta

Have fun... 🎉

Copy link
Member Author

@Oddant1 Oddant1 Aug 8, 2019

Choose a reason for hiding this comment

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

I guess if they had a space immediately after the > their id would start with a space and that would be silly, so I suppose they can't do that. That seems to be what that format definition implies.

Copy link
Member

Choose a reason for hiding this comment

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

I would probably interpret it as a "null" ID, but in any case, that is almost certainly a formatting error and we should probably avoid accepting it.

raise ValidationError(f'Id on line {line_number} '
Oddant1 marked this conversation as resolved.
Show resolved Hide resolved
'is a duplicate of another '
'id.')
Oddant1 marked this conversation as resolved.
Show resolved Hide resolved
ids.add(line)
last_line_was_ID = True
elif re.fullmatch(FASTADNAValidator, line):
last_line_was_ID = False
Expand Down