Skip to content

Commit

Permalink
Merge pull request #368 from AdamaJava/qprofiler2_longread
Browse files Browse the repository at this point in the history
Qprofiler2 longread
  • Loading branch information
felicity731 authored Jul 25, 2024
2 parents defe66e + 37e1480 commit c7b5eae
Show file tree
Hide file tree
Showing 18 changed files with 870 additions and 119 deletions.
10 changes: 8 additions & 2 deletions qprofiler2/src/org/qcmg/qprofiler2/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ final class Options {
private static final String OUTPUT_FILE_DESCRIPTION = Messages.getMessage(msgResource,"OUTPUT_FILE_DESCRIPTION");
private static final String INPUT_FILE_DESCRIPTION = Messages.getMessage(msgResource,"INPUT_FILE_DESCRIPTION");
private static final String INDEX_FILE_DESCRIPTION = Messages.getMessage(msgResource,"INDEX_FILE_DESCRIPTION");
private static final String VALIDATION_STRINGENCY_OPTION_DESCRIPTION = Messages.getMessage(msgResource,"VALIDATION_STRINGENCY_DESCRIPTION");
private static final String VALIDATION_STRINGENCY_OPTION_DESCRIPTION = Messages.getMessage(msgResource,"VALIDATION_STRINGENCY_DESCRIPTION");
private static final String LONG_READ_OPTION_DESCRIPTION = Messages.getMessage(msgResource, "LONG_READ_OPTION_DESCRIPTION");
private static final String FULL_BAMHEADER_OPTION_DESCRIPTION = Messages.getMessage(msgResource, "FULL_BAMHEADER_OPTION_DESCRIPTION");

// vcf mode
Expand Down Expand Up @@ -68,7 +69,8 @@ final class Options {
parser.accepts("bam-validation", VALIDATION_STRINGENCY_OPTION_DESCRIPTION).withRequiredArg().ofType(String.class);
parser.accepts("bam-full-header", FULL_BAMHEADER_OPTION_DESCRIPTION);
parser.accepts("vcf-format-field", FORMAT_OPTION_DESCRIPTION).withRequiredArg().ofType(String.class).withValuesSeparatedBy(',');
parser.accepts("bam-index", INDEX_FILE_DESCRIPTION).withRequiredArg().ofType(String.class).withValuesSeparatedBy(',');
parser.accepts("bam-index", INDEX_FILE_DESCRIPTION).withRequiredArg().ofType(String.class).withValuesSeparatedBy(',');
parser.accepts("long-read", LONG_READ_OPTION_DESCRIPTION);
parser.posixlyCorrect(true);
options = parser.parse(args);

Expand Down Expand Up @@ -120,6 +122,10 @@ boolean hasFullBamHeaderOption() {
return options.has("bam-full-header") ;
}

boolean hasLongReadBamOption() {
return options.has("long-read") ;
}

boolean hasVersionOption() {
return options.has("version");
}
Expand Down
10 changes: 8 additions & 2 deletions qprofiler2/src/org/qcmg/qprofiler2/QProfiler2.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class QProfiler2 {
private String logFile;
private String validation;
private boolean isFullBamHeader;
private boolean isLongReadBam;


/*
Expand Down Expand Up @@ -209,10 +210,13 @@ private Summarizer getSummarizer(ProfileType key) {
}
break;
case BAM:
if (isLongReadBam) {
logger.info("Processing long read BAM file");
}
if (noOfConsumerThreads > 0) {
summarizer = new BamSummarizerMT(noOfProducerThreads, noOfConsumerThreads, maxRecords, validation, isFullBamHeader);
summarizer = new BamSummarizerMT(noOfProducerThreads, noOfConsumerThreads, maxRecords, validation, isFullBamHeader, isLongReadBam);
} else {
summarizer = new BamSummarizer( maxRecords, validation, isFullBamHeader);
summarizer = new BamSummarizer( maxRecords, validation, isFullBamHeader, isLongReadBam);
}
break;
case XML:
Expand Down Expand Up @@ -299,6 +303,8 @@ public int setup(String args[]) throws Exception {
}

this.isFullBamHeader = options.hasFullBamHeaderOption();

this.isLongReadBam = options.hasLongReadBamOption();

// setup the ExecutorService thread pool
// the size of the pool is the smaller of the no of files, and the NO_OF_PROCESSORS variable
Expand Down
10 changes: 6 additions & 4 deletions qprofiler2/src/org/qcmg/qprofiler2/bam/BamSummarizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,26 @@ public class BamSummarizer implements Summarizer {
private int maxRecords;
private String validation;
private boolean isFullBamHeader;
private boolean isLongReadBam;

private static final QLogger logger = QLoggerFactory.getLogger(BamSummarizer.class);
public BamSummarizer() {} // default constructor
public BamSummarizer( int maxRecords, String validation, boolean isFullBamHeader) {
public BamSummarizer( int maxRecords, String validation, boolean isFullBamHeader, boolean isLongReadBam) {
this.maxRecords = maxRecords;
this.validation = validation;
this.isFullBamHeader = isFullBamHeader;
this.isLongReadBam = isLongReadBam;
}

public static BamSummaryReport createReport(SAMFileHeader header, String file, int maxRecords, boolean isFullBamHeader) throws IOException {
public static BamSummaryReport createReport(SAMFileHeader header, String file, int maxRecords, boolean isFullBamHeader, boolean isLongReadBam) throws IOException {

// create the SummaryReport

SAMSequenceDictionary samSeqDict = header.getSequenceDictionary();
// Natural order
List<String> readGroupIds = header.getReadGroups().stream().map(SAMReadGroupRecord::getId).sorted(Comparator.comparing(String::toString)).collect(toList());

BamSummaryReport bamSummaryReport = new BamSummaryReport( maxRecords, isFullBamHeader );
BamSummaryReport bamSummaryReport = new BamSummaryReport( maxRecords, isFullBamHeader, isLongReadBam );
bamSummaryReport.setBamHeader(header, isFullBamHeader);
bamSummaryReport.setSamSequenceDictionary(samSeqDict);
bamSummaryReport.setReadGroups(readGroupIds);
Expand All @@ -68,7 +70,7 @@ public SummaryReport summarize(String input, String index) throws IOException {
SamReader reader = SAMFileReaderFactory.createSAMFileReaderAsStream(input, index, vs);

// create the SummaryReport
BamSummaryReport bamSummaryReport = createReport(reader.getFileHeader(), input, maxRecords, isFullBamHeader);
BamSummaryReport bamSummaryReport = createReport(reader.getFileHeader(), input, maxRecords, isFullBamHeader, isLongReadBam);

boolean logLevelEnabled = logger.isLevelEnabled(QLevel.DEBUG);
long currentRecordCount = 0;
Expand Down
6 changes: 4 additions & 2 deletions qprofiler2/src/org/qcmg/qprofiler2/bam/BamSummarizerMT.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,18 @@ public class BamSummarizerMT implements Summarizer {
private final int maxRecords;
private final String validation;
private final boolean isFullBamHeader;
private final boolean isLongReadBam;
ValidationStringency vs;
private static final String UNMAPPED_READS = "Unmapped";

public BamSummarizerMT(int noOfProducerThreads, int noOfThreads, int maxNoOfRecords, String validation,boolean isFullBamHeader) {
public BamSummarizerMT(int noOfProducerThreads, int noOfThreads, int maxNoOfRecords, String validation,boolean isFullBamHeader, boolean isLongReadBam) {
super();
this.noOfProducerThreads = noOfProducerThreads;
this.noOfConsumerThreads = noOfThreads;
this.maxRecords = maxNoOfRecords;
this.validation = validation;
this.isFullBamHeader = isFullBamHeader;
this.isLongReadBam = isLongReadBam;
}

@Override
Expand Down Expand Up @@ -103,7 +105,7 @@ public int compare(SAMSequenceRecord o1, SAMSequenceRecord o2) {

final long start = System.currentTimeMillis();
final File file = new File(input);
final BamSummaryReport bamSummaryReport = BamSummarizer.createReport(header, input, maxRecords, isFullBamHeader );
final BamSummaryReport bamSummaryReport = BamSummarizer.createReport(header, input, maxRecords, isFullBamHeader, isLongReadBam );
logger.info("will create " + noOfConsumerThreads + " consumer threads");

final CountDownLatch pLatch = new CountDownLatch(noOfProducerThreads);
Expand Down
Loading

0 comments on commit c7b5eae

Please sign in to comment.