-
Notifications
You must be signed in to change notification settings - Fork 242
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
Why are Genotype.getAttributeAsX methods deprecated? #866
Comments
pinging @tfenne...do you know?
…On Thu, Apr 27, 2017 at 3:22 PM, Louis Bergelson ***@***.***> wrote:
There are a number of deprecated methods in Genotype that seem useful.
There's no explanation why they're deprecated or what the replacement is.
ex:
@deprecated
public int getAttributeAsInt(String key, int defaultValue) {
Object x = getExtendedAttribute(key);
if ( x == null || x == VCFConstants.MISSING_VALUE_v4 ) return defaultValue;
if ( x instanceof Integer ) return (Integer)x;
return Integer.valueOf((String)x); // throws an exception if this isn't a string
}
Is there something wrong with these methods? Is there a replacement
somewhere? There are analogous methods in VariantContext that are not
deprecated. They were deprecated before being moved into htsjdk so the
history is cut off. Does anyone know?
They seem like necessary functionality, maybe we should dedeprecate them?
(and possibly refactor so there isn't duplicated code between them and the
same methods in CommonInfo
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#866>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACnk0s8Atc8Tclvtv2lufvaemolGE_Q3ks5r0OsPgaJpZM4NKqKQ>
.
|
I was wondering the same. What'as about having a |
@yfarjoun I have no idea. I think that in general it would be really nice to make both Genotype and VariantContext a bit more type-safe, whether it's by un-deprecating these methods, or removing these methods and putting something similar in place. I still struggle when dealing with both
Since there's usually sufficient information in the header to know the types of things a-priori, I'd love to see us refactor to a model where for declared INFO/FORMAT attributes we enforce the correct type during I'm totally willing to chip in on the effort here - if others are on a similar page perhaps we can use this issue to write up what we'd like the interface to Genotype to be and then work towards it there, and have VariantContext follow suit? |
I would love to make this type safe. We have so much confusing defensive code and it always misses cases anyway resulting in bugs. I have some thoughts about how this could be cleaned up a bit: We could define a set of Accessor interfaces which would capture the type information. ex: public interface AttributeAccessor<T> {
T convert(Object attribute); //each accessor would provide a method that does whatever conversion it needs
String getKey(); // we'd keep the underlying map so we need the keys
}
//specializations could fill in the convert method allowing new accessors to be defined as lambdas
public interface IntAccessor extends AttributeAccessor<Integer> {
@Override
default Integer convert(Object a) {
return Integer.parseInt(a.toString()); //gross accessor that handles string/int/etc badly, we'd want to do something better here if we can't rely on sanitized input, or just a cast here if we can.
}
}
//example accessor for MIN_DP, easy to define, put these someplace public like VCFConstants
private static final IntAccessor MIN_DP = () -> "MIN_DP";
access is simple:
This doesn't solve the important "loading from vcf" issue, but we could at least standardize the defensive code in the accessors. It would be best to fix the problem on the loading side as well, since as you say there's header information available. |
@lbergelson (related idea) can we also use VCFHeaderLineType to define some String converters ?
|
I like the
With this, we will be able to use type-safe and header lines for attributes. What do you think? |
I'm not sure binding the converter to the VCFHeaderLineType is sufficient, you also need to consider the VCFHeaderLineCount to determine if it's a list or a scalar. I.e. We have to consider the performance impact / where we want validation failures to occur. It seems likely that it would be more efficient to only perform conversion/type validation, when accessing an attribute, since many operations access only a subset of the attributes. |
What I meant is that the |
In addition, I think that this will be also another interesting point supporting the non-backwards API changes (#520), including the addition of a new variant and "genotype" interface (I dislike the |
There are a number of deprecated methods in
Genotype
that seem useful. There's no explanation why they're deprecated or what the replacement is.ex:
Is there something wrong with these methods? Is there a replacement somewhere? There are analogous methods in
VariantContext
that are not deprecated. They were deprecated before being moved into htsjdk so the history is cut off. Does anyone know?They seem like necessary functionality, maybe we should dedeprecate them? (and possibly refactor so there isn't duplicated code between them and the same methods in
CommonInfo
The text was updated successfully, but these errors were encountered: