Skip to content

Commit

Permalink
Merge branch 'main' into refactoring/output-format
Browse files Browse the repository at this point in the history
  • Loading branch information
seppinho authored Jul 17, 2024
2 parents 442473d + d9db84e commit e867c5d
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<dependency>
<groupId>com.github.samtools</groupId>
<artifactId>htsjdk</artifactId>
<version>2.21.3</version>
<version>3.0.5</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ private boolean analyzeFiles() {
double sampleCallrate = panel.getQcFilterByKey("sampleCallrate");
double mixedGenotypesChrX = panel.getQcFilterByKey("mixedGenotypeschrX");
int strandFlips = (int) (panel.getQcFilterByKey("strandFlips"));
int alleleSwitches = (int) (panel.getQcFilterByKey("alleleSwitches"));
String ranges = panel.getRange();

if (ranges != null) {
HashSet<RangeEntry> rangeEntries = new HashSet<RangeEntry>();

Expand Down Expand Up @@ -379,6 +380,15 @@ else if (task.getStrandFlipSimple() + task.getStrandFlipAndAlleleSwitch() > stra
return false;
}

// Check if too many allele switches are detected
else if (task.getAlleleSwitch() + task.getStrandFlipAndAlleleSwitch() > alleleSwitches) {
text.append("<br><b>Error:</b> More than " + alleleSwitches
+ " allele switches have been detected. Imputation cannot be started!");
context.error(text.toString());

return false;
}

else if (task.isChrXMissingRate()) {
text.add(
"\n<b>Error:</b> Chromosome X nonPAR region includes > 10 % mixed genotypes. Imputation cannot be started!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class StatisticsTask implements ITask {

private boolean chrXMissingRate = false;
private boolean chrXPloidyError = false;

// chunk results
private int removedChunksSnps;
private int removedChunksOverlap;
Expand Down Expand Up @@ -474,12 +474,11 @@ else if (GenomicTools.alleleSwitch(snp, refSnp)) {
if (insideChunk) {

alleleSwitch++;
/*
* logWriter.write("Allele switch" + snp.getID() + "\t" + chr + ":"+
* snp.getStart() + "\t" + "ref: " + legendRef + "/" + legendAlt + "; data: " +
* studyRef + "/" + studyAlt + ")");
*/
filtered++;
excludedSnpsWriter.write(snp + "\t" + "Allele switch" + "\t" + "Ref:" + legendRef + "/" + legendAlt);

}
return;

}

Expand Down
25 changes: 18 additions & 7 deletions src/main/java/genepi/imputationserver/util/RefPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

public class RefPanel {

public static final String ALLELE_SWITCHES = String.valueOf(Integer.MAX_VALUE);
public static final String STRAND_FLIPS = "100";
public static final String SAMPLE_CALL_RATE = "0.5";
public static final String MIN_SNPS = "3";
Expand Down Expand Up @@ -57,6 +58,7 @@ public RefPanel() {
defaultQcFilter.put("sampleCallrate", SAMPLE_CALL_RATE);
defaultQcFilter.put("mixedGenotypeschrX", CHR_X_MIXED_GENOTYPES);
defaultQcFilter.put("strandFlips", STRAND_FLIPS);
defaultQcFilter.put("alleleSwitches", ALLELE_SWITCHES);
}

public String getId() {
Expand Down Expand Up @@ -127,7 +129,7 @@ public int getSamplesByPopulation(String population) {
if (population == null) {
return 0;
}

RefPanelPopulation panelPopulation = getPopulation(population);
if (panelPopulation != null) {
return panelPopulation.getSamples();
Expand All @@ -147,7 +149,7 @@ public List<RefPanelPopulation> getPopulations() {
public boolean supportsPopulation(String population) {
if (population == null || population.equals("")) {
return true;
}
}
return (getPopulation(population) != null);
}

Expand All @@ -169,15 +171,24 @@ public Map<String, String> getQcFilter() {
}

public double getQcFilterByKey(String key) {

if (qcFilter == null) {
qcFilter = defaultQcFilter;
}
String n = qcFilter.get(key);
if (n != null) {
return Double.parseDouble(n);
} else {
Object n = qcFilter.get(key);

if (n == null) {
return Double.parseDouble(defaultQcFilter.get(key));
}

if (n instanceof String) {
return Double.parseDouble((String) n);
} else if (n instanceof Number) {
return ((Number) n).doubleValue();
} else {
throw new IllegalArgumentException("Value associated with key is neither a String nor a Number: " + n);
}

}

public void setQcFilter(Map<String, String> qcFilter) {
Expand Down Expand Up @@ -257,7 +268,7 @@ public static RefPanel fromProperties(Object properties) throws IOException {
if (map.get("reference_build") != null) {
panel.setBuild(map.get("reference_build").toString());
}

if (map.get("build") != null) {
panel.setBuild(map.get("build").toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,27 @@ public void testQcStatisticsDontAllowStrandFlips() throws Exception {

}

@Test
public void testQcStatisticsDontAllowAlleleSwitches() throws Exception {

String panels = "test-data/configs/hapmap-3chr/panels.txt";
String inputFolder = "test-data/data/simulated-chip-3chr-imputation-switches";

// create workflow context
RefPanel panel = RefPanel.loadFromYamlFile(panels, "hapmap2-qcfilter-alleleswitches");

QualityControlCommand command = buildCommand(inputFolder);
command.setRefPanel(panel);
assertEquals(-1, (int) command.call());

CloudgeneReport log = new CloudgeneReport(CLOUDGENE_LOG);

// check statistics
assertTrue(log.hasInMemory("Excluded sites in total: 121,176"));
assertTrue(log.hasInMemory("Allele switch: 118,209"));
assertTrue(log.hasInMemory("No chunks passed the QC step. Imputation cannot be started!"));
}

@Test
public void testQcStatisticsFilterOverlap() throws Exception {

Expand Down
15 changes: 15 additions & 0 deletions test-data/configs/hapmap-3chr/panels.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@
strandFlips: 100
minSnps: 1000

- id: hapmap2-qcfilter-alleleswitches
genotypes: ${app_local_folder}/ref-panels/hapmap_r22.chr$chr.CEU.hg19.msav
legend: ${app_local_folder}/ref-panels/hapmap_r22.chr$chr.CEU.hg19_impute.legend.gz
mapEagle: ${app_local_folder}/ref-panels/genetic_map_hg19_chr1.txt
refEagle: ${app_local_folder}/ref-panels/hapmap_r22.eagle/hapmap_r22.chr$chr.CEU.hg19.recode.bcf
populations:
- id: eur
name: EUR
samples: 60
- id: mixed
name: Mixed
samples: -1
qcFilter:
alleleSwitches: 33

- id: hapmap2-qcfilter-low-callrate
reference_build: hg19
genotypes: ${app_local_folder}/ref-panels/hapmap_r22.chr$chr.CEU.hg19.m3vcf.gz
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit e867c5d

Please sign in to comment.