2009-04-04 03:54:54 +08:00
|
|
|
package org.broadinstitute.sting.gatk.refdata;
|
|
|
|
|
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
2009-07-21 08:55:52 +08:00
|
|
|
import java.util.HashMap;
|
2009-04-04 03:54:54 +08:00
|
|
|
|
|
|
|
|
/**
|
2009-04-10 06:04:59 +08:00
|
|
|
* This class represents the Reference Metadata available at a particular site in the genome. It can be
|
|
|
|
|
* used to conveniently lookup the RODs at this site, as well just getting a list of all of the RODs
|
|
|
|
|
*
|
|
|
|
|
* The standard interaction model is:
|
|
|
|
|
*
|
|
|
|
|
* Traversal system arrives at a site, which has a bunch of rods covering it
|
|
|
|
|
* Traversal calls tracker.bind(name, rod) for each rod in rods
|
|
|
|
|
* Traversal passes tracker to the walker
|
|
|
|
|
* walker calls lookup(name, default) to obtain the rod values at this site, or default if none was
|
|
|
|
|
* bound at this site.
|
|
|
|
|
*
|
2009-04-04 03:54:54 +08:00
|
|
|
* User: mdepristo
|
|
|
|
|
* Date: Apr 3, 2009
|
|
|
|
|
* Time: 3:05:23 PM
|
|
|
|
|
*/
|
|
|
|
|
public class RefMetaDataTracker {
|
|
|
|
|
final HashMap<String, ReferenceOrderedDatum> map = new HashMap<String, ReferenceOrderedDatum>();
|
|
|
|
|
protected static Logger logger = Logger.getLogger(RefMetaDataTracker.class);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Finds the reference meta data named name, if it exists, otherwise returns the defaultValue
|
|
|
|
|
*
|
|
|
|
|
* @param name
|
|
|
|
|
* @param defaultValue
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public ReferenceOrderedDatum lookup(final String name, ReferenceOrderedDatum defaultValue) {
|
|
|
|
|
//logger.debug(String.format("Lookup %s%n", name));
|
2009-04-10 06:04:59 +08:00
|
|
|
final String luName = canonicalName(name);
|
|
|
|
|
if ( map.containsKey(luName) )
|
|
|
|
|
return map.get(luName);
|
2009-04-04 03:54:54 +08:00
|
|
|
else
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-10 06:04:59 +08:00
|
|
|
/**
|
|
|
|
|
* @see this.lookup
|
|
|
|
|
* @param name
|
|
|
|
|
* @param defaultValue
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2009-04-04 03:54:54 +08:00
|
|
|
public Object lookup(final String name, Object defaultValue) {
|
2009-04-10 06:04:59 +08:00
|
|
|
final String luName = canonicalName(name);
|
|
|
|
|
if ( map.containsKey(luName) )
|
|
|
|
|
return map.get(luName);
|
2009-04-04 03:54:54 +08:00
|
|
|
else
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-10 06:04:59 +08:00
|
|
|
/**
|
|
|
|
|
* Returns the canonical name of the rod name
|
|
|
|
|
* @param name
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private final String canonicalName(final String name)
|
|
|
|
|
{
|
2009-05-28 06:02:24 +08:00
|
|
|
//return name; // .toLowerCase();
|
2009-04-10 06:04:59 +08:00
|
|
|
return name.toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Is there a binding at this site to a ROD with name?
|
|
|
|
|
*
|
2009-07-21 08:55:52 +08:00
|
|
|
* @param name the name of the rod
|
|
|
|
|
* @return true if it has the rod
|
2009-04-10 06:04:59 +08:00
|
|
|
*/
|
2009-07-21 08:55:52 +08:00
|
|
|
public boolean hasROD(final String name) {
|
2009-04-10 06:04:59 +08:00
|
|
|
return map.containsKey(canonicalName(name));
|
2009-04-04 03:54:54 +08:00
|
|
|
}
|
|
|
|
|
|
2009-04-10 06:04:59 +08:00
|
|
|
/**
|
|
|
|
|
* Get all of the RODs at the current site
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2009-04-04 03:54:54 +08:00
|
|
|
public Collection<ReferenceOrderedDatum> getAllRods() {
|
|
|
|
|
return map.values();
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-10 06:04:59 +08:00
|
|
|
/**
|
|
|
|
|
* Binds the reference ordered datum ROD to name at this site. Should be used only but the traversal
|
|
|
|
|
* system to provide access to RODs in a structured way to the walkers.
|
|
|
|
|
*
|
|
|
|
|
* @param name
|
|
|
|
|
* @param rod
|
|
|
|
|
*/
|
2009-04-04 03:54:54 +08:00
|
|
|
public void bind(final String name, ReferenceOrderedDatum rod) {
|
2009-06-06 07:34:37 +08:00
|
|
|
//logger.debug(String.format("Binding %s to %s", name, rod));
|
2009-04-10 06:04:59 +08:00
|
|
|
map.put(canonicalName(name), rod);
|
2009-04-04 03:54:54 +08:00
|
|
|
}
|
|
|
|
|
}
|