Now only prints 1 warning message about duplicate headers in simpleMerge
This commit is contained in:
parent
61633c95a8
commit
3b09d42ed6
|
|
@ -116,10 +116,26 @@ public class VCFUtils {
|
|||
return fields;
|
||||
}
|
||||
|
||||
|
||||
/** Only displays a warning if a logger is provided and an identical warning hasn't been already issued */
|
||||
private static final class HeaderConflictWarner {
|
||||
Logger logger;
|
||||
Set<String> alreadyIssued = new HashSet<String>();
|
||||
|
||||
private HeaderConflictWarner(final Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public void warn(final VCFHeaderLine line, final String msg) {
|
||||
if ( logger != null && ! alreadyIssued.contains(line.getKey()) ) {
|
||||
alreadyIssued.add(line.getKey());
|
||||
logger.warn(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<VCFHeaderLine> smartMergeHeaders(Collection<VCFHeader> headers, Logger logger) throws IllegalStateException {
|
||||
HashMap<String, VCFHeaderLine> map = new HashMap<String, VCFHeaderLine>(); // from KEY.NAME -> line
|
||||
HeaderConflictWarner conflictWarner = new HeaderConflictWarner(logger);
|
||||
|
||||
// todo -- needs to remove all version headers from sources and add its own VCF version line
|
||||
for ( VCFHeader source : headers ) {
|
||||
|
|
@ -152,24 +168,24 @@ public class VCFUtils {
|
|||
// number, then this value should be 1. However, if the INFO field describes a pair
|
||||
// of numbers, then this value should be 2 and so on. If the number of possible
|
||||
// values varies, is unknown, or is unbounded, then this value should be '.'.
|
||||
if ( logger != null ) logger.warn("Promoting header field Number to . due to number differences in header lines: " + line + " " + other);
|
||||
conflictWarner.warn(line, "Promoting header field Number to . due to number differences in header lines: " + line + " " + other);
|
||||
compOther.setNumberToUnbounded();
|
||||
} else if ( compLine.getType() == VCFHeaderLineType.Integer && compOther.getType() == VCFHeaderLineType.Float ) {
|
||||
// promote key to Float
|
||||
if ( logger != null ) logger.warn("Promoting Integer to Float in header: " + compOther);
|
||||
conflictWarner.warn(line, "Promoting Integer to Float in header: " + compOther);
|
||||
map.put(key, compOther);
|
||||
} else if ( compLine.getType() == VCFHeaderLineType.Float && compOther.getType() == VCFHeaderLineType.Integer ) {
|
||||
// promote key to Float
|
||||
if ( logger != null ) logger.warn("Promoting Integer to Float in header: " + compOther);
|
||||
conflictWarner.warn(line, "Promoting Integer to Float in header: " + compOther);
|
||||
} else {
|
||||
throw new IllegalStateException("Incompatible header types, collision between these two types: " + line + " " + other );
|
||||
}
|
||||
}
|
||||
if ( ! compLine.getDescription().equals(compOther) )
|
||||
if ( logger != null ) logger.warn("Allowing unequal description fields through: keeping " + compOther + " excluding " + compLine);
|
||||
conflictWarner.warn(line, "Allowing unequal description fields through: keeping " + compOther + " excluding " + compLine);
|
||||
} else {
|
||||
// we are not equal, but we're not anything special either
|
||||
if ( logger != null ) logger.warn("Ignoring header line already in map: this header line = " + line + " already present header = " + other);
|
||||
conflictWarner.warn(line, "Ignoring header line already in map: this header line = " + line + " already present header = " + other);
|
||||
}
|
||||
} else {
|
||||
map.put(key, line);
|
||||
|
|
|
|||
Loading…
Reference in New Issue