Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Write out SV callers as array (#81)
Browse files Browse the repository at this point in the history
Closes: #81
Related-Issue: #81
Projected-Results-Impact: none
  • Loading branch information
holtgrewe committed Sep 20, 2022
1 parent 2647211 commit eb5ba35
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 253 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Writing out proper SV type for Dragen CNV (#76)
- Adding support for depth of coverage annotation (#73)
- Ensure output files are sorted by chromosomes (#79)
- Write out SV callers as array (#81)

## v0.26

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ private void checkOptOutFeatures() {
ImmutableList.of(
GtRecordBuilder.FEATURE_CHROM2_COLUMNS,
GtRecordBuilder.FEATURE_DBCOUNTS_COLUMNS,
GtRecordBuilder.FEATURE_SUPPRESS_CARRIER_COUNTS);
GtRecordBuilder.FEATURE_SUPPRESS_CARRIER_COUNTS,
GtRecordBuilder.FEATURE_CALLER_STRING,
GtRecordBuilder.FEATURE_CALLERS_ARRAY
);
final String features[] = args.getOptOutFeatures().split(",");
boolean allGood = true;
for (String feature : features) {
Expand Down Expand Up @@ -332,7 +335,9 @@ private void annotateSvVcf(
gtWriter.append(
GenotypeRecord.tsvHeader(
!args.getOptOutFeatures().contains(GtRecordBuilder.FEATURE_CHROM2_COLUMNS),
!args.getOptOutFeatures().contains(GtRecordBuilder.FEATURE_DBCOUNTS_COLUMNS))
!args.getOptOutFeatures().contains(GtRecordBuilder.FEATURE_DBCOUNTS_COLUMNS),
!args.getOptOutFeatures().contains(GtRecordBuilder.FEATURE_CALLER_STRING),
!args.getOptOutFeatures().contains(GtRecordBuilder.FEATURE_CALLERS_ARRAY))
+ "\n");
// Write feature-effects header.
featureEffectsWriter.append(Joiner.on("\t").join(HEADERS_FEATURE_EFFECTS) + "\n");
Expand Down Expand Up @@ -573,7 +578,9 @@ private void annotateVariantContext(
gtWriter.append(
gtOutRec.toTsv(
!args.getOptOutFeatures().contains(GtRecordBuilder.FEATURE_CHROM2_COLUMNS),
!args.getOptOutFeatures().contains(GtRecordBuilder.FEATURE_DBCOUNTS_COLUMNS))
!args.getOptOutFeatures().contains(GtRecordBuilder.FEATURE_DBCOUNTS_COLUMNS),
!args.getOptOutFeatures().contains(GtRecordBuilder.FEATURE_CALLER_STRING),
!args.getOptOutFeatures().contains(GtRecordBuilder.FEATURE_CALLERS_ARRAY))
+ "\n");
} catch (IOException e) {
throw new VarfishAnnotatorException("Problem writing to genotypes call file.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

Expand All @@ -18,7 +19,7 @@ public class GenotypeRecord {
private static final ImmutableList<String> HEADERS_GT_PART_2 =
ImmutableList.of("chromosome2", "chromosome_no2", "bin2", "pe_orientation");
/** Header fields for the SV and genotype file (part 3). */
private static final ImmutableList<String> HEADERS_GT_PART_3 =
private static final ImmutableList<String> HEADERS_GT_PART_3_1 =
ImmutableList.of(
"start",
"end",
Expand All @@ -28,8 +29,9 @@ public class GenotypeRecord {
"end_ci_right",
"case_id",
"set_id",
"sv_uuid",
"caller",
"sv_uuid");

private static final ImmutableList<String> HEADERS_GT_PART_3_2 = ImmutableList.of(
"sv_type",
"sv_sub_type",
"info");
Expand Down Expand Up @@ -57,6 +59,7 @@ public class GenotypeRecord {
private final String setId;
private final String svUuid;
private final String caller;
private final ImmutableList<String> callers;
private final String svType;
private final String svSubType;
private final ImmutableMap<String, Object> info;
Expand Down Expand Up @@ -87,6 +90,7 @@ public GenotypeRecord(
String setId,
String svUuid,
String caller,
Collection<String> callers,
String svType,
String svSubType,
Map<String, Object> info,
Expand Down Expand Up @@ -114,6 +118,7 @@ public GenotypeRecord(
this.setId = setId;
this.svUuid = svUuid;
this.caller = caller;
this.callers = ImmutableList.copyOf(callers);
this.svType = svType;
this.svSubType = svSubType;
this.info = ImmutableMap.copyOf(info);
Expand All @@ -125,22 +130,29 @@ public GenotypeRecord(
this.genotype = ImmutableMap.copyOf(genotype);
}

public static String tsvHeader(boolean showChrom2Columns, boolean showDbCountColumns) {
public static String tsvHeader(boolean showChrom2Columns, boolean showDbCountColumns, boolean showCallerStringColumn, boolean showCallersArrayColumn) {
// (Conditionally) write genotype header.
final List<java.lang.String> headers = new ArrayList<>();
headers.addAll(HEADERS_GT_PART_1);
if (showChrom2Columns) {
headers.addAll(HEADERS_GT_PART_2);
}
headers.addAll(HEADERS_GT_PART_3);
headers.addAll(HEADERS_GT_PART_3_1);
if (showCallerStringColumn) {
headers.add("caller");
}
if (showCallersArrayColumn) {
headers.add("callers");
}
headers.addAll(HEADERS_GT_PART_3_2);
if (showDbCountColumns) {
headers.addAll(HEADERS_GT_PART_4);
}
headers.addAll(HEADERS_GT_PART_5);
return Joiner.on("\t").join(headers);
}

public String toTsv(boolean showChrom2Columns, boolean showDbCountColumns) {
public String toTsv(boolean showChrom2Columns, boolean showDbCountColumns, boolean showCallerStringColumn, boolean showCallersArrayColumn) {
final ImmutableList.Builder builder = ImmutableList.builder();
builder.add(release, chromosome, chromosomeNo, bin);
if (showChrom2Columns) {
Expand All @@ -155,9 +167,27 @@ public String toTsv(boolean showChrom2Columns, boolean showDbCountColumns) {
endCiRight,
caseId,
setId,
svUuid,
caller,
svType,
svUuid);
if (showCallerStringColumn) {
builder.add(caller);
}
if (showCallersArrayColumn) {
final ImmutableList.Builder<String> innerBuilder = ImmutableList.builder();
innerBuilder.add("{");
boolean first = true;
for (String caller: callers) {
if (!first) {
innerBuilder.add(",");
}
innerBuilder.add("\"");
innerBuilder.add(caller);
innerBuilder.add("\"");
first = false;
}
innerBuilder.add("}");
builder.add(Joiner.on("").join(innerBuilder.build()));
}
builder.add(svType,
svSubType);
builder.add(convert(info));
if (showDbCountColumns) {
Expand Down Expand Up @@ -281,6 +311,10 @@ public String getCaller() {
return caller;
}

public ImmutableList<String> getCallers() {
return callers;
}

public String getSvType() {
return svType;
}
Expand Down Expand Up @@ -361,9 +395,12 @@ public String toString() {
+ ", svUuid='"
+ svUuid
+ '\''
+ ", caller='"
+ caller
+ '\''
+ ", caller='"
+ caller
+ '\''
+ ", callers='"
+ callers
+ '\''
+ ", svType='"
+ svType
+ '\''
Expand Down Expand Up @@ -414,7 +451,8 @@ && getEndCiRight() == that.getEndCiRight()
&& Objects.equal(getCaseId(), that.getCaseId())
&& Objects.equal(getSetId(), that.getSetId())
&& Objects.equal(getSvUuid(), that.getSvUuid())
&& Objects.equal(getCaller(), that.getCaller())
&& Objects.equal(getCaller(), that.getCaller())
&& Objects.equal(getCallers(), that.getCallers())
&& Objects.equal(getSvType(), that.getSvType())
&& Objects.equal(getSvSubType(), that.getSvSubType())
&& Objects.equal(getInfo(), that.getInfo())
Expand Down Expand Up @@ -442,6 +480,7 @@ public int hashCode() {
getSetId(),
getSvUuid(),
getCaller(),
callers,
getSvType(),
getSvSubType(),
getInfo(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.github.bihealth.varfish_annotator.annotate_svs;

import java.util.Map;
import java.util.TreeMap;
import com.google.common.collect.ImmutableList;

import java.util.*;

/** Helper for building {@code GenotypeRecord} objects. */
public class GenotypeRecordBuilder {
Expand All @@ -23,6 +24,7 @@ public class GenotypeRecordBuilder {
private String setId;
private String svUuid;
private String caller;
private List<String> callers = new ArrayList<>();
private String svType;
private String svSubType;
private Map<String, Object> info = new TreeMap();
Expand Down Expand Up @@ -54,6 +56,7 @@ public GenotypeRecord build() {
setId,
svUuid,
caller,
callers,
svType,
svSubType,
info,
Expand Down Expand Up @@ -205,10 +208,19 @@ public String getCaller() {
return caller;
}

public List<String> getCallers() {
return callers;
}

public void setCaller(String caller) {
this.caller = caller;
}

public void setCallers(Collection<String> callers) {
this.callers= new ArrayList<>();
this.callers.addAll(callers);
}

public String getSvType() {
return svType;
}
Expand Down Expand Up @@ -327,9 +339,12 @@ public String toString() {
+ ", svUuid='"
+ svUuid
+ '\''
+ ", caller='"
+ caller
+ '\''
+ ", caller='"
+ caller
+ '\''
+ ", callers='"
+ callers
+ '\''
+ ", svType='"
+ svType
+ '\''
Expand Down
Loading

0 comments on commit eb5ba35

Please sign in to comment.