-
Notifications
You must be signed in to change notification settings - Fork 242
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
new Interface VCFIterator extends CloseableIterator<VariantContext> (continued) #1245
Changes from all commits
5a14002
c057534
187e596
9b1c117
aa6aa4a
81fb941
6af11e6
8693683
f2999fb
4181733
a632ba7
7d72eda
9c0ef3c
037c0a0
8bc4f0f
86c80cb
c57d351
21d8ff0
5aea602
cbbca47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,14 @@ | |
import htsjdk.samtools.seekablestream.SeekableStream; | ||
import htsjdk.samtools.util.BlockCompressedInputStream; | ||
import htsjdk.samtools.util.BlockCompressedStreamConstants; | ||
import htsjdk.samtools.util.IOUtil; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.Arrays; | ||
import java.util.zip.GZIPInputStream; | ||
|
||
/** | ||
* Utilities related to processing of {@link java.io.InputStream}s encoding SAM data | ||
|
@@ -66,26 +66,11 @@ public static boolean isBAMFile(final InputStream stream) | |
/** | ||
* Checks whether the file is a gzipped sam file. Returns true if it | ||
* is and false otherwise. | ||
* @see @link IOUtil#isGZIPInputStream(InputStream) | ||
*/ | ||
@Deprecated | ||
public static boolean isGzippedSAMFile(final InputStream stream) { | ||
if (!stream.markSupported()) { | ||
throw new IllegalArgumentException("Cannot test a stream that doesn't support marking."); | ||
} | ||
stream.mark(8000); | ||
|
||
try { | ||
final GZIPInputStream gunzip = new GZIPInputStream(stream); | ||
final int ch = gunzip.read(); | ||
return true; | ||
} catch (final IOException ioe) { | ||
return false; | ||
} finally { | ||
try { | ||
stream.reset(); | ||
} catch (final IOException ioe) { | ||
throw new IllegalStateException("Could not reset stream."); | ||
} | ||
} | ||
return IOUtil.isGZIPInputStream(stream); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a new use of this deprecated method in VCFHeaderReader. It should be migrated. |
||
} | ||
|
||
// Its too expensive to examine the remote file to determine type. | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -26,6 +26,7 @@ | |||
|
||||
import htsjdk.samtools.Defaults; | ||||
import htsjdk.samtools.SAMException; | ||||
import htsjdk.samtools.SamStreams; | ||||
import htsjdk.samtools.seekablestream.SeekableBufferedStream; | ||||
import htsjdk.samtools.seekablestream.SeekableFileStream; | ||||
import htsjdk.samtools.seekablestream.SeekableHTTPStream; | ||||
|
@@ -110,7 +111,6 @@ public class IOUtil { | |||
public static final Set<String> BLOCK_COMPRESSED_EXTENSIONS = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(".gz", ".gzip", ".bgz", ".bgzf"))); | ||||
|
||||
private static int compressionLevel = Defaults.COMPRESSION_LEVEL; | ||||
|
||||
/** | ||||
* Sets the GZip compression level for subsequent GZIPOutputStream object creation. | ||||
* @param compressionLevel 0 <= compressionLevel <= 9 | ||||
|
@@ -571,12 +571,13 @@ else if (!dir.canRead()) { | |||
* Checks that the two files are the same length, and have the same content, otherwise throws a runtime exception. | ||||
*/ | ||||
public static void assertFilesEqual(final File f1, final File f2) { | ||||
try { | ||||
if (f1.length() != f2.length()) { | ||||
throw new SAMException("File " + f1 + " is " + f1.length() + " bytes but file " + f2 + " is " + f2.length() + " bytes."); | ||||
} | ||||
if (f1.length() != f2.length()) { | ||||
throw new SAMException("File " + f1 + " is " + f1.length() + " bytes but file " + f2 + " is " + f2.length() + " bytes."); | ||||
} | ||||
try ( | ||||
final FileInputStream s1 = new FileInputStream(f1); | ||||
final FileInputStream s2 = new FileInputStream(f2); | ||||
) { | ||||
final byte[] buf1 = new byte[1024 * 1024]; | ||||
final byte[] buf2 = new byte[1024 * 1024]; | ||||
int len1; | ||||
|
@@ -589,12 +590,9 @@ public static void assertFilesEqual(final File f1, final File f2) { | |||
throw new SAMException("Files " + f1 + " and " + f2 + " differ."); | ||||
} | ||||
} | ||||
s1.close(); | ||||
s2.close(); | ||||
} catch (IOException e) { | ||||
} catch (final IOException e) { | ||||
throw new SAMException("Exception comparing files " + f1 + " and " + f2, e); | ||||
} | ||||
|
||||
} | ||||
|
||||
/** | ||||
|
@@ -1157,6 +1155,38 @@ public static List<Path> filesToPaths(Collection<File> files){ | |||
return files.stream().map(File::toPath).collect(Collectors.toList()); | ||||
} | ||||
|
||||
/** number of bytes that will be read for the GZIP-header in the function {@link #isGZIPInputStream(InputStream)} */ | ||||
public static final int GZIP_HEADER_READ_LENGTH = 8000; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you stick this at the top of the file with the other constants? |
||||
|
||||
/** | ||||
* Test whether a input stream looks like a GZIP input. | ||||
* @param stream the input stream. | ||||
* @return true if `stream` starts with a gzip signature | ||||
* @throws IllegalArgumentException if `stream` cannot mark or reset the stream | ||||
* @see SamStreams#isGzippedSAMFile(InputStream) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We can drop this pointer to the old method. |
||||
*/ | ||||
public static boolean isGZIPInputStream(final InputStream stream) { | ||||
/* this function was previously implemented in SamStreams.isGzippedSAMFile */ | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need this comment.
Suggested change
|
||||
if (!stream.markSupported()) { | ||||
throw new IllegalArgumentException("isGZIPInputStream() : Cannot test a stream that doesn't support marking."); | ||||
} | ||||
stream.mark(GZIP_HEADER_READ_LENGTH); | ||||
|
||||
try { | ||||
final GZIPInputStream gunzip = new GZIPInputStream(stream); | ||||
final int ch = gunzip.read(); | ||||
return true; | ||||
} catch (final IOException ioe) { | ||||
return false; | ||||
} finally { | ||||
try { | ||||
stream.reset(); | ||||
} catch (final IOException ioe) { | ||||
throw new IllegalStateException("isGZIPInputStream(): Could not reset stream."); | ||||
} | ||||
} | ||||
} | ||||
|
||||
/** | ||||
* Adds the extension to the given path. | ||||
* | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* | ||
* Permission is hereby granted, free of charge, to any person | ||
* obtaining a copy of this software and associated documentation | ||
* files (the "Software"), to deal in the Software without | ||
* restriction, including without limitation the rights to use, | ||
* copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following | ||
* conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR | ||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
package htsjdk.variant.vcf; | ||
|
||
import htsjdk.samtools.util.CloseableIterator; | ||
import htsjdk.variant.variantcontext.VariantContext; | ||
|
||
/** | ||
* An iterator of `VariantContext`. This iterator can be used to | ||
* decode VCF data on the fly . | ||
* | ||
* Example: | ||
* | ||
* <pre> | ||
* VCFIterator r = new VCFIteratorBuilder().open(System.in); | ||
* while (r.hasNext()) { | ||
* System.out.println(r.next()); | ||
* } | ||
* r.close(); | ||
* </pre> | ||
* | ||
* @author Pierre Lindenbaum / @yokofakun | ||
* @see htsjdk.variant.vcf.VCFIteratorBuilder | ||
* | ||
*/ | ||
public interface VCFIterator extends CloseableIterator<VariantContext> { | ||
/** Returns the VCFHeader associated with this VCF/BCF file. */ | ||
public VCFHeader getHeader(); | ||
|
||
/** | ||
* Returns the next object but does not advance the iterator. Subsequent | ||
* calls to peek() and next() will return the same object. | ||
*/ | ||
public VariantContext peek(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.