Skip to content

Commit

Permalink
Modifications to the VCF comparator tool kit.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAustinNix authored and DavidAustinNix committed Feb 2, 2017
1 parent 8e1bdd6 commit 710cfc8
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Documentation/USeqDocumentation/license.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<html><head> <title>README</title><style type="text/css"> #rt{text-align:right; color: #000000; font-weight: bold} #grBk {background-color: #CC9966;} TD {font-family: Verdana, Arial, Helvetica, sans-serif; font-size:12;} H1 {color: #996633; font:arial; font-size:16;} H2 {color: #996633; font:arial; font-size:12;} BODY {color:black; background-color:white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size:12;} A:link {text-decoration: none; color: #000000; font-weight: bold} A:visited {text-decoration: none; color: #000000; font-weight: bold} A:hover {text-decoration: none; color: #FFCC66; font-weight: bold} A:active {text-decoration: none; color: #000000; font-weight: bold} </style></head><center><H1>USeq License</H1></center>USeq, copyright 2014 University of Utah Research Foundation. All rights reserved.<p>Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:<p>(1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.<p>(2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.<p>(3) Neither the name of the University of Utah nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.<p>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<p>You are under no obligation whatsoever to provide any bug fixes, patches, or upgrades to the features, functionality or performance of the source code ("Enhancements") to anyone; however, if you choose to make your Enhancements available either publicly, or directly to the University of Utah, without imposing a separate written license agreement for such Enhancements, then you hereby grant the following license: a non-exclusive, royalty-free perpetual license to install, use, modify, prepare derivative works, incorporate into other computer software, distribute, and sublicense such enhancements or derivative works thereof, in binary and source code form.<p></HTML>
<html><head> <title>README</title><style type="text/css"> #rt{text-align:right; color: #000000; font-weight: bold} #grBk {background-color: #CC9966;} TD {font-family: Verdana, Arial, Helvetica, sans-serif; font-size:12;} H1 {color: #996633; font:arial; font-size:16;} H2 {color: #996633; font:arial; font-size:12;} BODY {color:black; background-color:white; font-family: Verdana, Arial, Helvetica, sans-serif; font-size:12;} A:link {text-decoration: none; color: #000000; font-weight: bold} A:visited {text-decoration: none; color: #000000; font-weight: bold} A:hover {text-decoration: none; color: #FFCC66; font-weight: bold} A:active {text-decoration: none; color: #000000; font-weight: bold} </style></head><center><H1>USeq BSD License</H1></center>USeq, copyright 2016 University of Utah Research Foundation. All rights reserved.<p>Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:<p>Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list ofconditions and the following disclaimer.<p> 2. Redistributions in binary form must reproduce the above copyright notice, this list ofconditions and the following disclaimer in the documentation and/or other materials provided withthe distribution.<p> 3. Neither the name of the University of Utah nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.<p> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESSOR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITYAND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER ORCONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIALDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANYWAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</HTML>
Expand Down
42 changes: 28 additions & 14 deletions Source/edu/utah/seq/vcf/VCFBackgroundScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class VCFBackgroundScanner {
private int minReadCoverage = 20;
private int minNumSamples = 3;
private boolean verbose = false;
private boolean removeNonZScoredRecords = false;
private double minimumZScore = 0;
private double maxSampleAF = 0.3;

Expand Down Expand Up @@ -85,7 +86,8 @@ public VCFBackgroundScanner(String[] args){

//print summary stats
if (tooFewSamples.size() !=0){
System.err.println("WARNING, the following did not have enough background samples present to calculate a z-score. Saving as unmodified records. Visually inspect!");
System.err.println("WARNING, the following did not have any mpileup lines (e.g. outside the compiled regions?) or enough background "
+ "samples passing thresholds to calculate a z-score. ");
System.err.println(Misc.stringArrayListToString(tooFewSamples, "\n"));
}
System.out.println("\t#Rec="+numRecords+" #Saved="+numSaved+" #NotScored="+numNotScored+" #FailingBKZ="+numFailingZscore+"\n");
Expand All @@ -107,7 +109,8 @@ record = record.trim();
if (record.length() == 0) continue;
if (record.startsWith("#")){
if (addInfo && record.startsWith("##INFO=")) {
vcfOut.println("##INFO=<ID=BKZ,Number=1,Type=Float,Description=\"Smallest AF z-score calculated from background AFs over effected bases. Values < ~4 are suspicous, non reference observations are likely present in the background samples.\">");
vcfOut.println("##INFO=<ID=BKZ,Number=1,Type=Float,Description=\"Smallest AF z-score calculated from background AFs over effected bases. "
+ "Values < ~4 are suspicous, non reference observations are likely present in the background samples.\">");
vcfOut.println("##INFO=<ID=BKAF,Type=String,Description=\"Non-reference AFs from the background samples used to calculate the BKZ.\">");
addInfo = false;
}
Expand Down Expand Up @@ -135,19 +138,30 @@ private void score(String record) throws Exception {

//interbase coor of effected bps
int[] startStop = QueryIndexFileLoader.fetchEffectedBps(fields, true);
if (startStop == null) throw new IOException ("Failed to parse the effected bps for this variant:\n"+record);
if (startStop == null) {
System.err.println("Failed to parse the effected bps.");
if (removeNonZScoredRecords == false) {
vcfOut.println(record);
numSaved++;
}
tooFewSamples.add(record);
numNotScored++;
return;
}

//pull mpileup records, if none then warn and save vcf record
int start = startStop[0]+1-bpBuffer;
if (start < 1) start = 1;
String tabixCoor = fields[0]+":"+start+"-"+(startStop[1]+bpBuffer);
TabixReader.Iterator it = fetchInteratorOnCoordinates(tabixCoor);
if (it == null) {

vcfOut.println(record);
if (removeNonZScoredRecords == false) {
vcfOut.println(record);
numSaved++;
}
tooFewSamples.add(record);
numNotScored++;
numSaved++;

return;
}

Expand Down Expand Up @@ -178,10 +192,12 @@ private void score(String record) throws Exception {

//was a z-score calculated?
if (minZScore == Double.MAX_VALUE) {
vcfOut.println(record);
if (removeNonZScoredRecords == false) {
vcfOut.println(record);
numSaved++;
}
tooFewSamples.add(record);
numNotScored++;
numSaved++;
}

//append min zscore and save
Expand Down Expand Up @@ -213,11 +229,6 @@ private String fetchFormattedAFs(MpileupSample[] toExamine) {
}
return sb.toString();
}

private void append4Decimals(double num, StringBuilder sb){
if (num ==0) sb.append("0");
else sb.append(fourDecimalMax.format(num));
}

private void printPileupInfo(MpileupLine ml, MpileupSample[] toExamine, double zscore) {
StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -309,6 +320,7 @@ public void processArgs(String[] args){
case 'q': minBaseQuality = Integer.parseInt(args[++i]); break;
case 'c': minReadCoverage = Integer.parseInt(args[++i]); break;
case 'a': minNumSamples = Integer.parseInt(args[++i]); break;
case 'e': removeNonZScoredRecords = true; break;
case 'd': verbose = true; break;
case 'h': printDocs(); System.exit(0);
default: Misc.printExit("\nProblem, unknown option! " + mat.group());
Expand Down Expand Up @@ -367,6 +379,7 @@ public void printSettings(){
System.out.println(minBaseQuality+"\tMin mpileup sample base quality");
System.out.println(maxSampleAF+"\tMax mpileup sample AF");
System.out.println(minNumSamples+"\tMin # samples for z-score calc");
System.out.println(removeNonZScoredRecords+ "\tExclude vcf records that could not be z-scored");
System.out.println(verbose+"\tVerbose");
System.out.println(minimumZScore+"\tMin vcf AF z-score to save");
if (sampleIndexesToExamine!=null) System.out.println(Misc.hashSetToString(sampleIndexesToExamine, ",")+"\tMpileup samples to examine");
Expand Down Expand Up @@ -404,12 +417,13 @@ public static void printDocs(){
"-c Minimum mpileup sample read coverge, defaults to 20\n"+
"-f Maximum mpileup sample AF, defaults to 0.3\n"+
"-a Minimum # mpileup samples for z-score calculation, defaults to 3\n" +
"-e Exclude vcf records that could not be z-scored\n"+
"-d Print verbose debugging output\n" +

"\n"+

"Example: java -Xmx4G -jar pathTo/USeq/Apps/VCFBackgroundScanner -v SomaticVcfs/ -z 3\n"+
"-m bkg.mpileup.gz -s BkgFiltVcfs/ -b 1 -q 13 \n\n"+
"-m bkg.mpileup.gz -s BkgFiltVcfs/ -b 1 -q 13 -e \n\n"+

"**************************************************************************************\n");
}
Expand Down
4 changes: 2 additions & 2 deletions Source/edu/utah/seq/vcf/VCFComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ public void parseFilterFiles(){
createIntervalTreesForBedCalls();
}
else if (keyParser == null && keyBedCalls == null){
keyParser = new VCFParser(vcfKey, true, requireGenotypeMatch, false);
keyParser = new VCFParser(vcfKey, true, true, false);
if (removeNonPass){
keyParser.setFilterFieldPeriodToTextOnAllRecords(VCFRecord.PASS);
keyParser.filterVCFRecords(VCFRecord.PASS);
Expand Down Expand Up @@ -571,7 +571,7 @@ else if (keyParser == null && keyBedCalls == null){
results.append(res);

//parse test variants!
testParser = new VCFParser(vcfTest, true, requireGenotypeMatch, useVQSLOD);
testParser = new VCFParser(vcfTest, true, true, useVQSLOD);

if (removeNonPass){
testParser.setFilterFieldPeriodToTextOnAllRecords(VCFRecord.PASS);
Expand Down
149 changes: 77 additions & 72 deletions Source/edu/utah/seq/vcf/VCFSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public class VCFSample {
private String originalFormat = null;
private String alleleCounts = null;
private String referenceCounts = null;
private String alternateCounts = null;
private double alleleFreqAF = -1;
private String[] data = null;
private String[] format = null;
private boolean missingQual = false;
private String alternateCounts = null;
private double alleleFreqAF = -1;
private String[] data = null;
private String[] format = null;
private boolean missingQual = false;

private static final Pattern PIPE = Pattern.compile("\\|");


/**Finding vcf files with mixed sample formats so must determine each record by record :(
* Add rippers as needed.*/
Expand All @@ -41,80 +41,85 @@ public VCFSample(String sample, String sampleFormat) throws Exception{
data = VCFParser.COLON.split(sample);
format = VCFParser.COLON.split(sampleFormat);
if (data.length != format.length) throw new Exception("Incorrect number of fields in sample -> "+sample+" for indicated format -> "+sampleFormat);
//attempt to parse GT, DP, GQ, AF
for (int i=0; i< format.length; i++){
if (format[i].equals("GT")) {
genotypeGT = data[i];
//replace any | with /
genotypeGT = PIPE.matcher(genotypeGT).replaceAll("/");
//replace 1/0 with 0/1
if (genotypeGT.equals("1/0")) genotypeGT = "0/1";
}
else if (format[i].equals("DP")) {
if (data[i].equals(".")) {
noCall = true;
break;
} else {
//only set if not set
if (readDepthDP == -1) readDepthDP = Integer.parseInt(data[i]);

//wrap with a try catch block since some callers insert nan in place of a number
String item = "";
try {

//attempt to parse GT, DP, GQ, AF
for (int i=0; i< format.length; i++){
item = format[i];
if (format[i].equals("GT")) {
genotypeGT = data[i];
//replace any | with /
genotypeGT = PIPE.matcher(genotypeGT).replaceAll("/");
//replace 1/0 with 0/1
if (genotypeGT.equals("1/0")) genotypeGT = "0/1";
}
}
else if (format[i].equals("AF")) {
alleleFreqAF = Double.parseDouble(data[i]);
}
else if (format[i].equals("GQ")) {
if (data[i].equals(".")) {
missingQual = true;
} else {
genotypeQualityGQ = Float.parseFloat(data[i]);
else if (format[i].equals("DP")) {
if (data[i].equals(".")) {
noCall = true;
break;
} else {
//only set if not set
if (readDepthDP == -1) readDepthDP = Integer.parseInt(data[i]);
}
}

}
else if (format[i].equals("AD")) {
alleleCounts = data[i];
String[] multiple = data[i].split(",");
if (multiple.length > 1) {
if (referenceCounts == null) referenceCounts = multiple[0];
alternateCounts = multiple[1];
//set DP, this will override anything set by DP
readDepthDP = Integer.parseInt(referenceCounts) + Integer.parseInt(alternateCounts);

} else if (multiple.length == 1) {
this.alternateCounts = multiple[0];
} else {
throw new Exception("There is no data in the 'AD' field, please make sure your file is formed correctly. If it is formed correctly, "
+ "please harass the HCI core to fix this problem");
else if (format[i].equals("AF")) {
alleleFreqAF = Double.parseDouble(data[i]);
}
else if (format[i].equals("GQ")) {
if (data[i].equals(".")) {
missingQual = true;
} else {
genotypeQualityGQ = Float.parseFloat(data[i]);
}

}
else if (format[i].equals("AD")) {
alleleCounts = data[i];
String[] multiple = data[i].split(",");
if (multiple.length > 1) {
if (referenceCounts == null) referenceCounts = multiple[0];
alternateCounts = multiple[1];
//set DP, this will override anything set by DP
readDepthDP = Integer.parseInt(referenceCounts) + Integer.parseInt(alternateCounts);

} else if (multiple.length == 1) {
this.alternateCounts = multiple[0];
} else {
throw new Exception("There is no data in the 'AD' field, please make sure your file is formed correctly. If it is formed correctly, "
+ "please harass the HCI core to fix this problem");
}
} else if (format[i].equals("RD")) {
this.referenceCounts = data[i];
}
else if (format[i].equals("DP4")) {
//# high-quality ref-forward bases, ref-reverse, alt-forward and alt-reverse bases
String[] multiple = data[i].split(",");
int rf = Integer.parseInt(multiple[0]);
int rr = Integer.parseInt(multiple[1]);
int af = Integer.parseInt(multiple[2]);
int ar = Integer.parseInt(multiple[3]);
referenceCounts = (rf+rr)+"";
alternateCounts = (af+ar)+"";
}
} else if (format[i].equals("RD")) {
this.referenceCounts = data[i];
}
else if (format[i].equals("DP4")) {
//# high-quality ref-forward bases, ref-reverse, alt-forward and alt-reverse bases
String[] multiple = data[i].split(",");
int rf = Integer.parseInt(multiple[0]);
int rr = Integer.parseInt(multiple[1]);
int af = Integer.parseInt(multiple[2]);
int ar = Integer.parseInt(multiple[3]);
referenceCounts = (rf+rr)+"";
alternateCounts = (af+ar)+"";
}
} catch (Exception e){
System.err.println("Error parsing sample data for "+sample+" skipping "+item);
}
//not all vcf records have counts! so don't require it
/*if (referenceCounts == null || alternateCounts == null) {
throw new Exception("Could not parse counts for either the reference (" + referenceCounts + ") or alternate (" + alternateCounts + ") allele.");
}*/


}
}

/**Looks in the Format for the label and returns the Sample value.*/
public String getFormatData(String label){
for (int i=0; i< format.length; i++){
if (format[i].equals(label)) return data[i];
}
return null;
}

/**Returns -1 if either ref or alt counts are null.*/
public double getAltRatio(){
if (alleleFreqAF != -1) return alleleFreqAF;
Expand All @@ -127,15 +132,15 @@ public double getAltRatio(){
}
return alleleFreqAF;
}

public String getReferenceCount() {
return referenceCounts;
}

public String getAlternateCounts() {
return alternateCounts;
}

public String getAlleleCount() {
return alleleCounts;
}
Expand All @@ -160,11 +165,11 @@ public boolean isNoCall() {
public void setNoCall(boolean noCall) {
this.noCall = noCall;
}

public String getUnmodifiedSampleString() {
return this.originalRecord;
}

public boolean isMissingQual() {
return this.missingQual;
}
Expand Down

0 comments on commit 710cfc8

Please sign in to comment.