Skip to content

Commit 9250d87

Browse files
committed
implement read aspect with 3' ends
Relating to issue #70, this commit separates out the "Read Output" selection into the Read Output:{read1, read2, allreads} and the Read Aspect:{5prime, 3prime, midpoint}. This new feature has been checked on some simple test data for 3' end. This sets the new parameter structure for filling in with new features. PileupParameters -`ASPECT` variable added with descriptive comment and getter/setter methods -`READ` variable's descriptive comments updated to remove "midpoint" -`printall()` method updated to include `ASPECT` variable PileupExtract -Midpoint parameter check changed from `param.getRead() == 3` to `param.getAspect() == 2` -Setting `mark` value now accounts for Read Aspect selected: -select start/left mark or end/right mark as appropriate for Read Aspect and reference strand values -Two places in the code: paired-end data conditional block and single-end conditional block -some heavier boolean logic was added to the paired data `firstOfPairFlag()` check against the Read Output parameter so that it includes the Read Aspect parameter -Separate SHIFT code into its own conditional block independently based on reference strand value alone TagPileup -update default file naming to include read aspect information TagPileupWindow -Window design: -add "Read Aspect" radiobutton selection options (with 5prime and 3prime and midpoint options) -remove "Midpoint" option from "Read Output" -components on right side of the window were vertically squished to fit with the new "Read Aspect" components (many `putConstraint()` lines changed) -update assignment of Read Aspect & Read type values to the PileupParameters object in the `Task` class -update radiobutton listeners to listen to "Read Aspect" choices rather than "Read Output" choices -`allowReadChoice()` method was updated to enable/disable Read Type selection components (keep enable/disable strand components, separate/combined) TagPileupCLI -Add new argument group for assigning Read Aspect value -Remove "midpoint" argument option from Read Type value -propagate changes to affected midpoint validation lines
1 parent 5fa82c1 commit 9250d87

5 files changed

Lines changed: 131 additions & 69 deletions

File tree

src/cli/Read_Analysis/TagPileupCLI.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ static class OutputOptions{
5858
private boolean tab = false;
5959
}
6060

61+
//Aspect
62+
@ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect Aspect of Read to output:%n\t@|fg(red) (select no more than one of these options)|@%n")
63+
AspectType aspectType = new AspectType();
64+
static class AspectType {
65+
@Option(names = {"-5", "--five-prime"}, description = "pileup of 5' end of read(default)")
66+
boolean fiveprime = false;
67+
@Option(names = {"-3", "--three-prime"}, description = "pileup of 3' end of read")
68+
boolean threeprime = false;
69+
@Option(names = {"-m", "--midpoint"}, description = "pileup fragment midpoints (require PE, combined)")
70+
boolean midpoint = false;
71+
}
72+
6173
//Read
6274
@ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect Read to output:%n\t@|fg(red) (select no more than one of these options)|@%n")
6375
ReadType readType = new ReadType();
@@ -68,9 +80,6 @@ static class ReadType {
6880
boolean read2 = false;
6981
@Option(names = {"-a", "--all-reads"}, description = "pileup all reads")
7082
boolean allreads = false;
71-
@Option(names = {"-m", "--midpoint"}, description = "pile midpoint (require PE and combined, -p --combined)")
72-
boolean midpoint = false;
73-
int finalRead = 0;
7483
}
7584

