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

improve gff: add Locatable to Gff3BaseData, add 'Optional<String> getAttr(key)' and 'hasAttribute' #1726

Merged
merged 3 commits into from
Oct 29, 2024

Conversation

lindenb
Copy link
Contributor

@lindenb lindenb commented Oct 29, 2024

Description

This PR improves the GFF3 classes:

  • 99% the interesting attributes in a GFF3 file are unique (for example gene_biotype, gene_name, etc...) , so using the function List<String> getAttribute(key) can be cumbersome. This PR adds a new function Optional<String> getAttr(key) , it returns an Optional if there is zero or one value. Otherwise an exception is thrown.
  • I also added a function hasAttribute to test for the presence of an attribute.
  • add implements Locatable to Gff3BaseData

Things to think about before submitting:

  • Make sure your changes compile and new tests pass locally.
  • Add new tests or update existing ones:
    • A bug fix should include a test that previously would have failed and passes now.
    • New features should come with new tests that exercise and validate the new functionality.
  • Extended the README / documentation, if necessary
  • Check your code style.
  • Write a clear commit title and message
    • The commit message should describe what changed and is targeted at htsjdk developers
    • Breaking changes should be mentioned in the commit message.

@lindenb lindenb marked this pull request as ready for review October 29, 2024 11:33
@lindenb lindenb changed the title improve gff: add Locatable to Gff3BaseData, add 'Optional<String> getAttr(key)' and 'hasAtt' improve gff: add Locatable to Gff3BaseData, add 'Optional<String> getAttr(key)' and 'hasAttribute' Oct 29, 2024
Copy link
Member

@lbergelson lbergelson left a comment

Choose a reason for hiding this comment

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

@lindenb This seems like a good idea but can we change the method name? getAttr and getAttribute are to confusing together. Something like getSingleAttribute() might be clearer?

* @return <tt>Optional&lt;String&gt;</tt> if this map contains zero or one attribute for the specified key
* @throws IllegalArgumentException if there is more than one value
*/
public Optional<String> getAttr(final String key) {
Copy link
Member

Choose a reason for hiding this comment

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

I like this idea. Can we change the name though? Maybe getSingleAttribute()?

@lbergelson
Copy link
Member

or getUniqueAttribute()

@lindenb
Copy link
Contributor Author

lindenb commented Oct 29, 2024

@lbergelson thanks for the review ! I changed the name to getUniqueAttribute

Copy link
Member

@lbergelson lbergelson left a comment

Choose a reason for hiding this comment

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

👍

@lbergelson lbergelson merged commit dbebac3 into samtools:master Oct 29, 2024
4 checks passed
@lbergelson
Copy link
Member

Thanks for all these additions @lindenb

@lindenb lindenb deleted the pl_gtf_att branch October 29, 2024 19:24
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.

2 participants