/** Add some lines to header before showing it */ @Override public boolean addHeaders(VcfFileIterator vcfFile) { super.addHeaders(vcfFile); for (String key : fieldsToAdd.keySet()) { // Get type String type = fieldsType.get(key); if (type == null) { System.err.println("WARNING: Cannot find type for field '" + key + "', using 'String'."); type = VcfInfoType.String.toString(); } String infoKey = VcfEntry.vcfInfoKeySafe(DBNSFP_VCF_INFO_PREFIX + key); vcfFile .getVcfHeader() .addLine( "##INFO=<ID=" + infoKey + ",Number=A,Type=" + type + ",Description=\"" + fieldsToAdd.get(key) + "\">"); } return false; }
/** Annotate a VCF file using dbNSFP */ ArrayList<VcfEntry> annotate(boolean createList) { ArrayList<VcfEntry> list = (createList ? new ArrayList<VcfEntry>() : null); // Open VCF file vcfFile = new VcfFileIterator(vcfFileName); vcfFile.setDebug(debug); // Initialize annotations try { annotateInit(vcfFile); } catch (Exception e) { throw new RuntimeException(e); } // Annotate VCF file if (verbose) Timer.showStdErr("Annotating file '" + vcfFileName + "'"); boolean showHeader = true; int pos = -1; String chr = ""; for (VcfEntry vcfEntry : vcfFile) { try { // Show header? if (showHeader) { // Add VCF header addHeaders(vcfFile); String headerStr = vcfFile.getVcfHeader().toString(); if (!headerStr.isEmpty()) print(headerStr); showHeader = false; // Check that the fields we want to add are actually in the database checkFieldsToAdd(); } // Check if file is sorted if (vcfEntry.getChromosomeName().equals(chr) && vcfEntry.getStart() < pos) { fatalError( "Your VCF file should be sorted!" // + "\n\tPrevious entry " + chr + ":" + pos // + "\n\tCurrent entry " + vcfEntry.getChromosomeName() + ":" + (vcfEntry.getStart() + 1) // ); } // Annotate annotate(vcfEntry); // Show print(vcfEntry); if (list != null) list.add(vcfEntry); count++; // Update chr:pos chr = vcfEntry.getChromosomeName(); pos = vcfEntry.getStart(); } catch (IOException e) { throw new RuntimeException(e); } } annotateFinish(); vcfFile.close(); // Show some stats if (verbose) { double perc = (100.0 * countAnnotated) / count; Timer.showStdErr( "Done." // + "\n\tTotal annotated entries : " + countAnnotated // + "\n\tTotal entries : " + count // + "\n\tPercent : " + String.format("%.2f%%", perc) // ); } return list; }