/** * Get the VCFHeaderLine whose key equals key. Returns null if no such line exists * @param key * @return */ public VCFHeaderLine getMetaDataLine(final String key) { for (final VCFHeaderLine line: mMetaData) { if ( line.getKey().equals(key) ) return line; } return null; }
/** * Get the VCFHeaderLine whose key equals key. Returns null if no such line exists * @param key * @return */ public VCFHeaderLine getMetaDataLine(final String key) { for (final VCFHeaderLine line: mMetaData) { if ( line.getKey().equals(key) ) return line; } return null; }
/** * Get the VCFHeaderLine whose key equals key. Returns null if no such line exists * @param key * @return */ public VCFHeaderLine getMetaDataLine(final String key) { for (final VCFHeaderLine line: mMetaData) { if ( line.getKey().equals(key) ) return line; } return null; }
protected void initialize(String name, Map<String, String> genericFields) { if ( name == null || genericFields == null || genericFields.isEmpty() ) throw new IllegalArgumentException(String.format("Invalid VCFSimpleHeaderLine: key=%s name=%s", super.getKey(), name)); if ( name.contains("<") || name.contains(">") ) throw new IllegalArgumentException("VCFHeaderLine: ID cannot contain angle brackets"); if ( name.contains("=") ) throw new IllegalArgumentException("VCFHeaderLine: ID cannot contain an equals sign"); this.name = name; this.genericFields.putAll(genericFields); }
protected void initialize(String name, Map<String, String> genericFields) { if ( name == null || genericFields == null || genericFields.isEmpty() ) throw new IllegalArgumentException(String.format("Invalid VCFSimpleHeaderLine: key=%s name=%s", super.getKey(), name)); if ( name.contains("<") || name.contains(">") ) throw new IllegalArgumentException("VCFHeaderLine: ID cannot contain angle brackets"); if ( name.contains("=") ) throw new IllegalArgumentException("VCFHeaderLine: ID cannot contain an equals sign"); this.name = name; this.genericFields.putAll(genericFields); }
protected void initialize(String name, Map<String, String> genericFields) { if ( name == null || genericFields == null || genericFields.isEmpty() ) throw new IllegalArgumentException(String.format("Invalid VCFSimpleHeaderLine: key=%s name=%s", super.getKey(), name)); if ( name.contains("<") || name.contains(">") ) throw new IllegalArgumentException("VCFHeaderLine: ID cannot contain angle brackets"); if ( name.contains("=") ) throw new IllegalArgumentException("VCFHeaderLine: ID cannot contain an equals sign"); this.name = name; this.genericFields.putAll(genericFields); }
private void validate() { if ( name == null || type == null || description == null || lineType == null ) throw new IllegalArgumentException(String.format("Invalid VCFCompoundHeaderLine: key=%s name=%s type=%s desc=%s lineType=%s", super.getKey(), name, type, description, lineType )); if ( name.contains("<") || name.contains(">") ) throw new IllegalArgumentException("VCFHeaderLine: ID cannot contain angle brackets"); if ( name.contains("=") ) throw new IllegalArgumentException("VCFHeaderLine: ID cannot contain an equals sign"); if ( type == VCFHeaderLineType.Flag && count != 0 ) { count = 0; if ( GeneralUtils.DEBUG_MODE_ENABLED ) { System.err.println("FLAG fields must have a count value of 0, but saw " + count + " for header line " + getID() + ". Changing it to 0 inside the code"); } } }
/** * Remove all lines with a VCF version tag from the provided set of header lines */ private void removeVCFVersionLines( final Set<VCFHeaderLine> headerLines ) { final List<VCFHeaderLine> toRemove = new ArrayList<VCFHeaderLine>(); for (final VCFHeaderLine line : headerLines) { if (VCFHeaderVersion.isFormatString(line.getKey())) { toRemove.add(line); } } headerLines.removeAll(toRemove); }
public boolean equals(Object o) { if ( !(o instanceof VCFHeaderLine) ) return false; return mKey.equals(((VCFHeaderLine)o).getKey()) && mValue.equals(((VCFHeaderLine)o).getValue()); }
/** * Remove all lines with a VCF version tag from the provided set of header lines */ private void removeVCFVersionLines( final Set<VCFHeaderLine> headerLines ) { final List<VCFHeaderLine> toRemove = new ArrayList<VCFHeaderLine>(); for (final VCFHeaderLine line : headerLines) { if (VCFHeaderVersion.isFormatString(line.getKey())) { toRemove.add(line); } } headerLines.removeAll(toRemove); }
/** * check our metadata for a VCF version tag, and throw an exception if the version is out of date * or the version is not present */ public void loadVCFVersion() { final List<VCFHeaderLine> toRemove = new ArrayList<VCFHeaderLine>(); for (final VCFHeaderLine line : mMetaData) if (VCFHeaderVersion.isFormatString(line.getKey())) { toRemove.add(line); } // remove old header lines for now, mMetaData.removeAll(toRemove); }
private static String getCommandLineKey(final VCFHeader header, final String walkerName) { final Iterator<VCFHeaderLine> existingMetaDataIterator = header.getMetaDataInInputOrder().iterator(); // the command line argument keys are in the format GATK_COMMAND_LINE_KEY.(walker name) final String searchKey = String.format("%s.%s", GATK_COMMAND_LINE_KEY, walkerName); int commandLineKeyCount = 0; VCFHeaderLine line; while ( existingMetaDataIterator.hasNext() ) { line = existingMetaDataIterator.next(); // if we find another key that starts with the same text as the walker if ( line.getKey().startsWith(searchKey) ) commandLineKeyCount++; } // if there are no existing keys with this same walker name, then just return the // GATK_COMMAND_LINE_KEY.(walker name) format if ( commandLineKeyCount == 0 ) return searchKey; // otherwise append the count associated with this new command (existing + 1) else return String.format("%s.%d", searchKey, commandLineKeyCount+1); }
public static VCFHeaderVersion getVCFHeaderVersion(VCFHeader vcfHeader){ Iterator<VCFHeaderLine> iter = vcfHeader.getMetaDataInInputOrder().iterator(); while(iter.hasNext()){ VCFHeaderLine hl = iter.next(); if(hl.getKey().equals("fileformat")){ return VCFHeaderVersion.toHeaderVersion(hl.getValue()); } } return null; }
public static Set<VCFHeaderLine> withUpdatedContigsAsLines(final Set<VCFHeaderLine> oldLines, final File referenceFile, final SAMSequenceDictionary refDict, final boolean referenceNameOnly) { final Set<VCFHeaderLine> lines = new LinkedHashSet<>(oldLines.size()); for (final VCFHeaderLine line : oldLines) { if (line instanceof VCFContigHeaderLine) continue; // skip old contig lines if (line.getKey().equals(VCFHeader.REFERENCE_KEY)) continue; // skip the old reference key lines.add(line); } for (final VCFHeaderLine contigLine : makeContigHeaderLines(refDict, referenceFile)) lines.add(contigLine); final String referenceValue; if (referenceFile != null) { if (referenceNameOnly) { final int extensionStart = referenceFile.getName().lastIndexOf('.'); referenceValue = extensionStart == -1 ? referenceFile.getName() : referenceFile.getName().substring(0, extensionStart); } else { referenceValue = "file://" + referenceFile.getAbsolutePath(); } lines.add(new VCFHeaderLine(VCFHeader.REFERENCE_KEY, referenceValue)); } return lines; }
@Test public void testToVCFHeaderLine() { final HomRefBlock band = new HomRefBlock(vc, 10, 20, HomoSapiensConstants.DEFAULT_PLOIDY); Assert.assertEquals(band.toVCFHeaderLine().getKey(), "GVCFBlock10-20", "Wrong key for HomRefBlock " + band); } }
private VariantSetMetadata convertHeaderLine(VCFHeaderLine hl) { VariantSetMetadata vsm = new VariantSetMetadata(); vsm.setKey(hl.getKey()); vsm.setValue(hl.getValue()); return vsm; }
@Override public void setHeader(VCFHeader header) { VCFHeaderVersion version = null; // Normally AbstractVCFCodec parses the header and thereby sets the // version field. It gets used later on so we need to set it. for (final VCFHeaderLine line : header.getMetaDataInInputOrder()) { if (VCFHeaderVersion.isFormatString(line.getKey())) { version = VCFHeaderVersion.toHeaderVersion(line.getValue()); break; } } codec.setHeaderAndVersion(header, version); }
@Override public void setHeader(VCFHeader header) { VCFHeaderVersion version = null; // Normally AbstractVCFCodec parses the header and thereby sets the // version field. It gets used later on so we need to set it. for (final VCFHeaderLine line : header.getMetaDataInInputOrder()) { if (VCFHeaderVersion.isFormatString(line.getKey())) { version = VCFHeaderVersion.toHeaderVersion(line.getValue()); break; } } codec.setHeaderAndVersion(header, version); }
@Override public void setHeader(VCFHeader header) { VCFHeaderVersion version = null; // Normally AbstractVCFCodec parses the header and thereby sets the // version field. It gets used later on so we need to set it. for (final VCFHeaderLine line : header.getMetaDataInInputOrder()) { if (VCFHeaderVersion.isFormatString(line.getKey())) { version = VCFHeaderVersion.toHeaderVersion(line.getValue()); break; } } codec.setHeaderAndVersion(header, version); }
@Test(enabled = true) public void testGATKVersionInVCF() throws Exception { WalkerTestSpec spec = new WalkerTestSpec("-T TestPrintVariantsWalker -R " + b37KGReference + " -V " + privateTestDir + "NA12878.WGS.b37.chr20.firstMB.vcf" + " -o %s -L 20:61098", 1, Arrays.asList("")); spec.disableShadowBCF(); final File vcf = executeTest("testGATKVersionInVCF", spec).first.get(0); final VCFCodec codec = new VCFCodec(); final VCFHeader header = (VCFHeader) codec.readActualHeader(codec.makeSourceFromStream(new FileInputStream(vcf))); // go through the metadata headers and look for ones that start with the GATK_COMMAND_LINE_KEY VCFHeaderLine versionLine = null; for ( final VCFHeaderLine headerLine : header.getMetaDataInInputOrder()) { if(headerLine.getKey().startsWith(GATKVCFUtils.GATK_COMMAND_LINE_KEY)) { versionLine = headerLine; break; } } Assert.assertNotNull(versionLine); Assert.assertTrue(versionLine.toString().contains("TestPrintVariantsWalker")); }