Skip to content

Commit

Permalink
Check readgroup
Browse files Browse the repository at this point in the history
  • Loading branch information
seppinho committed Mar 2, 2024
1 parent 6b50ec3 commit 6361dea
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>genepi</groupId>
<artifactId>mutserve</artifactId>
<version>v2.0.0-rc15</version>
<version>v2.0.0-rc17</version>
<packaging>jar</packaging>

<properties>
Expand Down
87 changes: 69 additions & 18 deletions src/main/java/genepi/mut/commands/StatisticsCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package genepi.mut.commands;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -26,6 +29,9 @@ public class StatisticsCommand implements Callable<Integer> {
@Option(names = { "--input" }, description = "\"Input file", required = true)
private String input;

@Option(names = { "--mapping" }, description = "\"Mapping file", required = true)
private String mapping;

@Option(names = { "--output-excluded-samples" }, description = "\"Exclude file", required = true)
private String output;

Expand Down Expand Up @@ -74,6 +80,7 @@ public Integer call() throws IOException {

int countLowCoveredPercentage = 0;
int countMeanBaseQuality = 0;
int countNoReadGroups = 0;
int countMeanDepth = 0;
int countTooLowBaseQuality = 0;
int countTooLowMapQuality = 0;
Expand All @@ -86,10 +93,48 @@ public Integer call() throws IOException {
List<String> contigs = new ArrayList<String>();
StringBuffer text = new StringBuffer();

BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(mapping));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return -1;
}
String line;
ArrayList<String> sampleList = new ArrayList<>();

// header
reader.readLine();

while ((line = reader.readLine()) != null) {
String sampleName = line.split("\t")[0];
String fileName = line.split("\t")[1];
if (sampleList.contains(sampleName)) {
text.append("\n<b>Error:</b> Duplicate sample name for sample '" + sampleName + "' (Filename: "
+ fileName + ".<br>mtDNA analysis cannot be started!");
context.error(text.toString());
reader.close();
return -1;
}

sampleList.add(sampleName);
}
reader.close();

for (StatisticsFile sample : samples) {

if ((tool.equals("mutect2") || tool.equals("fusion")) && sample.getReadGroup() == null) {
{
countNoReadGroups++;
excludedSamples++;
excludedSamplesFile.append(
sample.getSampleName() + "\t" + "No readgroup tag (@RG) available in BAM file" + "\n");
}
}

if (sample.getSampleName() == null) {
text.append("\n<b>Error:</b> Error in sample file name. mtDNA analysis cannot be started!");
text.append("\n<b>Error:</b> Error in sample file name.<br>mtDNA analysis cannot be started!");
context.error(text.toString());
return -1;
}
Expand Down Expand Up @@ -130,27 +175,30 @@ public Integer call() throws IOException {
if (sample.getCoveredPercentage() != -1 && sample.getCoveredPercentage() < MIN_COVERAGE_PERCENTAGE) {
countLowCoveredPercentage++;
excludedSamples++;
excludedSamplesFile.append(sample.getSampleName() + "\t" + "Mean Coverage Percentage <"+ MIN_COVERAGE_PERCENTAGE +"\n");
excludedSamplesFile.append(
sample.getSampleName() + "\t" + "Mean Coverage Percentage <" + MIN_COVERAGE_PERCENTAGE + "\n");
} else if (sample.getMeanBaseQuality() != -1 && sample.getMeanBaseQuality() < MIN_MEAN_BASE_QUALITY) {
countMeanBaseQuality++;
excludedSamples++;
excludedSamplesFile.append(sample.getSampleName() + "\t" + "Mean Base Quality < "+ MIN_MEAN_BASE_QUALITY +"\n");
excludedSamplesFile
.append(sample.getSampleName() + "\t" + "Mean Base Quality < " + MIN_MEAN_BASE_QUALITY + "\n");
} else if (sample.getMeanDepth() != -1 && sample.getMeanDepth() < MIN_MEAN_DEPTH) {
countMeanDepth++;
excludedSamples++;
excludedSamplesFile.append(sample.getSampleName() + "\t" + "Mean Depth < "+ MIN_MEAN_DEPTH +"\n");
excludedSamplesFile.append(sample.getSampleName() + "\t" + "Mean Depth < " + MIN_MEAN_DEPTH + "\n");
} else if (sample.getMeanBaseQuality() != -1 && sample.getMeanBaseQuality() < baseQ) {
countTooLowBaseQuality++;
excludedSamples++;
excludedSamplesFile.append(sample.getSampleName() + "\t" + "Sample Mean Base Quality < "+ baseQ +"\n");
excludedSamplesFile
.append(sample.getSampleName() + "\t" + "Sample Mean Base Quality < " + baseQ + "\n");
} else if (sample.getMeanMapQuality() != -1 && sample.getMeanMapQuality() < mapQ) {
countTooLowBaseQuality++;
excludedSamples++;
excludedSamplesFile.append(sample.getSampleName() + "\t" + "Mapping Quality < "+ mapQ +"\n");
excludedSamplesFile.append(sample.getSampleName() + "\t" + "Mapping Quality < " + mapQ + "\n");
}

}

writer.write(excludedSamplesFile.toString());
writer.close();

Expand Down Expand Up @@ -179,7 +227,7 @@ public Integer call() throws IOException {
}

if (tool.equals("mutect2") || tool.equals("fusion")) {

boolean found = false;
for (String contig : allowed_contigs) {
if (contig.equals(contigs.get(0))) {
Expand All @@ -198,7 +246,7 @@ public Integer call() throws IOException {
if (lowestMeanDepth != -1) {
text.append("Min Mean Depth: " + lowestMeanDepth + "\n");
}
if (highgestMeanDepth != -1 && validFiles > 1) {
if (highgestMeanDepth != -1 && validFiles > 1) {
text.append("Max Mean Depth: " + highgestMeanDepth + "\n");
}

Expand All @@ -214,43 +262,46 @@ public Integer call() throws IOException {
text = new StringBuffer();

if (countMissingContigs > 0) {
text.append(countMissingContigs + " sample(s) with missing contigs have been excluded");
text.append(countMissingContigs + " sample(s) with missing contigs have been excluded.");
}

writerContig.write(contigs.get(0));
writerContig.close();

if (countLowCoveredPercentage > 0) {
text.append(countLowCoveredPercentage + " sample(s) with a coverage percentage of < "
+ MIN_COVERAGE_PERCENTAGE + " have been excluded");
+ MIN_COVERAGE_PERCENTAGE + " have been excluded.");
}
if (countMeanBaseQuality > 0) {
text.append(countMeanBaseQuality + " sample(s) with a mean base quality of < " + MIN_MEAN_BASE_QUALITY
+ " have been excluded");
+ " have been excluded.");
}

if (countNoReadGroups > 0) {
text.append(countNoReadGroups + " sample(s) with no readgroups (RG) have been excluded.");
}

if (countMeanDepth > 0) {
text.append(countMeanDepth + " sample(s) with mean depth of < " + MIN_MEAN_DEPTH
+ " have been excluded. This affects the level of heteroplasmy which can be detected.");
text.append(countMeanDepth + " sample(s) with mean depth of < " + MIN_MEAN_DEPTH + " have been excluded.");
}

if (countTooLowBaseQuality > 0) {
text.append(countTooLowBaseQuality
+ " sample(s) have been removed where the mean base quality is lower then configured base quality ("
+ baseQ + ")");
+ baseQ + ").");
}
if (countTooLowMapQuality > 0) {
text.append(countTooLowMapQuality
+ " sample(s) have been removed where the mean base quality is lower then configured base quality ("
+ mapQ + ")");
+ mapQ + ").");
}

if (text.length() > 0) {
context.warning(text.toString());
}

if (validFiles == 0) {
context.error("No input samples passed the QC step");
context.error("No input samples passed the QC step.");
return -1;
} else {
context.ok("Input Validation run succesfully, mtDNA analysis can be started.");
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/genepi/mut/objects/StatisticsFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ public class StatisticsFile {

private String sampleName;
private String contig;
private int numberOfReads = -1;;
private int coveredBases = -1;;
private int numberOfReads = -1;
private int coveredBases = -1;
private double coveredPercentage = -1;
private double meanDepth = -1;;
private double meanBaseQuality = -1;;
private double meanMapQuality = -1;;
private double meanDepth = -1;
private double meanBaseQuality = -1;
private double meanMapQuality = -1;
private String readGroup;

public String getSampleName() {
return sampleName;
Expand Down Expand Up @@ -74,4 +75,12 @@ public double getMeanMapQuality() {
public void setMeanMapQuality(double meanMapQuality) {
this.meanMapQuality = meanMapQuality;
}

public String getReadGroup() {
return readGroup;
}

public void setReadGroup(String readGroup) {
this.readGroup = readGroup;
}
}
3 changes: 3 additions & 0 deletions src/main/java/genepi/mut/util/StatisticsFileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public List<StatisticsFile> load(String input) {
case "MeanMapQuality":
file.setMeanMapQuality(Double.parseDouble(value));
break;
case "RG":
file.setReadGroup(value);
break;
}
}

Expand Down

0 comments on commit 6361dea

Please sign in to comment.