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

Conversation

Oddant1
Copy link
Member

@Oddant1 Oddant1 commented Jul 18, 2019

Addresses #198 at least for DNAFASTAFormat. After this is done, maybe I can make AlignedDNAFASTAFormat validate in a similar manner to DNAFASTAFormat. currently all this does is make a set of all encountered ids and raise a ValidationError if it finds any overlaps. This is basically the most basic initial implementation I could think of so we could potentially create a more robust implementation from here, some ideas for that.

  1. Keep track of the lines all the ids occur on so when and if you find a duplicate you can report the lines each of the duplicates came on not just the line the second one occurred on (this one seems like a good idea)
  2. Keep track of all lines all ids occur on and do not error out as soon as a duplicate is found. Instead wait until the validation completes (assuming it doesn't run into any other errors) and report any and all duplicates found while validating along with the lines they occurred on (this seems like overkill to me)

Thoughts?

Copy link
Contributor

@thermokarst thermokarst left a comment

Choose a reason for hiding this comment

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

Keep track of all lines all ids occur on and do not error out as soon as a duplicate is found. Instead wait until the validation completes (assuming it doesn't run into any other errors) and report any and all duplicates found while validating along with the lines they occurred on (this seems like overkill to me)

I am fine with not worrying about this for now, what is more important to the original issue is to get this behavior rolled into the aligned format, too.

q2_types/feature_data/_format.py Outdated Show resolved Hide resolved
q2_types/feature_data/_format.py Outdated Show resolved Hide resolved
q2_types/feature_data/_format.py Outdated Show resolved Hide resolved
@Oddant1 Oddant1 assigned thermokarst and unassigned Oddant1 Aug 8, 2019
@@ -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.

@thermokarst
Copy link
Contributor

LGTM, thanks @Oddant1! @ebolyen, reassigning to you in case you want to take a pass through the code. If not, please merge.

@thermokarst thermokarst assigned ebolyen and unassigned thermokarst Aug 16, 2019
Copy link
Member

@ebolyen ebolyen left a comment

Choose a reason for hiding this comment

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

Logic looks good to me, just some updates on the error text.

q2_types/feature_data/_format.py Outdated Show resolved Hide resolved
q2_types/feature_data/_format.py Outdated Show resolved Hide resolved
q2_types/feature_data/_format.py Outdated Show resolved Hide resolved
q2_types/feature_data/_format.py Show resolved Hide resolved
@thermokarst thermokarst merged commit e046b9a into qiime2:master Aug 21, 2019
@Oddant1 Oddant1 deleted the no-duplicate-fasta-records branch June 25, 2020 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants