Skip to content

Commit ca63bf8

Browse files
authored
Merge pull request #379 from AdamaJava/qmotif_revisit
Qmotif revisit
2 parents 29d0e57 + 8266349 commit ca63bf8

20 files changed

+346
-358
lines changed

docs/qmotif/qmotif_1_2.md

Lines changed: 123 additions & 42 deletions
Large diffs are not rendered by default.

qmotif/src/org/qcmg/motif/Algorithm.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
import org.qcmg.motif.util.RegionCounter;
1515

1616
interface Algorithm {
17-
public String getName();
18-
public boolean applyTo(final SAMRecord read, Map<ChrPosition, RegionCounter> motifRefPositions);
17+
String getName();
18+
boolean applyTo(final SAMRecord read, Map<ChrPosition, RegionCounter> motifRefPositions);
1919
}

qmotif/src/org/qcmg/motif/Configuration.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.io.File;
1010
import java.util.HashSet;
1111
import java.util.List;
12-
import java.util.concurrent.atomic.AtomicLong;
12+
import java.util.concurrent.atomic.LongAdder;
1313

1414
import org.ini4j.Ini;
1515
import org.qcmg.common.model.ChrPosition;
@@ -23,13 +23,13 @@
2323
public final class Configuration {
2424
private final int numberThreads;
2525
private final File outputFile;
26-
private final HashSet<Pair<File, File>> filePairs = new HashSet<Pair<File, File>>();
26+
private final HashSet<Pair<File, File>> filePairs = new HashSet<>();
2727
private final QueryExecutor filter;
2828
private final Algorithm algorithm;
2929
private final LoggerInfo loggerInfo;
3030
private final String validation;
31-
private final AtomicLong countReadFromInput;
32-
private final AtomicLong countReadToCoverage;
31+
private final LongAdder countReadFromInput;
32+
private final LongAdder countReadToCoverage;
3333
private final List<ChrPosition> excludes;
3434
private final List<ChrPosition> includes;
3535
private final Integer windowSize;
@@ -67,7 +67,7 @@ public Configuration(final Options options) throws Exception {
6767
stageTwoMotifs = new Motifs(Boolean.parseBoolean(IniUtils.getEntry(iniFile, MotifConstants.PARAMS, MotifConstants.STAGE_2_STRING_REV_COMP)), s2Motifs.split(Constants.COMMA_STRING));
6868
}
6969

70-
mAndR = new MotifsAndRegexes(stageOneMotifs, stageOneRegex, stageTwoMotifs, stageTwoRegex, windowSize.intValue());
70+
mAndR = new MotifsAndRegexes(stageOneMotifs, stageOneRegex, stageTwoMotifs, stageTwoRegex, windowSize);
7171
algorithm = new MotifCoverageAlgorithm(mAndR);
7272

7373
// get excludes and includes
@@ -83,7 +83,7 @@ public Configuration(final Options options) throws Exception {
8383
inferFilePairings(bamFileNames, baiFileNames);
8484

8585
if (options.hasNumberThreadsOption()) {
86-
numberThreads = options.getNumberThreads().intValue();
86+
numberThreads = options.getNumberThreads();
8787
} else {
8888
numberThreads = 1;
8989
}
@@ -96,8 +96,8 @@ public Configuration(final Options options) throws Exception {
9696

9797
outputFile = new File(options.getOutputXmlFileName());
9898
checkFileExistence();
99-
countReadFromInput = new AtomicLong();
100-
countReadToCoverage = new AtomicLong();
99+
countReadFromInput = new LongAdder();
100+
countReadToCoverage = new LongAdder();
101101

102102
String includesOnlyModeS = IniUtils.getEntry(iniFile, MotifConstants.PARAMS, MotifConstants.INCLUDES_ONLY_MODE);
103103
if (null != includesOnlyModeS) {
@@ -106,22 +106,18 @@ public Configuration(final Options options) throws Exception {
106106

107107
}
108108

109-
public AtomicLong getInputReadsCount(){
109+
public LongAdder getInputReadsCount(){
110110
return countReadFromInput;
111111
}
112112

113-
public AtomicLong getCoverageReadsCount(){
113+
public LongAdder getCoverageReadsCount(){
114114
return countReadToCoverage;
115115
}
116116

117117
public int getNumberThreads() {
118118
return numberThreads;
119119
}
120120

121-
public File getOutputFile() {
122-
return outputFile;
123-
}
124-
125121
public HashSet<Pair<File, File>> getFilePairs() {
126122
return filePairs;
127123
}

qmotif/src/org/qcmg/motif/CoverageJob.java

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
import java.util.Iterator;
1313
import java.util.List;
1414
import java.util.Map;
15-
import java.util.concurrent.atomic.AtomicLong;
16-
import java.util.regex.Pattern;
15+
import java.util.concurrent.atomic.LongAdder;
1716

1817
import htsjdk.samtools.SamReader;
1918
import htsjdk.samtools.SAMRecord;
@@ -33,44 +32,39 @@ class CoverageJob implements Job {
3332
private final ChrPosition cp;
3433
private final QLogger logger;
3534
private final QueryExecutor filter;
36-
private final HashSet<SamReader> fileReaders = new HashSet<SamReader>();
35+
private final HashSet<File> fileReaders = new HashSet<>();
3736
private final Algorithm alg;
38-
private final AtomicLong counterIn;
39-
private final AtomicLong counterOut;
37+
private final LongAdder counterIn;
38+
private final LongAdder counterOut;
4039
private final List<ChrPosition> includes;
4140
private final List<ChrPosition> excludes;
4241
private Map<ChrPosition, RegionCounter> chrSpecificRegions;
4342
private int windowSize = 1000000; // default to a mill
4443
private final AbstractQueue<SAMRecord> outputQueue;
44+
String validation;
4545

4646
CoverageJob(final ChrPosition cp,
4747
final HashSet<Pair<File, File>> filePairs, final QueryExecutor filter,
48-
final Algorithm algorithm, final AtomicLong counterIn,final AtomicLong counterOut,
49-
Integer windowSize, Pattern regex, AbstractQueue<SAMRecord> outputQueue) throws Exception {
50-
this(cp, filePairs, filter, algorithm, counterIn, counterOut, null, windowSize, outputQueue, null, null);
51-
}
52-
CoverageJob(final ChrPosition cp,
53-
final HashSet<Pair<File, File>> filePairs, final QueryExecutor filter,
54-
final Algorithm algorithm, final AtomicLong counterIn, final AtomicLong counterOut, final String validation,
48+
final Algorithm algorithm, final LongAdder counterIn, final LongAdder counterOut, final String validation,
5549
Integer windowSize, AbstractQueue<SAMRecord> outputQueue,
56-
List<ChrPosition> includes, List<ChrPosition> excludes) throws Exception {
50+
List<ChrPosition> includes, List<ChrPosition> excludes) {
5751
assert (cp.getLength() > -1);
5852
this.cp = cp;
5953
this.alg = algorithm;
54+
this.validation = validation;
6055
this.counterIn = counterIn;
6156
this.counterOut = counterOut;
6257
this.filter = filter;
6358
this.logger = QLoggerFactory.getLogger(CoverageJob.class);
6459
this.includes = includes;
6560
this.excludes = excludes;
6661
if (null != windowSize) {
67-
this.windowSize = windowSize.intValue();
62+
this.windowSize = windowSize;
6863
}
6964
this.outputQueue = outputQueue;
7065
for (final Pair<File, File> pair : filePairs) {
7166
File bamFile = pair.left();
72-
SamReader reader = SAMFileReaderFactory.createSAMFileReader(bamFile, validation);
73-
fileReaders.add(reader);
67+
fileReaders.add(bamFile);
7468
}
7569
logger.debug("Length of sequence to be processed by job '" + cp.toIGVString() + " : " + cp.getLength());
7670
}
@@ -110,15 +104,15 @@ void constructCoverageMap() {
110104
}
111105

112106
private void performCoverage() throws Exception {
113-
for (final SamReader fileReader : fileReaders) {
114-
107+
for (final File file : fileReaders) {
108+
SamReader fileReader = SAMFileReaderFactory.createSAMFileReader(file, validation);
115109
Iterator<SAMRecord> iter = "unmapped".equals(cp.getChromosome()) ? fileReader.queryUnmapped() : fileReader.query(cp.getChromosome(), cp.getStartPosition(), cp.getEndPosition(), true);
116110
long recordCounterIn = 0;
117111
long recordCounterOut = 0;
118112
while (iter.hasNext()) {
119113
SAMRecord read = iter.next();
120114

121-
counterIn.incrementAndGet(); //count input read number
115+
counterIn.increment(); //count input read number
122116

123117
if (++recordCounterIn % 10000000 == 0) {
124118
logger.debug("Hit " + recordCounterIn + " record for " + cp.toIGVString());
@@ -127,26 +121,25 @@ private void performCoverage() throws Exception {
127121
if (MotifConstants.UNMAPPED.equals(cp.getChromosome()) || read.getReferenceName().equals(cp.getChromosome())) {
128122
if (null == filter) {
129123
recordCounterOut ++;
130-
counterOut.incrementAndGet(); //count output read number
124+
counterOut.increment(); //count output read number
131125
if (alg.applyTo(read, chrSpecificRegions)) outputQueue.add(read);
132126
} else if (filter.Execute(read)) {
133127
recordCounterOut ++;
134-
counterOut.incrementAndGet(); //count output read number
128+
counterOut.increment(); //count output read number
135129
if (alg.applyTo(read, chrSpecificRegions)) outputQueue.add(read);
136130
}
137131
} else {
138132
logger.info("ref names did not match!");
139133
}
140134
}
141135
fileReader.close();
136+
137+
String sb = cp.toIGVString() + ":\n" +
138+
"read " + recordCounterIn + " records, of which " + recordCounterOut + " satisfied the query\n" +
139+
"number in counterIn instance is: " + counterIn.longValue() + "\n" +
140+
"number in counterOut instance is: " + counterOut.longValue() + "\n";
142141

143-
StringBuilder sb = new StringBuilder();
144-
sb.append(cp.toIGVString()).append(":\n");
145-
sb.append("read ").append(recordCounterIn).append(" records, of which ").append(recordCounterOut).append(" satisfied the query\n");
146-
sb.append("number in counterIn instance is: ").append(counterIn.get()).append("\n");
147-
sb.append("number in counterOut instance is: ").append(counterOut.get()).append("\n");
148-
149-
logger.info(sb.toString());
142+
logger.info(sb);
150143
}
151144
}
152145
}

qmotif/src/org/qcmg/motif/Job.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
import java.util.Map;
1010

1111
import org.qcmg.common.model.ChrPosition;
12-
import org.qcmg.common.model.ChrRangePosition;
1312
import org.qcmg.motif.util.RegionCounter;
1413

1514
interface Job {
16-
public Map<ChrPosition, RegionCounter> getResults();
17-
public void run() throws Exception;
15+
Map<ChrPosition, RegionCounter> getResults();
16+
void run() throws Exception;
1817
@Override
19-
public String toString();
18+
String toString();
2019
}

0 commit comments

Comments
 (0)