From 486712bfc2f69d356da739098b8710142fe1bf47 Mon Sep 17 00:00:00 2001 From: Mauricio Carneiro Date: Thu, 1 Mar 2012 17:55:28 -0500 Subject: [PATCH] ugly RG encoding --- .../gatk/walkers/bqsr/ReadGroupCovariate.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/ReadGroupCovariate.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/ReadGroupCovariate.java index 6076a7a20..aecdd3d4b 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/ReadGroupCovariate.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/bqsr/ReadGroupCovariate.java @@ -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 readGroupLookupTable = new HashMap(); + private final HashMap readGroupReverseLookupTable = new HashMap(); + 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); + } }