Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ReferenceSequenceFile.getSubsequenceAt(final Locatable locatable ) shortcut to getSubsequenceAt(loc.getContig(), loc.getStart(), loc.getEnd()) #1725

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package htsjdk.samtools.reference;

import htsjdk.samtools.SAMSequenceDictionary;
import htsjdk.samtools.util.Locatable;

import java.io.Closeable;
import java.io.IOException;
Expand Down Expand Up @@ -80,7 +81,17 @@ public interface ReferenceSequenceFile extends Closeable {
* @throws UnsupportedOperationException if !sIndexed.
*/
public ReferenceSequence getSubsequenceAt( String contig, long start, long stop );


/**
* Gets the subsequence of the contig in the locatable. Shortcut to <code>getSubsequenceAt(locatable.getContig(), locatable.getStart(), locatable.getEnd());</code>
* @param locatable the interval to retrieve.
* @return The partial reference sequence associated with this location.
* @throws UnsupportedOperationException if !sIndexed.
*/
public default ReferenceSequence getSubsequenceAt(final Locatable locatable ) {
return getSubsequenceAt(locatable.getContig(), locatable.getStart(), locatable.getEnd());
}

/**
* @return Reference name, file name, or something other human-readable representation.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import htsjdk.samtools.util.CloserUtil;
import htsjdk.samtools.util.GZIIndex;
import htsjdk.samtools.util.IOUtil;
import htsjdk.samtools.util.Interval;
import htsjdk.samtools.util.RuntimeIOException;
import htsjdk.samtools.util.StringUtil;
import org.testng.Assert;
Expand Down Expand Up @@ -138,6 +139,21 @@ public void testFirstSequence(AbstractIndexedFastaSequenceFile sequenceFile) {
System.err.printf("testFirstSequence runtime: %dms%n", (endTime - startTime)) ;
}

@Test(dataProvider="homosapiens")
public void testSubsequenceAtLocatable(AbstractIndexedFastaSequenceFile sequenceFile) {
long startTime = System.currentTimeMillis();
ReferenceSequence sequence = sequenceFile.getSubsequenceAt(new Interval("chrM",1,firstBasesOfChrM.length()));
long endTime = System.currentTimeMillis();

Assert.assertEquals(sequence.getName(),"chrM","Sequence contig is not correct");
Assert.assertEquals(sequence.getContigIndex(),0,"Sequence contig index is not correct");
Assert.assertEquals(StringUtil.bytesToString(sequence.getBases()),firstBasesOfChrM,"First n bases of chrM are incorrect");

CloserUtil.close(sequenceFile);

System.err.printf("testSubsequenceAtLocatable runtime: %dms%n", (endTime - startTime)) ;
}

@Test(dataProvider="homosapiens")
public void testFirstSequenceExtended(AbstractIndexedFastaSequenceFile sequenceFile) {
long startTime = System.currentTimeMillis();
Expand Down
Loading