-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathStrandedPair.java
More file actions
153 lines (138 loc) · 3.96 KB
/
StrandedPair.java
File metadata and controls
153 lines (138 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package org.seqcode.deepseq;
import org.seqcode.genome.Genome;
import org.seqcode.genome.location.Point;
import org.seqcode.genome.location.ScoredRegion;
/**
* StrandedPair represents a pair of reads that are paired together.
* Coordinate is the 5' end of each hit.
* Weight is determined by implementation of hit loading.
*
* @author mahony
*
*/
public class StrandedPair implements Comparable<StrandedPair>{
private Genome gen;
private int r1Chrom, r2Chrom; // int codes for chroms - convert with Genome
private char r1Strand, r2Strand;
private int r1Coordinate, r2Coordinate;
private float weight;
private boolean sameChrom;
public StrandedPair(Genome g, int r1Chr, int r1Coord, char r1Str, int r2Chr, int r2Coord, char r2Str, float w){
gen=g;
r1Chrom = r1Chr;
r2Chrom = r2Chr;
r1Strand = r1Str;
r2Strand = r2Str;
r1Coordinate = r1Coord;
r2Coordinate = r2Coord;
sameChrom = r1Chrom==r2Chrom;
weight = w;
}
/**
* Get the pair midpoint. Returns null if reads on different strands.
* @return
*/
public Point getMidpoint(){
if(!sameChrom)
return null;
else{
return new Point(gen, gen.getChromName(r1Chrom), (r1Coordinate+r2Coordinate)/2);
}
}
/**
* Returns distance between read 5' positions if this is a proper concurrent pair.
* Returns -1 otherwise.
* @return
*/
public int getFragmentSize(){
if(!sameChrom)
return -1;
else if((r1Coordinate<=r2Coordinate && r1Strand=='+' && r2Strand=='-') || (r2Coordinate<=r1Coordinate && r2Strand=='+' && r1Strand=='-')){
return Math.abs(r2Coordinate-r1Coordinate)+1;
}else{
return -1;
}
}
public void setR1Strand(char strand) {
this.r1Strand = strand;
}
public void setR2Strand(char strand) {
this.r2Strand = strand;
}
public char getR1Strand() {
return r1Strand;
}
public char getR2Strand() {
return r2Strand;
}
public void setR1Coordinate(int coordinate) {
this.r1Coordinate = coordinate;
}
public void setR2Coordinate(int coordinate) {
this.r2Coordinate = coordinate;
}
public int getR1Coordinate() {
return r1Coordinate;
}
public int getR2Coordinate() {
return r2Coordinate;
}
public void setR1Chrom(int chrom){
if(r1Chrom == r2Chrom)
sameChrom=true;
this.r1Chrom=chrom;
}
public void setR2Chrom(int chrom){
if(r1Chrom == r2Chrom)
sameChrom=true;
this.r2Chrom=chrom;
}
public String getR1Chrom(){
return gen.getChromName(r1Chrom);
}
public String getR2Chrom(){
return gen.getChromName(r2Chrom);
}
public boolean pairFromSameChrom(){ return sameChrom; }
public void setWeight(float weight) {
this.weight = weight;
}
public float getWeight() {
return weight;
}
// sort according to R1 coordinate, then by R2 coordinate, then by strands
public int compareTo(StrandedPair b) {
int result;
if (r1Chrom==b.r1Chrom) { //R1 coord
result = r1Coordinate - b.r1Coordinate;
} else {
result = r1Chrom > b.r1Chrom ? +1 : r1Chrom < b.r1Chrom ? -1 : 0;
}
if (result == 0) { //R2 coord
if (r2Chrom == b.r2Chrom) {
result = r2Coordinate - b.r2Coordinate;
} else {
result = r2Chrom > b.r2Chrom ? +1 : r2Chrom < b.r2Chrom ? -1 : 0;
}
}
if (result == 0) //R1 strand
result = (r1Strand==b.r1Strand ? 0 : r1Strand=='+'?1:-1);
if (result == 0) { //R2 strand
result = (r2Strand==b.r2Strand ? 0 : r2Strand=='+'?1:-1);
}
return result;
}
public String toString(){
return new String(gen.getChromName(r1Chrom)+":"+r1Coordinate+":"+r1Strand+"\t"+gen.getChromName(r2Chrom)+":"+r2Coordinate+":"+r2Strand+"\t"+weight);
}
public ScoredRegion toContiguousRegion(){
if(r1Chrom == r2Chrom)
if (r1Coordinate<r1Coordinate) {
return new ScoredRegion(gen, gen.getChromName(r1Chrom), r1Coordinate, r2Coordinate, weight);
} else {
return new ScoredRegion(gen, gen.getChromName(r1Chrom), r2Coordinate, r1Coordinate, weight);
}
else
return null;
}
}