samtools / htsjdk

A Java API for high-throughput sequencing data (HTS) formats.
http://samtools.github.io/htsjdk/
283 stars 242 forks source link

get filter null #1368

Open YdlNAU opened 5 years ago

YdlNAU commented 5 years ago

Verify

I have already see https://github.com/samtools/htsjdk/issues/679 I repeat because I think it is a bug and I have a emergency!

Subject of the issue

I use this library's query API to rapidly get un parserd variant string ! BUT when i get the filter FIELD, it returns [] (or null!) here is my code, and I use 2.18 and 2.19. can any one do me a favor to tell me, how can I fix this problem! Super thanks!!

VCFFileReader reader = new VCFFileReader(filePath, true);
CloseableIterator<VariantContext> searchVariantRecords = reader.query(chrName, beginPos, endPos);

dataIsEmpty = true;

while (searchVariantRecords.hasNext()) {
    dataIsEmpty = false;    
    VariantContext variantContext = searchVariantRecords.next();
    String[] dataValues = analysisVCF.getVariationRecord(variantContext);
    showVariantReccords(dataValues, separate);
}

public String[] getVariationRecord(VariantContext variantContext) {
        String genotypeData = ((LazyGenotypesContext) variantContext.getGenotypes()).getUnparsedGenotypeData()
                .toString();
        String[] split = genotypeData.split("\t");
        String[] dataValues = new String[8 + split.length];
        dataValues[0] = variantContext.getContig();
        dataValues[1] = String.valueOf(variantContext.getStart());
        dataValues[2] = variantContext.getID();
        dataValues[3] = variantContext.getReference().getBaseString();
        dataValues[4] = variantContext.getAlternateAlleles().toString();
        dataValues[5] = String.valueOf(variantContext.getPhredScaledQual());
        dataValues[6] = variantContext.getFilters().toString();
        dataValues[7] = variantContext.getAttributes().toString();
        dataValues[8] = split[0];

        System.out.println(variantContext.toStringWithoutGenotypes());

        for (int i = 9; i < dataValues.length; i++) {
            dataValues[i] = split[i - 8];
        }
        return dataValues;
}

Your environment

Steps to reproduce

Any indexed VCF is OK

Expected behaviour

should return PASS

Actual behaviour

return [] or null

yfarjoun commented 5 years ago

replace variantContext.getFilters() with Optional.ofNullable(variantContext.getFilters()).getOrElse("PASS").toString()

YdlNAU commented 5 years ago
  1. Firstly, super thanks for you response so quickly!!
  2. I consider this is same with
    
    if (variantContext.getFilters().isEmpty()) {
        return "PASS";
    }

because I have an error when paste your codes to my eclipse !



3. But how can I distinguish "PASS" with "." ??? @yfarjoun   thanks you so much !
YdlNAU commented 5 years ago

I have already test a quality bad bgzip compressed vcf file! it can't distinguish them.

YdlNAU commented 5 years ago

@yfarjoun

I'm writing codes for non-open source project! But this is an LGPL lic. So if you have answer not to change source codes, I will very appreciate!