Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/fileIO/ChainLine.java @ 68:5028fdace37b
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 16:23:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 68:5028fdace37b |
---|---|
1 package fileIO; | |
2 | |
3 import dna.Data; | |
4 import dna.Gene; | |
5 import shared.Shared; | |
6 | |
7 public class ChainLine implements Comparable<ChainLine> { | |
8 | |
9 | |
10 public static void main(String[] args){ | |
11 | |
12 int chrom=Gene.toChromosome(args[0]); | |
13 | |
14 ChainLine[][] lines=ChainBlock.loadChainLines(Data.ROOT_CHAIN+"hg18ToHg19.over.chain"); | |
15 | |
16 for(int i=1; i<args.length; i++){ | |
17 int loc=Integer.parseInt(args[i]); | |
18 int[] result=translate(loc, lines[chrom]); | |
19 System.out.print(chrom+"\t+\t"+loc+"\t->\t"); | |
20 System.out.println(result==null ? "null" : result[0]+"\t"+Shared.strandCodes[result[1]]+"\t"+result[2]); | |
21 } | |
22 | |
23 } | |
24 | |
25 | |
26 public ChainLine(int chromT, byte strandT, int startT, int stopT, int chromQ, byte strandQ, int startQ, int stopQ){ | |
27 tChrom=chromT; | |
28 tStrand=strandT; | |
29 tStart=startT; | |
30 tStop=stopT; | |
31 | |
32 qChrom=chromQ; | |
33 qStrand=strandQ; | |
34 qStart=startQ; | |
35 qStop=stopQ; | |
36 } | |
37 | |
38 | |
39 @Override | |
40 public String toString(){ | |
41 return tChrom+"\t"+Shared.strandCodes[tStrand]+"\t"+tStart+"\t"+tStop+"\t"+ | |
42 qChrom+"\t"+Shared.strandCodes[qStrand]+"\t"+qStart+"\t"+qStop; | |
43 } | |
44 | |
45 | |
46 public static int binarySearch(int loc, ChainLine[] array){ | |
47 return binarySearch(loc, array, 0, array.length-1); | |
48 } | |
49 | |
50 | |
51 public static int binarySearch(int loc, ChainLine[] array, int first, int last){ | |
52 // if(first>=last){ | |
53 // if(first>last){return -1;} | |
54 // assert(first==last && first<array.length); | |
55 // return (array[first].tStart<=loc && array[first].tStop>=loc) ? first : -1; | |
56 // } | |
57 // System.out.println("BinarySearch "+loc+", "+first+", "+last); | |
58 if(first>last){return -1;} | |
59 int mid=(first+last)/2; | |
60 ChainLine midcl=array[mid]; | |
61 // System.out.println("mid = "+midcl); | |
62 if(loc<midcl.tStart){return binarySearch(loc, array, first, mid-1);} | |
63 else if(loc>midcl.tStop){return binarySearch(loc, array, mid+1, last);} | |
64 return mid; | |
65 } | |
66 | |
67 /** Returns {chrom, strand, loc} */ | |
68 public static int[] translate(int loc, ChainLine[] array){ | |
69 int index=binarySearch(loc, array); | |
70 if(index<0){return null;} | |
71 ChainLine cl=array[index]; | |
72 return cl.translate(loc); | |
73 } | |
74 | |
75 public int[] translate(int loc){ | |
76 if(loc<tStart || loc>tStop){return null;} | |
77 // assert(loc>=tStart && loc<=tStop); | |
78 if(qChrom<1 || qChrom>25){return null;} | |
79 if(qStrand==Shared.PLUS){ | |
80 return new int[] {qChrom, qStrand, qStart+loc-tStart}; | |
81 }else{ | |
82 assert(qStart>=qStop) : this; | |
83 return new int[] {qChrom, qStrand, qStart-(loc-tStart)}; | |
84 } | |
85 } | |
86 | |
87 | |
88 public boolean contains(int a, int b){ | |
89 assert(b>=a); | |
90 return a>=tStart && b<=tStop; | |
91 } | |
92 | |
93 | |
94 public boolean contains(int a){ | |
95 return a>=tStart && a<=tStop; | |
96 } | |
97 | |
98 | |
99 @Override | |
100 public int compareTo(ChainLine other) { | |
101 int temp; | |
102 | |
103 temp=tChrom-other.tChrom; | |
104 if(temp!=0){return temp;} | |
105 | |
106 assert(tStrand==other.tStrand); | |
107 | |
108 temp=tStart-other.tStart; | |
109 if(temp!=0){return temp;} | |
110 | |
111 temp=tStop-other.tStop; | |
112 return temp; | |
113 } | |
114 | |
115 public int tChrom; | |
116 public byte tStrand; | |
117 public int tStart; | |
118 public int tStop; | |
119 | |
120 public int qChrom; | |
121 public byte qStrand; | |
122 public int qStart; | |
123 public int qStop; | |
124 | |
125 } |