11package sng .dataholders ;
22
3- import java .io .Serializable ;
4- import java .lang .Comparable ;
5-
63/**
4+ * CAS333 cleaned out stuff including comparable
75 * Holds all of the data corresponding to a coding region. The begin and
86 * end are always relative to the sequence that the coding region
97 * corresponds to.
108 */
11- public class CodingRegion implements Comparable < CodingRegion >, Serializable
9+ public class CodingRegion
1210{
1311 public static final int TYPE_UNKWOWN = 0 ;
1412 public static final int TYPE_ORF = 1 ;
1513 public static final int TYPE_LARGEST_ORF = 2 ;
1614 public static final int TYPE_UNIPROT = 3 ;
1715
18- private boolean debug = false ;
1916 /**
2017 * Creates a new CodingRegion object with one of the following types:
21- * (TYPE_UNKWOWN | TYPE_ORF | TYPE_LARGEST_ORF | TYPE_UNIPROT)
18+ * (TYPE_UNKNOWN | TYPE_ORF | TYPE_LARGEST_ORF | TYPE_UNIPROT)
2219 * @param nInType The type of the coding region
2320 */
24- public CodingRegion ( int nInType ) { nType = nInType ;
25- if (debug ) System .err .println ("Create Coding region " + nType );}
26-
27- public void setType ( int nInType ) { nType = nInType ; }
28-
29- public String getDescription ( )
30- {
31- int len = (nEnd -nBegin )+1 ;
32- String s = "Frame " + nFrame + " Start " + nBegin + " End " + nEnd + " Len " + len ;
33- switch ( nType )
34- {
35- case TYPE_ORF : return "ORF " + s ;
36- case TYPE_LARGEST_ORF : return "Largest ORF " + s ;
37- case TYPE_UNIPROT : return "Protein ORF " + s ;
38- default : return "?" ;
39- }
40- }
21+ public CodingRegion ( int nInType ) { nType = nInType ; }
4122
4223 public int getBegin () { return nBegin ; };
4324 public void setBegin ( int n ) { nBegin = n ; };
@@ -51,62 +32,9 @@ public String getDescription ( )
5132 public boolean getHasEnd () { return bHasEnd ; };
5233 public void setHasEnd ( boolean b ) { bHasEnd = b ; };
5334
54- public int getLength () { return nEnd - nBegin + 1 ; }
55-
5635 public int getFrame () { return nFrame ; };
5736 public void setFrame ( int n ) { nFrame = n ; }
5837
59- public boolean getIsComplement ( ) { return nFrame < 0 ; }
60-
61- public boolean getHasStartCodon ()
62- {
63- return ( getHasBegin () && !getIsComplement ( ) ) ||
64- ( getHasEnd () && getIsComplement ( ) );
65- }
66-
67- public int getStartCodonIndex ( )
68- {
69- if ( !getIsComplement ( ) )
70- {
71- if ( getHasBegin () )
72- return nBegin ;
73- else
74- return nBegin + Math .abs ( nFrame ) - 1 ;
75- }
76- else
77- {
78- if ( getHasEnd () )
79- return nEnd ;
80- else
81- return nEnd + Math .abs ( nFrame ) - 1 ;
82- }
83- }
84-
85- public int getStopIndex ( )
86- {
87- if ( !getIsComplement ( ) )
88- return nEnd ;
89- else
90- return nBegin ;
91- }
92-
93- public int compareTo (CodingRegion rORF )
94- {
95- // First compare the width. The wider the better.
96- if ( getLength () != rORF .getLength () )
97- return rORF .getLength () - getLength ();
98-
99- // Otherwise if only one has both start and stop consider it better
100- if ( getHasBegin () && getHasEnd () && (!rORF .getHasBegin () || !rORF .getHasEnd () ) )
101- return -1 ;
102- if ( rORF .getHasBegin () && rORF .getHasEnd () && (!getHasBegin () || !getHasEnd () ) )
103- return 1 ;
104-
105- return 0 ;
106- }
107-
108- public Object clone () { return cloneRegion (); }
109-
11038 /**
11139 * @return copy of the coding region
11240 */
@@ -121,41 +49,7 @@ public CodingRegion cloneRegion ( )
12149
12250 return copy ;
12351 }
124-
125- public void sanityCheck ()
126- {
127- if ( nFrame < -3 || nFrame == 0 || nFrame > 3 )
128- throw new RuntimeException ( "Invalid frame of " + nFrame );
129- if ( nBegin > nEnd )
130- throw new RuntimeException ( "Coding Begin > End" );
131- if ( nEnd - nBegin < 6 )
132- throw new RuntimeException ( "Coding region less than two codons: " + nEnd + " " + nBegin );
133- }
134-
135-
136- public CodingRegion getComplement ( int nSeqMinIndex , int nSeqMaxIndex )
137- {
138- // Sanity
139- String s = "MinIndex " + nSeqMinIndex + " MaxIndex " + nSeqMaxIndex + " begin " + nBegin + " end " + nEnd ;
140- if ( nSeqMinIndex > nSeqMaxIndex )
141- throw new RuntimeException ( "Min index > Max index. " + s );
142- if ( nBegin < nSeqMinIndex )
143- throw new RuntimeException ( "Begin < than min index. " + s );
144- if ( nEnd > nSeqMaxIndex )
145- throw new RuntimeException ( "End > than max index. " + s );
146-
147- CodingRegion comp = cloneRegion ();
148- comp .bHasBegin = bHasEnd ;
149- comp .bHasEnd = bHasBegin ;
150- comp .nFrame = -nFrame ;
151- comp .nEnd = nSeqMaxIndex - (nBegin - nSeqMinIndex );
152- comp .nBegin = nSeqMaxIndex - (nEnd - nSeqMinIndex );
153- comp .sanityCheck ();
154- return comp ;
155- }
156-
157- public void clear ()
158- {
52+ public void clear (){
15953 // nothing to clear
16054 }
16155
@@ -167,6 +61,4 @@ public void clear()
16761 private int nBegin = 0 ;
16862 private int nEnd = -1 ;
16963 private int nLen = 0 ;
170-
171- private static final long serialVersionUID = 1 ;
17264}
0 commit comments