Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
299 changes: 299 additions & 0 deletions adama/licenses/eclipselink_MOXy-LICENSE.txt

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions adama/licenses/jakarta.xml.bind-LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Eclipse Distribution License - v 1.0

Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
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.
Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
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.
5 changes: 5 additions & 0 deletions qcoverage/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ dependencies {
implementation project(':qbamfilter')
implementation project(':qpicard')
implementation 'net.sf.jopt-simple:jopt-simple:4.6'
// https://mvnrepository.com/artifact/jakarta.xml.bind/jakarta.xml.bind-api
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:3.0.1'
// https://mvnrepository.com/artifact/org.eclipse.persistence/org.eclipse.persistence.moxy
implementation 'org.eclipse.persistence:org.eclipse.persistence.moxy:3.0.3'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does using this require that we add any license to adama/licenses ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks - have added the EPL and EDL for MOXy and EDL for jakarta

}

81 changes: 35 additions & 46 deletions qcoverage/src/org/qcmg/coverage/Coverage.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,9 @@
*/
package org.qcmg.coverage;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.math.BigInteger;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Marshaller;
import org.eclipse.persistence.jaxb.JAXBContextFactory;
import org.qcmg.common.log.QLogger;
import org.qcmg.common.log.QLoggerFactory;
import org.qcmg.common.meta.QExec;
Expand All @@ -33,24 +21,31 @@
import org.qcmg.common.vcf.header.VcfHeaderUtils;
import org.qcmg.qio.record.RecordWriter;

import java.io.*;
import java.math.BigInteger;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

