<commit_before>package io.compgen.ngsutils.vcf;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.zip.GZIPInputStream;

import io.compgen.ngsutils.tabix.BGZFile;
import io.compgen.ngsutils.tabix.BGZInputStream;

public class VCFReader {
	protected BufferedReader in;
	protected VCFHeader header=null;
	private boolean closed = false;
	
	public VCFReader(String filename) throws IOException, VCFParseException {
		if (filename.equals("-")) {
			in = new BufferedReader(new InputStreamReader(System.in));
		} else if (filename.endsWith(".gz") || filename.endsWith(".bgz") ||filename.endsWith(".bgzf")) {
			if (BGZFile.isBGZFile(filename)) {
				in = new BufferedReader(new InputStreamReader(new BGZInputStream(filename)));				
			} else {
				in = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(filename))));
			}
		} else {
			in = new BufferedReader(new FileReader(filename));
		}
		readHeader();
	}
<commit_msg>Gzip vs bgzip now auto-detected using file magic, not just by filename.<commit_after>package io.compgen.ngsutils.vcf;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.zip.GZIPInputStream;

import io.compgen.ngsutils.tabix.BGZFile;
import io.compgen.ngsutils.tabix.BGZInputStream;

public class VCFReader {
	protected BufferedReader in;
	protected VCFHeader header=null;
	private boolean closed = false;
	
	public VCFReader(String filename) throws IOException, VCFParseException {
        if (filename.equals("-")) {
            in = new BufferedReader(new InputStreamReader(System.in));
        } else if (BGZFile.isBGZFile(filename)) {
                in = new BufferedReader(new InputStreamReader(new BGZInputStream(filename)));               
        } else if (isGZipFile(filename)){
                in = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(filename))));
        } else {
            in = new BufferedReader(new FileReader(filename));
        }

//        if (filename.equals("-")) {
//            in = new BufferedReader(new InputStreamReader(System.in));
//        } else if (filename.endsWith(".gz") || filename.endsWith(".bgz") ||filename.endsWith(".bgzf")) {
//            if (BGZFile.isBGZFile(filename)) {
//                in = new BufferedReader(new InputStreamReader(new BGZInputStream(filename)));               
//            } else {
//                in = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(filename))));
//            }
//        } else {
//            in = new BufferedReader(new FileReader(filename));
//        }

        readHeader();
	}

	public static boolean isGZipFile(String filename) throws IOException {
	    InputStream is = new FileInputStream(filename);
        byte[] magic = new byte[2];
        is.read(magic);
        is.close();
        return Arrays.equals(magic, new byte[] {0x1f, (byte) 0x8B});// need to cast 0x8b because it is a neg. num in 2-complement
	}
	
{'fraction_non_alphanumeric': 0.11764705882352941, 'fraction_numerical': 0.002341235001463272, 'mean_word_length': 3.4855643044619424, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3393344', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1008, 'n_words': 229}