Skip to content

Commit c65f746

Browse files
authored
Merge pull request #77 from CEGRcode/hotfix
Hotfix for various TagPileup bugs
2 parents 61271d4 + 0d300ec commit c65f746

2 files changed

Lines changed: 23 additions & 26 deletions

File tree

src/scripts/Read_Analysis/PileupScripts/PileupExtract.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ public void extract(BEDCoord read) {
4848

4949
int BEDSTART = (int)read.getStart();
5050
int BEDSTOP = (int)read.getStop();
51-
//Correct for '-' strand BED coord so they align with '+' strand
52-
if(read.getDir().equals("-")) {
53-
BEDSTART++;
54-
BEDSTOP++;
55-
}
5651

5752
//Correct Window Size for proper transformations
5853
int WINDOW = (BEDSTOP - BEDSTART) + ((param.getBin() / 2) * 2);
@@ -81,24 +76,29 @@ else if(param.getTrans() == 2) {
8176
if((sr.getFirstOfPairFlag() && param.getRead() == 0) || (!sr.getFirstOfPairFlag() && param.getRead() == 1) || param.getRead() == 2 || (sr.getFirstOfPairFlag() && param.getRead() == 3)) {
8277
int FivePrime = sr.getUnclippedStart() - 1;
8378
if(sr.getReadNegativeStrandFlag()) {
84-
FivePrime = sr.getUnclippedEnd();
79+
FivePrime = sr.getUnclippedEnd() - 1;
8580
FivePrime -= SHIFT; //SHIFT DATA HERE IF NECCESSARY
8681
} else { FivePrime += SHIFT; }
8782

8883
if(sr.getProperPairFlag()) { //prevent cases where non-properly paired Read1 gets to this point
89-
int recordStart = sr.getUnclippedStart() - 1;
90-
int recordStop = sr.getMateAlignmentStart() + sr.getReadLength() - 1;
91-
if(sr.getMateAlignmentStart() - 1 < recordStart) {
92-
recordStart = sr.getMateAlignmentStart() - 1;
93-
recordStop = sr.getUnclippedEnd();
84+
//Find midpoint if read flag == 3
85+
if(param.getRead() == 3) {
86+
if(sr.getInferredInsertSize()>0) {
87+
FivePrime = sr.getAlignmentStart() - 1 + (sr.getInferredInsertSize() / 2);
88+
} else if(sr.getInferredInsertSize()<0) {
89+
FivePrime = sr.getMateAlignmentStart() - 1 - (sr.getInferredInsertSize() / 2);
90+
} else {
91+
//Most aligners will flag records with an insert size of zero as improper pairs
92+
System.err.println("This statement should never print (insert size=0 when finding midpoint in PileupExtract)");
93+
continue;
94+
}
95+
// Correction to ensure that even insert size mark reoriented for negative strands
96+
if(sr.getInferredInsertSize() % 2 == 0 && read.getDir().equals("-") ) { FivePrime--; }
9497
}
95-
96-
//Find midpoint is read flag == 3
97-
if(param.getRead() == 3) { FivePrime = (recordStart + recordStop) / 2; }
98-
99-
if(recordStop - recordStart < param.getMinInsert() && param.getMinInsert() != -9999) { FivePrime = -1; } //Test for MIN insert size cutoff here
100-
if(recordStop - recordStart > param.getMaxInsert() && param.getMaxInsert() != -9999) { FivePrime = -1; } //Test for MAX insert size cutoff here
101-
} else if(param.getRead() == 3) { FivePrime = -1; } // Make sure that midpoint pileup must come from properly paired read
98+
// Apply insert size filters
99+
if(Math.abs(sr.getInferredInsertSize()) < param.getMinInsert() && param.getMinInsert() != -9999) { continue; } //Test for MIN insert size cutoff here
100+
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
102102

103103
//Adjust tag start to be within array reference
104104
FivePrime -= (BEDSTART - QUERYWINDOW);
@@ -119,7 +119,7 @@ else if(param.getTrans() == 2) {
119119
} else if(param.getRead() == 0 || param.getRead() == 2) { //Also outputs if not paired-end since by default it is read-1
120120
int FivePrime = sr.getUnclippedStart() - 1;
121121
if(sr.getReadNegativeStrandFlag()) {
122-
FivePrime = sr.getUnclippedEnd();
122+
FivePrime = sr.getUnclippedEnd() - 1;
123123
FivePrime -= SHIFT; //SHIFT DATA HERE IF NECCESSARY
124124
} else { FivePrime += SHIFT; }
125125
FivePrime -= (BEDSTART - QUERYWINDOW);

src/scripts/Read_Analysis/TagPileup.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,16 +378,13 @@ public Vector<BEDCoord> loadCoord(File INPUT) throws FileNotFoundException {
378378
}
379379
if (Integer.parseInt(temp[1]) >= 0) {
380380
if (temp.length > 4) {
381-
if (temp[5].equals("+")) {
382-
COORD.add(new BEDCoord(temp[0], Integer.parseInt(temp[1]), Integer.parseInt(temp[2]),
383-
"+", name));
381+
if (temp[5].equals("-")) {
382+
COORD.add(new BEDCoord(temp[0], Integer.parseInt(temp[1]), Integer.parseInt(temp[2]), "-", name));
384383
} else {
385-
COORD.add(new BEDCoord(temp[0], Integer.parseInt(temp[1]), Integer.parseInt(temp[2]),
386-
"-", name));
384+
COORD.add(new BEDCoord(temp[0], Integer.parseInt(temp[1]), Integer.parseInt(temp[2]), "+", name));
387385
}
388386
} else {
389-
COORD.add(new BEDCoord(temp[0], Integer.parseInt(temp[1]), Integer.parseInt(temp[2]), "+",
390-
name));
387+
COORD.add(new BEDCoord(temp[0], Integer.parseInt(temp[1]), Integer.parseInt(temp[2]), "+", name));
391388
}
392389

393390
} else {

0 commit comments

Comments
 (0)