2010-01-28 01:19:37 +08:00
|
|
|
package org.broadinstitute.sting.oneoffprojects.variantcontext;
|
|
|
|
|
|
|
|
|
|
import org.broadinstitute.sting.utils.GenomeLoc;
|
|
|
|
|
import org.broadinstitute.sting.utils.StingException;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-01-28 12:10:16 +08:00
|
|
|
* @author depristo
|
2010-01-28 01:19:37 +08:00
|
|
|
* <p/>
|
2010-01-28 12:10:16 +08:00
|
|
|
* Class AttributedObject
|
2010-01-28 01:19:37 +08:00
|
|
|
* <p/>
|
2010-01-28 12:10:16 +08:00
|
|
|
* Common functions in VariantContext
|
2010-01-28 01:19:37 +08:00
|
|
|
*/
|
|
|
|
|
public class AttributedObject {
|
2010-01-28 12:10:16 +08:00
|
|
|
public static final double NO_NEG_LOG_10PERROR = 0.0;
|
|
|
|
|
private double negLog10PError = NO_NEG_LOG_10PERROR;
|
2010-02-02 01:49:51 +08:00
|
|
|
private Set<Object> filters = new HashSet<Object>();
|
2010-01-28 12:10:16 +08:00
|
|
|
|
2010-01-28 01:19:37 +08:00
|
|
|
private Map<Object, Object> attributes = new HashMap<Object, Object>();
|
|
|
|
|
|
2010-01-28 12:10:16 +08:00
|
|
|
public AttributedObject() { }
|
|
|
|
|
|
|
|
|
|
public AttributedObject(double negLog10PError) {
|
|
|
|
|
setNegLog10PError(negLog10PError);
|
2010-01-28 01:19:37 +08:00
|
|
|
}
|
|
|
|
|
|
2010-01-28 12:10:16 +08:00
|
|
|
public AttributedObject(Map<? extends Object, ? extends Object> attributes) {
|
2010-01-28 01:19:37 +08:00
|
|
|
setAttributes(attributes);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-28 12:10:16 +08:00
|
|
|
public AttributedObject(Map<? extends Object, ? extends Object> attributes, double negLog10PError) {
|
|
|
|
|
this(attributes);
|
|
|
|
|
|
|
|
|
|
setNegLog10PError(negLog10PError);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-02-02 01:49:51 +08:00
|
|
|
// ---------------------------------------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filter
|
|
|
|
|
//
|
|
|
|
|
// ---------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
public Set<Object> getFilters() {
|
|
|
|
|
return filters;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isFiltered() {
|
|
|
|
|
return filters.size() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isNotFiltered() {
|
|
|
|
|
return ! isFiltered();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addFilter(Object filter) {
|
|
|
|
|
if ( filter == null ) throw new IllegalArgumentException("BUG: Attempting to add null filter " + this);
|
|
|
|
|
if ( getFilters().contains(filter) ) throw new IllegalArgumentException("BUG: Attempting to add duplicate filter " + filter + " at " + this);
|
|
|
|
|
filters.add(filter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addFilters(Collection<? extends Object> filters) {
|
|
|
|
|
if ( filters == null ) throw new IllegalArgumentException("BUG: Attempting to add null filters at" + this);
|
|
|
|
|
for ( Object f : filters )
|
|
|
|
|
addFilter(f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void clearFilters() {
|
|
|
|
|
filters.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setFilters(Collection<? extends Object> filters) {
|
|
|
|
|
clearFilters();
|
|
|
|
|
addFilters(filters);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-28 12:10:16 +08:00
|
|
|
// ---------------------------------------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Working with log error rates
|
|
|
|
|
//
|
|
|
|
|
// ---------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
public boolean hasNegLog10PError() {
|
|
|
|
|
return getNegLog10PError() == NO_NEG_LOG_10PERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the -1 * log10-based error estimate
|
|
|
|
|
*/
|
|
|
|
|
public double getNegLog10PError() { return negLog10PError; }
|
|
|
|
|
|
|
|
|
|
public void setNegLog10PError(double negLog10PError) {
|
|
|
|
|
if ( negLog10PError < 0 && negLog10PError != NO_NEG_LOG_10PERROR ) throw new IllegalArgumentException("BUG: negLog10PError cannot be < than 0 : " + negLog10PError);
|
|
|
|
|
if ( Double.isInfinite(negLog10PError) ) throw new IllegalArgumentException("BUG: negLog10PError should not be Infinity");
|
|
|
|
|
if ( Double.isNaN(negLog10PError) ) throw new IllegalArgumentException("BUG: negLog10PError should not be NaN");
|
|
|
|
|
|
|
|
|
|
this.negLog10PError = negLog10PError;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-28 01:19:37 +08:00
|
|
|
// ---------------------------------------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Working with attributes
|
|
|
|
|
//
|
|
|
|
|
// ---------------------------------------------------------------------------------------------------------
|
|
|
|
|
public void clearAttributes() {
|
|
|
|
|
this.attributes.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the attribute map
|
|
|
|
|
*/
|
|
|
|
|
public Map<Object, Object> getAttributes() {
|
|
|
|
|
return attributes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// todo -- define common attributes as enum
|
|
|
|
|
|
2010-01-28 12:10:16 +08:00
|
|
|
public void setAttributes(Map<? extends Object, ? extends Object> map) {
|
2010-01-28 01:19:37 +08:00
|
|
|
this.attributes.clear();
|
2010-01-28 12:10:16 +08:00
|
|
|
putAttributes(map);
|
2010-01-28 01:19:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void putAttribute(Object key, Object value) {
|
|
|
|
|
putAttribute(key, value, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void putAttribute(Object key, Object value, boolean allowOverwrites) {
|
|
|
|
|
if ( hasAttribute(key) && ! allowOverwrites )
|
|
|
|
|
throw new StingException("Attempting to overwrite key->value binding: key = " + key + " this = " + this);
|
|
|
|
|
|
|
|
|
|
this.attributes.put(key, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removeAttribute(Object key) {
|
|
|
|
|
this.attributes.remove(key);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-28 12:10:16 +08:00
|
|
|
public void putAttributes(Map<? extends Object, ? extends Object> map) {
|
|
|
|
|
if ( map != null ) {
|
|
|
|
|
for ( Map.Entry<? extends Object, ? extends Object> elt : map.entrySet() ) {
|
|
|
|
|
putAttribute(elt.getKey(), elt.getValue());
|
|
|
|
|
}
|
2010-01-28 01:19:37 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean hasAttribute(Object key) {
|
|
|
|
|
return attributes.containsKey(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNumAttributes() {
|
|
|
|
|
return attributes.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param key the attribute key
|
|
|
|
|
*
|
|
|
|
|
* @return the attribute value for the given key (or null if not set)
|
|
|
|
|
*/
|
|
|
|
|
public Object getAttribute(Object key) {
|
|
|
|
|
return attributes.get(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Object getAttribute(Object key, Object defaultValue) {
|
|
|
|
|
if ( hasAttribute(key) )
|
|
|
|
|
return attributes.get(key);
|
|
|
|
|
else
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AttributedObject getAttributes(Collection<Object> keys) {
|
|
|
|
|
AttributedObject selected = new AttributedObject();
|
|
|
|
|
|
|
|
|
|
for ( Object key : keys )
|
|
|
|
|
selected.putAttribute(key, this.getAttribute(key));
|
|
|
|
|
|
|
|
|
|
return selected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getAttributeAsString(Object key) { return (String)getAttribute(key); }
|
|
|
|
|
public int getAttributeAsInt(Object key) { return (Integer)getAttribute(key); }
|
|
|
|
|
public double getAttributeAsDouble(Object key) { return (Double)getAttribute(key); }
|
|
|
|
|
|
|
|
|
|
public String getAttributeAsString(Object key, String defaultValue) { return (String)getAttribute(key, defaultValue); }
|
|
|
|
|
public int getAttributeAsInt(Object key, int defaultValue) { return (Integer)getAttribute(key, defaultValue); }
|
|
|
|
|
public double getAttributeAsDouble(Object key, double defaultValue) { return (Double)getAttribute(key, defaultValue); }
|
|
|
|
|
}
|