Added a copy() method for ReadBackedPileups

necessary to create new alignment contexts with hard-copies of the pileup.
This commit is contained in:
Mauricio Carneiro 2012-12-04 23:56:30 -05:00
parent 6feda540a4
commit 30f013aeb0
3 changed files with 30 additions and 0 deletions

View File

@ -1054,6 +1054,11 @@ public abstract class AbstractReadBackedPileup<RBP extends AbstractReadBackedPil
public FragmentCollection<PileupElement> toFragments() {
return FragmentUtils.create(this);
}
@Override
public ReadBackedPileup copy() {
return new ReadBackedPileupImpl(loc, (PileupElementTracker<PileupElement>) pileupElementTracker.copy());
}
}

View File

@ -34,11 +34,20 @@ import java.util.*;
*/
abstract class PileupElementTracker<PE extends PileupElement> implements Iterable<PE> {
public abstract int size();
public abstract PileupElementTracker<PE> copy();
}
class UnifiedPileupElementTracker<PE extends PileupElement> extends PileupElementTracker<PE> {
private final List<PE> pileup;
@Override
public UnifiedPileupElementTracker<PE> copy() {
UnifiedPileupElementTracker<PE> result = new UnifiedPileupElementTracker<PE>();
for(PE element : pileup)
result.add(element);
return result;
}
public UnifiedPileupElementTracker() { pileup = new LinkedList<PE>(); }
public UnifiedPileupElementTracker(List<PE> pileup) { this.pileup = pileup; }
@ -65,6 +74,14 @@ class PerSamplePileupElementTracker<PE extends PileupElement> extends PileupElem
pileup = new HashMap<String,PileupElementTracker<PE>>();
}
public PerSamplePileupElementTracker<PE> copy() {
PerSamplePileupElementTracker<PE> result = new PerSamplePileupElementTracker<PE>();
for (Map.Entry<String, PileupElementTracker<PE>> entry : pileup.entrySet())
result.addElements(entry.getKey(), entry.getValue());
return result;
}
/**
* Gets a list of all the samples stored in this pileup.
* @return List of samples in this pileup.

View File

@ -283,4 +283,12 @@ public interface ReadBackedPileup extends Iterable<PileupElement>, HasGenomeLoca
* @return
*/
public FragmentCollection<PileupElement> toFragments();
/**
* Creates a full copy (not shallow) of the ReadBacked Pileup
*
* @return
*/
public ReadBackedPileup copy();
}