From 85f2968104aade8802af021ed7f176a8d3eef660 Mon Sep 17 00:00:00 2001 From: aaron Date: Wed, 29 Dec 2010 20:46:03 +0000 Subject: [PATCH] add convenience methods for RODs-for-reads: the ability to get all the RODs covering the read, regardless of their type or position on the read. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4912 348d0f76-0448-11de-a6fe-93d51630548a --- .../providers/RODMetaDataContainer.java | 15 ++++++++++++--- .../sting/gatk/refdata/ReadMetaDataTracker.java | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/providers/RODMetaDataContainer.java b/java/src/org/broadinstitute/sting/gatk/datasources/providers/RODMetaDataContainer.java index 36b02466d..180431ddd 100644 --- a/java/src/org/broadinstitute/sting/gatk/datasources/providers/RODMetaDataContainer.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/providers/RODMetaDataContainer.java @@ -40,14 +40,14 @@ import java.util.*; * stores both the name and the class for each ROD. This class assumes that: * * -Names must be unique - * -Classes are allowed to have dupplicates + * -Classes are allowed to have duplicates * * This class encapsulates the ref data associations, and provides lookup by name and by * class type. * */ public class RODMetaDataContainer { - // we only allow non-dupplicate ROD names, a HashMap is fine + // we only allow non-duplicate ROD names, a HashMap is fine private final HashMap nameMap = new HashMap(); // we do allow duplicate class entries, so we need to store pairs of data @@ -59,11 +59,20 @@ public class RODMetaDataContainer { } public Collection getSet(String name) { - if (name == null) return nameMap.values(); + if (name == null) return getSet(); Set set = new HashSet(); if (nameMap.containsKey(name)) set.add(nameMap.get(name)); return set; } + + /** + * get the feature contents of this container; the unfiltered set without their name association + * @return + */ + public Collection getSet() { + return new ArrayList(nameMap.values()); + } + // the brute force (n) search ended up being faster than sorting and binary search in all but the most extreme cases (thousands of RODs at a location). public Collection getSet(Class cls) { Collection ret = new ArrayList(); diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/ReadMetaDataTracker.java b/java/src/org/broadinstitute/sting/gatk/refdata/ReadMetaDataTracker.java index 090022269..96dbd15f2 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/ReadMetaDataTracker.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/ReadMetaDataTracker.java @@ -29,10 +29,7 @@ import org.broadinstitute.sting.gatk.refdata.utils.GATKFeature; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.TreeMap; +import java.util.*; /** @@ -168,4 +165,15 @@ public class ReadMetaDataTracker { public Map> getContigOffsetMapping(Class cl) { return createGenomeLocAlignment(record, mapping, cl, null); } + + /** + * get the list of all the RODS overlapping this read, without any information about their position + * @return a Collection (no order guaranteed), of all the RODs covering this read + */ + public List getAllCoveringRods() { + List ret = new ArrayList(); + for (Map.Entry entry : mapping.entrySet()) + ret.addAll(entry.getValue().getSet()); + return ret; + } }