2011-07-26 23:09:06 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011, The Broad Institute
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
|
* restriction, including without limitation the rights to use,
|
|
|
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following
|
|
|
|
|
* conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package org.broadinstitute.sting.commandline;
|
|
|
|
|
|
2011-07-29 02:19:27 +08:00
|
|
|
import org.broad.tribble.Feature;
|
2011-07-26 23:09:06 +08:00
|
|
|
|
2011-08-03 10:00:06 +08:00
|
|
|
import java.util.*;
|
2011-07-26 23:09:06 +08:00
|
|
|
|
|
|
|
|
/**
|
2011-07-28 12:16:34 +08:00
|
|
|
* A RodBinding representing a walker argument that gets bound to a ROD track.
|
2011-07-26 23:09:06 +08:00
|
|
|
*
|
2011-07-28 12:16:34 +08:00
|
|
|
* There is no constraint on the type of the ROD bound.
|
2011-07-26 23:09:06 +08:00
|
|
|
*/
|
2011-07-29 02:19:27 +08:00
|
|
|
public class RodBinding<T extends Feature> {
|
2011-08-03 10:00:06 +08:00
|
|
|
protected final static String UNBOUND_VARIABLE_NAME = "";
|
|
|
|
|
protected final static String UNBOUND_SOURCE = "UNBOUND";
|
|
|
|
|
protected final static String UNBOUND_TRIBBLE_TYPE = null;
|
2011-08-03 08:28:47 +08:00
|
|
|
public final static <T extends Feature> RodBinding<T> makeUnbound(Class<T> type) {
|
|
|
|
|
return new RodBinding<T>(type);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-03 10:00:06 +08:00
|
|
|
final private String name;
|
2011-08-03 08:11:24 +08:00
|
|
|
final private String source;
|
2011-08-03 10:00:06 +08:00
|
|
|
final private String tribbleType;
|
2011-08-03 08:11:24 +08:00
|
|
|
final private Tags tags;
|
|
|
|
|
final private Class<T> type;
|
2011-08-03 08:28:47 +08:00
|
|
|
final private boolean bound;
|
2011-08-03 08:11:24 +08:00
|
|
|
|
2011-08-03 10:00:06 +08:00
|
|
|
final private static Map<String, Integer> nameCounter = new HashMap<String, Integer>();
|
|
|
|
|
|
|
|
|
|
final protected static void resetNameCounter() {
|
|
|
|
|
nameCounter.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final private static synchronized String countedVariableName(final String rawName) {
|
|
|
|
|
Integer count = nameCounter.get(rawName);
|
|
|
|
|
if ( count == null ) {
|
|
|
|
|
nameCounter.put(rawName, 1);
|
|
|
|
|
return rawName;
|
|
|
|
|
} else {
|
|
|
|
|
nameCounter.put(rawName, count + 1);
|
|
|
|
|
return rawName + (count + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-03 08:11:24 +08:00
|
|
|
public boolean isBound() {
|
2011-08-03 08:28:47 +08:00
|
|
|
return bound;
|
2011-08-03 08:11:24 +08:00
|
|
|
}
|
2011-07-26 23:09:06 +08:00
|
|
|
|
2011-08-03 10:00:06 +08:00
|
|
|
public RodBinding(Class<T> type, final String rawName, final String source, final String tribbleType, final Tags tags) {
|
2011-07-29 02:19:27 +08:00
|
|
|
this.type = type;
|
2011-08-03 10:00:06 +08:00
|
|
|
this.name = countedVariableName(rawName);
|
2011-07-27 01:59:44 +08:00
|
|
|
this.source = source;
|
2011-08-03 10:00:06 +08:00
|
|
|
this.tribbleType = tribbleType;
|
2011-07-30 02:37:12 +08:00
|
|
|
this.tags = tags;
|
2011-08-03 08:28:47 +08:00
|
|
|
this.bound = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make an unbound RodBinding<T>
|
|
|
|
|
* @param type
|
|
|
|
|
*/
|
|
|
|
|
private RodBinding(Class<T> type) {
|
|
|
|
|
this.type = type;
|
2011-08-03 10:00:06 +08:00
|
|
|
this.name = UNBOUND_VARIABLE_NAME; // special value can never be found in RefMetaDataTracker
|
|
|
|
|
this.source = UNBOUND_SOURCE;
|
|
|
|
|
this.tribbleType = UNBOUND_TRIBBLE_TYPE;
|
2011-08-03 08:28:47 +08:00
|
|
|
this.tags = new Tags();
|
|
|
|
|
this.bound = false;
|
2011-07-26 23:09:06 +08:00
|
|
|
}
|
|
|
|
|
|
2011-08-03 10:00:06 +08:00
|
|
|
public String getName() {
|
|
|
|
|
return name;
|
2011-07-26 23:09:06 +08:00
|
|
|
}
|
2011-07-31 03:34:11 +08:00
|
|
|
public Class<T> getType() {
|
|
|
|
|
return type;
|
|
|
|
|
}
|
2011-07-27 01:59:44 +08:00
|
|
|
public String getSource() {
|
|
|
|
|
return source;
|
2011-07-26 23:09:06 +08:00
|
|
|
}
|
|
|
|
|
|
2011-07-27 23:36:53 +08:00
|
|
|
public Tags getTags() {
|
2011-07-30 02:37:12 +08:00
|
|
|
return tags;
|
2011-07-27 23:36:53 +08:00
|
|
|
}
|
|
|
|
|
|
2011-08-03 10:00:06 +08:00
|
|
|
public String getTribbleType() {
|
|
|
|
|
return tribbleType;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-26 23:37:31 +08:00
|
|
|
public String toString() {
|
2011-08-03 10:00:06 +08:00
|
|
|
return String.format("(RodBinding name=%s source=%s)", getName(), getSource());
|
2011-07-26 23:09:06 +08:00
|
|
|
}
|
|
|
|
|
}
|