ugly RG encoding

This commit is contained in:
Mauricio Carneiro 2012-03-01 17:55:28 -05:00
parent 4409293b5d
commit 486712bfc2
1 changed files with 20 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package org.broadinstitute.sting.gatk.walkers.bqsr;
import org.broadinstitute.sting.utils.sam.GATKSAMRecord;
import java.util.Arrays;
import java.util.HashMap;
/*
* Copyright (c) 2009 The Broad Institute
@ -38,6 +39,10 @@ import java.util.Arrays;
*/
public class ReadGroupCovariate implements RequiredCovariate {
private final HashMap<String, Short> readGroupLookupTable = new HashMap<String, Short>();
private final HashMap<Short, String> readGroupReverseLookupTable = new HashMap<Short, String>();
private short nextId = 0;
// Initialize any member variables using the command-line arguments passed to the walkers
@Override
@ -48,8 +53,17 @@ public class ReadGroupCovariate implements RequiredCovariate {
public CovariateValues getValues(final GATKSAMRecord read) {
final int l = read.getReadLength();
final String readGroupId = read.getReadGroup().getReadGroupId();
String [] readGroups = new String[l];
Arrays.fill(readGroups, readGroupId);
short shortId;
if (readGroupLookupTable.containsKey(readGroupId))
shortId = readGroupLookupTable.get(readGroupId);
else {
shortId = nextId;
readGroupLookupTable.put(readGroupId, nextId);
readGroupReverseLookupTable.put(nextId, readGroupId);
nextId++;
}
Short [] readGroups = new Short[l];
Arrays.fill(readGroups, shortId);
return new CovariateValues(readGroups, readGroups, readGroups);
}
@ -58,6 +72,10 @@ public class ReadGroupCovariate implements RequiredCovariate {
public final Object getValue(final String str) {
return str;
}
public final String decodeReadGroup(final short id) {
return readGroupReverseLookupTable.get(id);
}
}