Skip to content

Commit 26ea24f

Browse files
committed
implement full fragment option to tag pileup
Relating to issue #70 Add "Full Fragment" to read Aspect options in TagPileupWindow -new radio button to readAspect button group -separate out allow read choice and strand choice into separate methods -allow strand choice for Full fragment (strand determined by R1 strand" Update objects/PileupParameters with new read aspect option Update TagPileup to use an appropriate default output filename suffix Recode scripts/Read_Analysis/PileupScripts/PileupExtract.java to account for full fragment option -use mark variable to mark the beginning (lower coordinate index) of the fragment -when adding marks, loop through values from mark to mark+insertsize
1 parent 9250d87 commit 26ea24f

4 files changed

Lines changed: 68 additions & 16 deletions

File tree

src/objects/PileupParameters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class PileupParameters {
1010
private PrintStream COMPOSITE = null;
1111

1212
//Read aspect:
13-
// 0=5prime end, 1=3prime end, 2=midpoint
13+
// 0=5prime end, 1=3prime end, 2=midpoint, 3=fullfragment
1414
private int ASPECT = 0;
1515
//Read type:
1616
// 0=read1, 1=read2, 2=allreads

src/scripts/Read_Analysis/PileupScripts/PileupExtract.java

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ else if(param.getTrans() == 2) {
7171

7272
if(sr.getReadPairedFlag()) { //Must be PAIRED-END mapped
7373
if((sr.getProperPairFlag() && param.getPErequire()) || !param.getPErequire()) { //Must either be properly paired if paired-end or don't care about requirement
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)) {
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) or (Read 1 and want fragment)
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) || (sr.getFirstOfPairFlag() && param.getAspect() == 3)) {
7676
// 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;
7878
if((param.getAspect() == 0 && sr.getReadNegativeStrandFlag()) || (param.getAspect() == 1 && !sr.getReadNegativeStrandFlag())) {
@@ -93,12 +93,20 @@ else if(param.getTrans() == 2) {
9393
}
9494
// Correction to ensure that even insert size mark reoriented for negative strands
9595
if(sr.getInferredInsertSize() % 2 == 0 && coord.getDir().equals("-") ) { mark--; }
96+
} else if(param.getAspect() == 3) {
97+
if(sr.getInferredInsertSize()>0) { mark = sr.getAlignmentStart() - 1; }
98+
else if(sr.getInferredInsertSize()<0) { mark = sr.getMateAlignmentStart() - 1; }
99+
else {
100+
//Most aligners will flag records with an insert size of zero as improper pairs
101+
System.err.println("This statement should never print (insert size=0 when finding fragment start in PileupExtract)");
102+
continue;
103+
}
96104
}
97105
// Apply insert size filters
98106
if(Math.abs(sr.getInferredInsertSize()) < param.getMinInsert() && param.getMinInsert() != -9999) { continue; } //Test for MIN insert size cutoff here
99107
if(Math.abs(sr.getInferredInsertSize()) > param.getMaxInsert() && param.getMaxInsert() != -9999) { continue; } //Test for MAX insert size cutoff here
100-
} else if(param.getAspect() == 2) { continue; } // Make sure that midpoint pileup must come from properly paired read
101-
108+
} else if(param.getAspect() < 1) { continue; } // Make sure that midpoint/fragment pileup must come from properly paired read
109+
102110
// Shift as needed
103111
if(sr.getReadNegativeStrandFlag()) { mark -= SHIFT; }
104112
else { mark += SHIFT; }
@@ -107,14 +115,30 @@ else if(param.getTrans() == 2) {
107115
mark -= (BEDSTART - QUERYWINDOW);
108116

109117
//Increment Final Array keeping track of pileup
110-
if(mark >= 0 && mark < TAG_S1.length) {
111-
if(STRAND == 0) {
112-
if(!sr.getReadNegativeStrandFlag() && coord.getDir().equals("-")) { TAG_S2[mark] += 1; }
113-
else if(sr.getReadNegativeStrandFlag() && coord.getDir().equals("+")) { TAG_S2[mark] += 1; }
114-
else if(!sr.getReadNegativeStrandFlag() && coord.getDir().equals("+")) { TAG_S1[mark] += 1; }
115-
else if(sr.getReadNegativeStrandFlag() && coord.getDir().equals("-")) { TAG_S1[mark] += 1;}
116-
} else {
117-
TAG_S1[mark] += 1;
118+
if(param.getAspect() < 3) {
119+
if(mark >= 0 && mark < TAG_S1.length) {
120+
if(STRAND == 0) {
121+
if(!sr.getReadNegativeStrandFlag() && coord.getDir().equals("-")) { TAG_S2[mark] += 1; }
122+
else if(sr.getReadNegativeStrandFlag() && coord.getDir().equals("+")) { TAG_S2[mark] += 1; }
123+
else if(!sr.getReadNegativeStrandFlag() && coord.getDir().equals("+")) { TAG_S1[mark] += 1; }
124+
else if(sr.getReadNegativeStrandFlag() && coord.getDir().equals("-")) { TAG_S1[mark] += 1;}
125+
} else {
126+
TAG_S1[mark] += 1;
127+
}
128+
}
129+
} else {
130+
int markStop = Math.min(mark + Math.abs(sr.getInferredInsertSize()), TAG_S1.length);
131+
for(int m = mark; m < markStop; m++) {
132+
if(m >= 0 && m < TAG_S1.length) {
133+
if(STRAND == 0) {
134+
if(!sr.getReadNegativeStrandFlag() && coord.getDir().equals("-")) { TAG_S2[m] += 1; }
135+
else if(sr.getReadNegativeStrandFlag() && coord.getDir().equals("+")) { TAG_S2[m] += 1; }
136+
else if(!sr.getReadNegativeStrandFlag() && coord.getDir().equals("+")) { TAG_S1[m] += 1; }
137+
else if(sr.getReadNegativeStrandFlag() && coord.getDir().equals("-")) { TAG_S1[m] += 1;}
138+
} else {
139+
TAG_S1[m] += 1;
140+
}
141+
}
118142
}
119143
}
120144
}

src/scripts/Read_Analysis/TagPileup.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ public String generateFileName(String bed, String bam, int strandnum) {
338338
read = "3readc";
339339
} else if (PARAM.getAspect() == 2) {
340340
read = "midpoint";
341+
} else if (PARAM.getAspect() == 3) {
342+
read = "fragment";
341343
}
342344

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

src/window_interface/Read_Analysis/TagPileupWindow.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class TagPileupWindow extends JFrame implements ActionListener, PropertyC
6666
private JRadioButton rdbtnFivePrime;
6767
private JRadioButton rdbtnThreePrime;
6868
private JRadioButton rdbtnMidpoint;
69+
private JRadioButton rdbtnFragment;
6970
private JRadioButton rdbtnRead1;
7071
private JRadioButton rdbtnRead2;
7172
private JRadioButton rdbtnAllReads;
@@ -153,6 +154,7 @@ public Void doInBackground() throws IOException, InterruptedException {
153154
if (rdbtnFivePrime.isSelected()) { param.setAspect(0); }
154155
else if (rdbtnThreePrime.isSelected()) { param.setAspect(1); }
155156
else if (rdbtnMidpoint.isSelected()) { param.setAspect(2); }
157+
else if (rdbtnFragment.isSelected()) { param.setAspect(3); }
156158

157159
if (rdbtnRead1.isSelected()) { param.setRead(0); }
158160
else if (rdbtnRead2.isSelected()) { param.setRead(1); }
@@ -344,10 +346,17 @@ public void actionPerformed(ActionEvent arg0) {
344346
sl_contentPane.putConstraint(SpringLayout.WEST, rdbtnMidpoint, 10, SpringLayout.EAST, rdbtnThreePrime);
345347
contentPane.add(rdbtnMidpoint);
346348

349+
rdbtnFragment = new JRadioButton("Full Fragment (Require PE)");
350+
sl_contentPane.putConstraint(SpringLayout.NORTH, rdbtnFragment, 0, SpringLayout.NORTH, rdbtnFivePrime);
351+
sl_contentPane.putConstraint(SpringLayout.WEST, rdbtnFragment, 10, SpringLayout.EAST, rdbtnMidpoint);
352+
sl_contentPane.putConstraint(SpringLayout.EAST, rdbtnFragment, -10, SpringLayout.EAST, contentPane);
353+
contentPane.add(rdbtnFragment);
354+
347355
ButtonGroup AspectRead = new ButtonGroup();
348356
AspectRead.add(rdbtnFivePrime);
349357
AspectRead.add(rdbtnThreePrime);
350358
AspectRead.add(rdbtnMidpoint);
359+
AspectRead.add(rdbtnFragment);
351360
rdbtnFivePrime.setSelected(true);
352361

353362
JLabel lblOutputRead = new JLabel("Select Read to Output:");
@@ -798,6 +807,7 @@ public void actionPerformed(ActionEvent e) {
798807
public void itemStateChanged(ItemEvent e) {
799808
if (rdbtnFivePrime.isSelected()) {
800809
allowReadChoice(true);
810+
allowStrandChoice(true);
801811
}
802812
}
803813
});
@@ -806,6 +816,7 @@ public void itemStateChanged(ItemEvent e) {
806816
public void itemStateChanged(ItemEvent e) {
807817
if (rdbtnThreePrime.isSelected()) {
808818
allowReadChoice(true);
819+
allowStrandChoice(true);
809820
}
810821
}
811822
});
@@ -814,6 +825,7 @@ public void itemStateChanged(ItemEvent e) {
814825
public void itemStateChanged(ItemEvent e) {
815826
if (rdbtnMidpoint.isSelected()) {
816827
allowReadChoice(false);
828+
allowStrandChoice(false);
817829
rdbtnComb.setSelected(true);
818830
chckbxRequireProperPe.setSelected(true);
819831
chckbxRequireProperPe.setEnabled(false);
@@ -823,6 +835,19 @@ public void itemStateChanged(ItemEvent e) {
823835
}
824836
});
825837

838+
rdbtnFragment.addItemListener(new ItemListener() {
839+
public void itemStateChanged(ItemEvent e) {
840+
if (rdbtnFragment.isSelected()) {
841+
allowReadChoice(false);
842+
allowStrandChoice(false);
843+
chckbxRequireProperPe.setSelected(true);
844+
chckbxRequireProperPe.setEnabled(false);
845+
} else if (!chckbxFilterByMin.isSelected() && !chckbxFilterByMax.isSelected()) {
846+
chckbxRequireProperPe.setEnabled(true);
847+
}
848+
}
849+
});
850+
826851
rdbtnNone.addItemListener(new ItemListener() {
827852
public void itemStateChanged(ItemEvent e) {
828853
if (rdbtnNone.isSelected()) {
@@ -948,11 +973,12 @@ public void actionPerformed(ActionEvent e) {
948973
btnPileup.addActionListener(this);
949974
}
950975

951-
public void allowReadChoice(boolean activate) {
952-
// Allow Strand choice
976+
public void allowStrandChoice(boolean activate) {
953977
rdbtnComb.setEnabled(activate);
954978
rdbtnSeperate.setEnabled(activate);
955-
// Allow Read type choice
979+
}
980+
981+
public void allowReadChoice(boolean activate) {
956982
rdbtnRead1.setEnabled(activate);
957983
rdbtnRead2.setEnabled(activate);
958984
rdbtnAllReads.setEnabled(activate);

0 commit comments

Comments
 (0)