7685
//Strand
@@ -148,11 +157,15 @@ public Integer call() throws Exception {
148157
private String validateInput() throws IOException {
149158
String r = "";
150159

160+
// Set ASPECT
161+
if(aspectType.fiveprime) { p.setAspect(0); }
162+
else if(aspectType.threeprime) { p.setAspect(1); }
163+
else if(aspectType.midpoint) { p.setAspect(2); }
164+
151165
// Set READ
152166
if(readType.read1){ p.setRead(0); }
153167
else if(readType.read2){ p.setRead(1); }
154168
else if(readType.allreads){ p.setRead(2); }
155-
else if(readType.midpoint){ p.setRead(3); }
156169

157170
//check input extensions
158171
if(!"bed".equals(ExtensionFileFilter.getExtension(bedFile))){
@@ -195,7 +208,7 @@ private String validateInput() throws IOException {
195208

196209
//set require PE for appropriate flags
197210
p.setPErequire(filterOptions.requirePE);
198-
if( filterOptions.MIN_INSERT!=-9999 || filterOptions.MAX_INSERT!=-9999 || p.getRead() == 3) { p.setPErequire(true); }
211+
if( filterOptions.MIN_INSERT!=-9999 || filterOptions.MAX_INSERT!=-9999 || p.getAspect()==2) { p.setPErequire(true); }
199212

200213
//validate shift, binSize, and CPUs
201214
if(calcOptions.shift<0){ r += "(!)Invalid shift! Must be non-negative, shift=" + calcOptions.shift + "\n"; }
@@ -243,7 +256,7 @@ private String validateInput() throws IOException {
243256

244257
//Set STRAND
245258
p.setStrand(0);
246-
if(combStatus || p.getRead() == 3) { p.setStrand(1); }
259+
if(combStatus || p.getAspect() == 2) { p.setStrand(1); }
247260

248261
//Set smooth type and parameters
249262
if(smoothType.noSmooth){ //default behavior

src/objects/PileupParameters.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ public class PileupParameters {
99
//Composite values file if output
1010
private PrintStream COMPOSITE = null;
1111

12+
//Read aspect:
13+
// 0=5prime end, 1=3prime end, 2=midpoint
14+
private int ASPECT = 0;
1215
//Read type:
13-
// 0=read1, 1=read2, 2=allreads, 3=midpoint
16+
// 0=read1, 1=read2, 2=allreads
1417
private int READ = 0;
1518

1619
//Strand type:
@@ -45,6 +48,7 @@ public void printAll(){
4548
System.out.println( "private File OUTPUT = " + OUTPUT );
4649
System.out.println( "private String COMPOSITE = " + COMPOSITE );
4750
System.out.println( "private int READ = " + READ );
51+
System.out.println( "private int ASPECT = " + ASPECT );
4852
System.out.println( "private int STRAND = " + STRAND );
4953
System.out.println( "private int TRANS = " + TRANS );
5054
System.out.println( "private int SHIFT = " + SHIFT );
@@ -144,6 +148,13 @@ public void setOutputDirectory(File oUTPUT) {
144148
OUTPUT = oUTPUT;
145149
}
146150

151+
public int getAspect() {
152+
return ASPECT;
153+
}
154+
public void setAspect(int aSPECT) {
155+
ASPECT = aSPECT;
156+
}
157+
147158
public int getRead() {
148159
return READ;
149160
}

src/scripts/Read_Analysis/PileupScripts/PileupExtract.java

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void extract(BEDCoord coord) {
4444
// Ugly hack to account for the fact that read 1 5' end may be outside the window of interest even though read 2 and the midpoint may be in range
4545
// TODO FIX this into something more logical, probably check for read2 in region independently?
4646
int MIDPOINT_ADJUST = 0;
47-
if(param.getRead() == 3) { MIDPOINT_ADJUST = 300; }
47+
if(param.getAspect() == 2) { MIDPOINT_ADJUST = 300; }
4848

4949
int BEDSTART = (int)coord.getStart();
5050
int BEDSTOP = (int)coord.getStop();
@@ -63,26 +63,25 @@ else if(param.getTrans() == 2) {
6363
TAG_S1 = new double[WINDOW];
6464
if(STRAND == 0) TAG_S2 = new double[WINDOW];
6565

66-
//SAMRecords are 1-based
66+
//SAMRecords are 1-based and inclusive
6767
CloseableIterator<SAMRecord> iter = inputSam.query(coord.getChrom(), BEDSTART - QUERYWINDOW - SHIFT - MIDPOINT_ADJUST - 1, BEDSTOP + QUERYWINDOW + SHIFT + MIDPOINT_ADJUST + 1, false);
6868
while (iter.hasNext()) {
6969
//Create the record object
70-
//SAMRecord is 1-based
7170
SAMRecord sr = iter.next();
7271

7372
if(sr.getReadPairedFlag()) { //Must be PAIRED-END mapped
7473
if((sr.getProperPairFlag() && param.getPErequire()) || !param.getPErequire()) { //Must either be properly paired if paired-end or don't care about requirement
75-
//Read 1 and want Read 1, Read 2 and want Read 2, want any read, Read 1 and want midpoint
76-
if((sr.getFirstOfPairFlag() && param.getRead() == 0) || (!sr.getFirstOfPairFlag() && param.getRead() == 1) || param.getRead() == 2 || (sr.getFirstOfPairFlag() && param.getRead() == 3)) {
74+
// (Aspect=5/3prime and (Read 1 and want Read 1, Read 2 and want Read 2, want any read)) or Read 1 and want midpoint
75+
if(((param.getAspect() == 0 || param.getAspect() == 1) && ((sr.getFirstOfPairFlag() && param.getRead() == 0) || (!sr.getFirstOfPairFlag() && param.getRead() == 1) || param.getRead() == 2 )) || (sr.getFirstOfPairFlag() && param.getAspect() == 2)) {
76+
// Set marker (left side default, right side if positive strand and 5 prime or negative strand and 3 prime
7777
int mark = sr.getUnclippedStart() - 1;
78-
if(sr.getReadNegativeStrandFlag()) {
78+
if((param.getAspect() == 0 && sr.getReadNegativeStrandFlag()) || (param.getAspect() == 1 && !sr.getReadNegativeStrandFlag())) {
7979
mark = sr.getUnclippedEnd() - 1;
80-
mark -= SHIFT; //SHIFT DATA HERE IF NECCESSARY
81-
} else { mark += SHIFT; }
80+
}
8281

8382
if(sr.getProperPairFlag()) { //prevent cases where non-properly paired Read1 gets to this point
84-
//Find midpoint if read flag == 3
85-
if(param.getRead() == 3) {
83+
//Find midpoint if aspect flag == 2
84+
if(param.getAspect() == 2) {
8685
if(sr.getInferredInsertSize()>0) {
8786
mark = sr.getAlignmentStart() - 1 + (sr.getInferredInsertSize() / 2);
8887
} else if(sr.getInferredInsertSize()<0) {
@@ -98,12 +97,16 @@ else if(param.getTrans() == 2) {
9897
// Apply insert size filters
9998
if(Math.abs(sr.getInferredInsertSize()) < param.getMinInsert() && param.getMinInsert() != -9999) { continue; } //Test for MIN insert size cutoff here
10099
if(Math.abs(sr.getInferredInsertSize()) > param.getMaxInsert() && param.getMaxInsert() != -9999) { continue; } //Test for MAX insert size cutoff here
101-
} else if(param.getRead() == 3) { continue; } // Make sure that midpoint pileup must come from properly paired read
100+
} else if(param.getAspect() == 2) { continue; } // Make sure that midpoint pileup must come from properly paired read
102101

102+
// Shift as needed
103+
if(sr.getReadNegativeStrandFlag()) { mark -= SHIFT; }
104+
else { mark += SHIFT; }
105+
103106
//Adjust tag start to be within array reference
104107
mark -= (BEDSTART - QUERYWINDOW);
105108

106-
//Increment Final Array keeping track of pileup
109+
//Increment Final Array keeping track of pileup
107110
if(mark >= 0 && mark < TAG_S1.length) {
108111
if(STRAND == 0) {
109112
if(!sr.getReadNegativeStrandFlag() && coord.getDir().equals("-")) { TAG_S2[mark] += 1; }
@@ -116,12 +119,17 @@ else if(param.getTrans() == 2) {
116119
}
117120
}
118121
}
119-
} else if(param.getRead() == 0 || param.getRead() == 2) { //Also outputs if not paired-end since by default it is read-1
122+
} else if((param.getRead() == 0 || param.getRead() == 2) && (param.getAspect() == 0 || param.getAspect() == 1)) { //Also outputs if not paired-end since by default it is read-1 (and 5' or 3' end)
123+
// Set marker (left side default, right side if positive strand and 5 prime or negative strand and 3 prime
120124
int mark = sr.getUnclippedStart() - 1;
121-
if(sr.getReadNegativeStrandFlag()) {
125+
if((param.getAspect() == 0 && sr.getReadNegativeStrandFlag()) || (param.getAspect() == 1 && !sr.getReadNegativeStrandFlag())) {
122126
mark = sr.getUnclippedEnd() - 1;
123-
mark -= SHIFT; //SHIFT DATA HERE IF NECCESSARY
124-
} else { mark += SHIFT; }
127+
}
128+
// Shift as needed
129+
if(sr.getReadNegativeStrandFlag()) { mark -= SHIFT; }
130+
else { mark += SHIFT; }
131+
132+
//Adjust tag start to be within array reference
125133
mark -= (BEDSTART - QUERYWINDOW);
126134

127135
//Increment Final Array keeping track of pileup

src/scripts/Read_Analysis/TagPileup.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,19 @@ public String generateFileName(String bed, String bam, int strandnum) {
325325
String[] bedname = bed.split("\\.");
326326
String[] bamname = bam.split("\\.");
327327

328-
String read = "read1";
329-
if (PARAM.getRead() == 1) {
330-
read = "read2";
331-
} else if (PARAM.getRead() == 2) {
332-
read = "readc";
328+
String read = "5read1";
329+
if (PARAM.getAspect() == 0 && PARAM.getRead() == 1) {
330+
read = "5read2";
331+
} else if (PARAM.getAspect() == 0 && PARAM.getRead() == 2) {
332+
read = "5readc";
333+
} else if (PARAM.getAspect() == 1 && PARAM.getRead() == 0) {
334+
read = "3read1";
335+
} else if (PARAM.getAspect() == 1 && PARAM.getRead() == 1) {
336+
read = "3read2";
337+
} else if (PARAM.getAspect() == 1 && PARAM.getRead() == 2) {
338+
read = "3readc";
339+
} else if (PARAM.getAspect() == 2) {
340+
read = "midpoint";
333341
}
334342

335343
return (generateFileName(bedname[0] + "_" + bamname[0] + "_" + read, strandnum));

0 commit comments

Comments
 (0)