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
|
package structures;
import repeat.Palindrome;
import shared.Tools;
public class Crispr implements Comparable<Crispr> {
public Crispr() {}
public Crispr(int a1, int b1, int a2, int b2) {
a=new Range(a1, b1);
b=new Range(a2, b2);
}
public int gap() {
return b.a-a.b-1;
}
public boolean containsInGap(Range r) {
return r.a>a.b && r.b<b.a;
}
public String toString() {
return appendTo(new ByteBuilder()).toString();
}
public String toString(byte[] bases) {
ByteBuilder bb=new ByteBuilder();
appendTo(bb, bases.length, bases);
return bb.toString();
}
public ByteBuilder appendTo(ByteBuilder bb) {
return appendTo(bb, 0, null);
}
public ByteBuilder appendTo(ByteBuilder bb, int len, byte[] bases) {
bb.append('[').append(a.a).dash().append(a.b).comma();
bb.append(b.a).dash().append(b.b);
if(len>0) {bb.semi().append(len);}
bb.append(']');
if(pa!=null) {pa.appendTo(bb.comma(), a.a, a.b);}
else if(pb!=null) {pb.appendTo(bb, a.a, a.b);}
if(bases!=null) {
bb.nl();
for(int i=a.a; i<=a.b; i++) {bb.append(bases[i]);}
bb.nl();
for(int i=b.a; i<=b.b; i++) {bb.append(bases[i]);}
}
return bb;
}
public void set(int a1, int b1, int a2, int b2) {
a.a=a1;
a.b=b1;
b.a=a2;
b.b=b2;
//These could happen and will probably be dealt with later, but are good to prevent if possible.
assert(a2>b1) : this;
assert(a1<b1) : this;
assert(a2<b2) : this;
}
public int edgeDist(int length) {
return Tools.min(a.a, length-b.b-1);
}
public boolean spans(int length) {
return a.a==0 && b.b+1==length;
}
public int minLength() {
return Tools.min(a.length(), b.length());
}
public int maxLength() {
return Tools.max(a.length(), b.length());
}
public int lengthDif() {
return b.length()-a.length();
}
public void fixBounds(int length) {
a.fixBounds(length);
b.fixBounds(length);
}
public float maxScore() {
return Tools.max(scoreA, scoreB);
}
public boolean sameLength() {
return a.length()==b.length();
}
// public boolean internal(byte[] seq) {
// return !touchesEdge(seq.length);
// }
public boolean internal(int seqLen) {
return a.a>0 && b.b<seqLen-1;
}
// public boolean touchesEdge(byte[] seq) {
// return touchesEdge(seq.length);
// }
public boolean touchesEdge(int seqLen) {
return a.a<=0 || b.b>=seqLen-1;
}
public boolean touchesBothEnds(int seqLen) {
return a.a<=0 && b.b>=seqLen-1;
}
@Override
/**
* So this sort of compares them but it's not really optimal.
* Not clear how to improve it though.
* @param o
* @return
*/
public int compareTo(Crispr o) {
int x=a.compareTo(o.a);
if(x!=0) {return x;}
return b.compareTo(o.b);
}
public Range a;
public Range b;
public Palindrome pa, pb;
public float scoreA, scoreB;
public int matches=0, mismatches=0;
public int trimmedConsensus=0;
public int extendedConsensus=0;
}
|