public final class Coverage {
private final Options options;
private final Configuration invariants;
private final JobQueue jobQueue;

public Coverage(final Options options) throws Exception {
options.detectBadOptions();
this.options = options;
invariants = new Configuration(options);
Configuration invariants = new Configuration(options);
jobQueue = new JobQueue(invariants);
saveCoverageReport();
}

/**
* check output file extension whether match format
* @param fname is the input file name
* @param format is the input file requied format, eg. txt, xml and vcf
* @return return corrected output file name which extension match the formate
* @param format is the input file required format, e.g. txt, xml and vcf
* @return return corrected output file name which extension match the format
*/
private String fileNameCorrection(String fname, String format) {
String extension = format.startsWith(".")?
Expand All @@ -63,15 +58,15 @@ private String fileNameCorrection(String fname, String format) {
private void writePerFeatureTabDelimitedCoverageReport( final QCoverageStats stats) throws IOException {
String foutput = fileNameCorrection(options.getOutputFileNames()[0], "txt");
final File file = new File(foutput);
try (final BufferedWriter out = new BufferedWriter(new FileWriter(file));) {
try (final BufferedWriter out = new BufferedWriter(new FileWriter(file))) {
out.write("#coveragetype\tnumberofbases\tcoverage\n");
final CoverageComparator comparator = new CoverageComparator();
for (final CoverageReport report : stats.getCoverageReport()) {
final String type = report.getType().toString().toLowerCase();
final String feature = report.getFeature();
out.write("#" + feature + StringUtils.RETURN);
final List<CoverageModel> coverages = report.getCoverage();
Collections.sort(coverages, comparator);
coverages.sort(comparator);
for (final CoverageModel coverage : coverages) {
final BigInteger bases = coverage.getBases();
final String atCoverage = coverage.getAt() + "x";
Expand All @@ -85,14 +80,14 @@ private void writePerFeatureTabDelimitedCoverageReport( final QCoverageStats sta
private void writePerTypeTabDelimitedCoverageReport(final QCoverageStats stats) throws IOException {
String foutput = fileNameCorrection(options.getOutputFileNames()[0], "txt");
final File file = new File(foutput);
try (final BufferedWriter out = new BufferedWriter(new FileWriter(file));) {
try (final BufferedWriter out = new BufferedWriter(new FileWriter(file))) {
out.write("#coveragetype\tfeaturetype\tnumberofbases\tcoverage\n");
final CoverageComparator comparator = new CoverageComparator();
for (final CoverageReport report : stats.getCoverageReport()) {
final String type = report.getType().toString().toLowerCase();
final String feature = report.getFeature();
final List<CoverageModel> coverages = report.getCoverage();
Collections.sort(coverages, comparator);
coverages.sort(comparator);
for (final CoverageModel coverage : coverages) {
final BigInteger bases = coverage.getBases();
final String atCoverage = coverage.getAt() + "x";
Expand All @@ -104,25 +99,29 @@ private void writePerTypeTabDelimitedCoverageReport(final QCoverageStats stats)
}
}

private void writeXMLCoverageReport(final QCoverageStats report) throws Exception {
final JAXBContext context = JAXBContext.newInstance(QCoverageStats.class);
private void writeXMLCoverageReport(final QCoverageStats report) throws JAXBException, IOException {
writeXMLCoverageReport(report, fileNameCorrection(options.getOutputFileNames()[0], "xml"));
}

public static void writeXMLCoverageReport(final QCoverageStats report, String outputFile) throws IOException, jakarta.xml.bind.JAXBException {
jakarta.xml.bind.JAXBContext context = JAXBContextFactory
.createContext(new Class[] {CoverageReport.class, CoverageModel.class, QCoverageStats.class}, null);
final Marshaller m = context.createMarshaller();
final StringWriter sw = new StringWriter();
m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(report, sw);
String foutput = fileNameCorrection(options.getOutputFileNames()[0], "xml");
final File file = new File(foutput);
try (final FileWriter fileWriter = new FileWriter(file);) {
final File file = new File(outputFile);
try (final FileWriter fileWriter = new FileWriter(file)) {
fileWriter.write(sw.toString());
}
}

private void writeVCFReport(final QCoverageStats report) throws Exception {
String foutput = fileNameCorrection(options.getOutputFileNames()[0], "vcf");
final File file = new File(foutput);

final List<VcfRecord> vcfs = new ArrayList<VcfRecord>();
final List<VcfRecord> vcfs = new ArrayList<>();

for (final CoverageReport cr : report.getCoverageReport()) {
if (cr.getFeature().contains("\t")) {
Expand All @@ -132,11 +131,11 @@ private void writeVCFReport(final QCoverageStats report) throws Exception {
}

if ( ! vcfs.isEmpty()) {
Collections.sort(vcfs, new VcfPositionComparator());
vcfs.sort(new VcfPositionComparator());
try(final RecordWriter<VcfRecord> writer = new RecordWriter<>(file)) {
final VcfHeader header = getHeaderForQCoverage(options.getBAMFileNames()[0], options.getInputGFF3FileNames()[0]);
for(final VcfHeaderRecord record: header) {
writer.addHeader(record.toString()+"\n");
writer.addHeader(record.toString() + "\n");
}
for (final VcfRecord vcf : vcfs) {
writer.add(vcf);
Expand All @@ -147,7 +146,7 @@ private void writeVCFReport(final QCoverageStats report) throws Exception {
}

//create vcf output header
private VcfHeader getHeaderForQCoverage(final String bamFileName, final String gffFile) throws Exception {
private VcfHeader getHeaderForQCoverage(final String bamFileName, final String gffFile) {
final VcfHeader header = new VcfHeader();
final DateFormat df = new SimpleDateFormat("yyyyMMdd");
final String version = Coverage.class.getPackage().getImplementationVersion();
Expand All @@ -174,16 +173,15 @@ private VcfHeader getHeaderForQCoverage(final String bamFileName, final String
}


private static VcfRecord convertCoverageToVCFRecord(org.qcmg.coverage.CoverageReport covReport) throws Exception {
private static VcfRecord convertCoverageToVCFRecord(org.qcmg.coverage.CoverageReport covReport) {

// tab delimited string containing loads of useful stuff
final String feature = covReport.getFeature();
// if there are no tabs in the string, the per-feature flag was not set
final String[] params = TabTokenizer.tokenize(feature);

final VcfRecord vcf = new VcfRecord.Builder(params[0], Integer.parseInt(params[3])).build();
//VcfUtils.createVcfRecord(params[0], Integer.parseInt(params[3]), null);


// info field will contain coverage details
int zeroCov = 0, nonZeroCov = 0, totalCov = 0;
for (final CoverageModel c : covReport.getCoverage()) {
Expand Down Expand Up @@ -257,13 +255,7 @@ public static void main(final String[] args) throws Exception {
}

private static String chooseErrorMessage(Throwable e) {
String message = null;
if (null == e.getMessage()) {
message = "Unknown error";
} else {
message = e.getMessage();
}
return message;
return null == e.getMessage() ? "Unknown error" : e.getMessage();
}

private static void logErrorMessage(final String errorMessage,
Expand Down Expand Up @@ -296,7 +288,4 @@ static String getProgramVersion() {
return Coverage.class.getPackage().getImplementationVersion();
}

static String getVersionMessage() throws Exception {
return getProgramName() + ", version " + getProgramVersion();
}
}
15 changes: 10 additions & 5 deletions qcoverage/src/org/qcmg/coverage/CoverageModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
*/
package org.qcmg.coverage;

import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlType;
import org.eclipse.persistence.oxm.annotations.XmlNameTransformer;

import java.math.BigInteger;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
//import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
//import javax.xml.bind.annotation.XmlType;

@XmlAccessorType(XmlAccessType.FIELD)
//@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Coverage")

@XmlNameTransformer(NameGenerator.class)
public class CoverageModel {

public BigInteger getBases() {
Expand All @@ -30,7 +35,7 @@ public void setAt(String at) {
}

@XmlAttribute(name = "bases", required = true)
@XmlSchemaType(name = "positiveInteger")
// @XmlSchemaType(name = "positiveInteger")
protected BigInteger bases;
@XmlAttribute(name = "at", required = true)
protected String at;
Expand Down
16 changes: 9 additions & 7 deletions qcoverage/src/org/qcmg/coverage/CoverageReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

import java.util.ArrayList;
import java.util.List;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
//import javax.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

@XmlAccessorType(XmlAccessType.FIELD)
Expand All @@ -19,11 +21,11 @@
public class CoverageReport {

@XmlElement(required = true)
protected List<CoverageModel> coverage;
private List<CoverageModel> coverage;
@XmlAttribute(name = "feature", required = true)
protected String feature;
private String feature;
@XmlAttribute(name = "type", required = true)
protected CoverageType type;
private CoverageType type;

/**
* Gets the value of the coverage property.
Expand Down
28 changes: 28 additions & 0 deletions qcoverage/src/org/qcmg/coverage/NameGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.qcmg.coverage;

public class NameGenerator implements org.eclipse.persistence.oxm.XMLNameTransformer {
@Override
public String transformTypeName(String s) {
return s;
}

@Override
public String transformElementName(String s) {
return s;
}

@Override
public String transformAttributeName(String s) {
return s;
}

@Override
// Use the unqualified class name as our root element name.
public String transformRootElementName(String name) {
String shortName = name.substring(name.lastIndexOf('.') + 1);
if ("CoverageModel".equals(shortName)) {
return "coverage";
}
return shortName;
}
}
13 changes: 7 additions & 6 deletions qcoverage/src/org/qcmg/coverage/QCoverageStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlType;
import org.eclipse.persistence.oxm.annotations.XmlNameTransformer;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
@XmlType(name = "QCoverageStats", propOrder = {
"coverageReport"
})
@XmlRootElement(name = "QCoverageStats")
@XmlRootElement
@XmlNameTransformer(NameGenerator.class)
public class QCoverageStats {

@XmlElement(required = true)
Expand Down
Loading