From 4723cad1bee86d35c697f88f5585a237a8b385b8 Mon Sep 17 00:00:00 2001 From: asivache Date: Tue, 20 Apr 2010 17:35:09 +0000 Subject: [PATCH] New method: getBasesAtLocus(int n); for the windowed reference context, this method extracts n bases starting at the current locus (NOT at the window start, so this method is an extension of getBase()) git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3210 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/gatk/contexts/ReferenceContext.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/java/src/org/broadinstitute/sting/gatk/contexts/ReferenceContext.java b/java/src/org/broadinstitute/sting/gatk/contexts/ReferenceContext.java index 76d093ac0..0db2801ac 100644 --- a/java/src/org/broadinstitute/sting/gatk/contexts/ReferenceContext.java +++ b/java/src/org/broadinstitute/sting/gatk/contexts/ReferenceContext.java @@ -107,4 +107,26 @@ public class ReferenceContext { public char[] getBases() { return bases; } + + /** Extracts from the current window and returns n bases starting at this context's locus (NOT + * from the window start!). The returned array of chars is newly allocated. If n is too large (runs beyond + * the right boundary of this context's window), an exception will be thrown. If n==(-1), all bases starting + * from this context's locus through the end of the window will be returned. + * @param n number of requested bases including and starting from the current locus + * @return + */ + public char[] getBasesAtLocus(int n) { + + int start = (int)(locus.getStart()-window.getStart()); + int stop = ( n==(-1) ? bases.length : start+n ); + + char[] b = new char[stop-start]; + + if ( stop > bases.length ) + throw new StingException("Bases beyond the current window requested: window="+window+", requested="+n); + + int i = 0; + for ( int j = start ; j < stop ; j++) b[i++]=bases[j]; + return b; + } }