comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/prok/Feature.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 prok;
2
3 import java.util.Comparator;
4
5 /**
6 * Represents a genomic feature such as a gene, with start, stop, and strand.
7 * @author Brian Bushnell
8 * @date Sep 24, 2018
9 *
10 */
11 abstract class Feature extends ProkObject implements Comparable<Feature>{
12
13 /*--------------------------------------------------------------*/
14 /*---------------- Constructor ----------------*/
15 /*--------------------------------------------------------------*/
16
17 public Feature(String scafName_, int start_, int stop_, int strand_, int scaflen_){
18 scafName=scafName_;
19 start=start_;
20 stop=stop_;
21 strand=strand_;
22 scaflen=scaflen_;
23 }
24
25 /*--------------------------------------------------------------*/
26 /*---------------- Methods ----------------*/
27 /*--------------------------------------------------------------*/
28
29 public final void flip(){
30 int a=scaflen-start-1;
31 int b=scaflen-stop-1;
32 start=b;
33 stop=a;
34 flipped=flipped^1;
35 }
36
37 public final int currentStrand(){
38 return strand^flipped;
39 }
40
41 public final int length(){
42 return stop-start+1;
43 }
44
45 @Override
46 public final int compareTo(Feature f) {
47 int x=scafName.compareTo(f.scafName);
48 if(x!=0){return x;}
49 if(stop!=f.stop){return stop-f.stop;}
50 return start-f.start;
51 }
52
53 public final int flipped(){return flipped;}
54
55 public abstract float score();
56
57 /*--------------------------------------------------------------*/
58 /*---------------- Fields ----------------*/
59 /*--------------------------------------------------------------*/
60
61 public final String scafName;
62 public final int strand;
63 public final int scaflen;
64
65 /** 0-based position of first base of feature **/
66 public int start;
67 /** 0-based position of last base of feature **/
68 public int stop;
69 private int flipped=0;
70
71 /*--------------------------------------------------------------*/
72 /*---------------- Nested Classes ----------------*/
73 /*--------------------------------------------------------------*/
74
75 @SuppressWarnings("synthetic-access")
76 public static final FeatureComparatorScore featureComparatorScore=new FeatureComparatorScore();
77
78 //Sorts so that high scores are first.
79 private static class FeatureComparatorScore implements Comparator<Feature> {
80
81 private FeatureComparatorScore(){}
82
83 @Override
84 public int compare(Feature a, Feature b) {
85 float sa=a.score(), sb=b.score();
86 if(sa<sb){return 1;}
87 if(sb<sa){return -1;}
88 return a.compareTo(b);
89 }
90
91 }
92
93 }