1 /*=========================================================================== 2 * 3 * PUBLIC DOMAIN NOTICE 4 * National Center for Biotechnology Information 5 * 6 * This software/database is a "United States Government Work" under the 7 * terms of the United States Copyright Act. It was written as part of 8 * the author's official duties as a United States Government employee and 9 * thus cannot be copyrighted. This software/database is freely available 10 * to the public for use. The National Library of Medicine and the U.S. 11 * Government have not placed any restriction on its use or reproduction. 12 * 13 * Although all reasonable efforts have been taken to ensure the accuracy 14 * and reliability of the software and data, the NLM and the U.S. 15 * Government do not and cannot warrant the performance or results that 16 * may be obtained by using this software or data. The NLM and the U.S. 17 * Government disclaim all warranties, express or implied, including 18 * warranties of performance, merchantability or fitness for any particular 19 * purpose. 20 * 21 * Please cite the author in any work or product based on this material. 22 * 23 * =========================================================================== 24 * 25 */ 26 27 package ngs.itf; 28 29 import ngs.ErrorMsg; 30 import ngs.Reference; 31 import ngs.Alignment; 32 import ngs.AlignmentIterator; 33 import ngs.PileupIterator; 34 35 36 /*========================================================================== 37 * ReferenceItf 38 * represents a reference sequence 39 */ 40 class ReferenceItf 41 extends Refcount 42 implements Reference 43 { 44 45 /*********************** 46 * Reference Interface * 47 ***********************/ 48 49 /* getCommonName 50 * returns the common name of reference, e.g. "chr1" 51 */ getCommonName()52 public String getCommonName () 53 throws ErrorMsg 54 { 55 return this . GetCommonName ( self ); 56 } 57 58 /* getCanonicalName 59 * returns the accessioned name of reference, e.g. "NC_000001.11" 60 */ getCanonicalName()61 public String getCanonicalName () 62 throws ErrorMsg 63 { 64 return this . GetCanonicalName ( self ); 65 } 66 67 68 /* getIsCircular 69 * returns true if reference is circular 70 */ getIsCircular()71 public boolean getIsCircular () 72 throws ErrorMsg 73 { 74 return this . GetIsCircular ( self ); 75 } 76 77 78 /* getIsLocal 79 * returns true if reference is local 80 */ getIsLocal()81 public boolean getIsLocal () 82 throws ErrorMsg 83 { 84 return this . GetIsLocal ( self ); 85 } 86 87 88 /* getLength 89 * returns the length of the reference sequence 90 */ getLength()91 public long getLength () 92 throws ErrorMsg 93 { 94 return this . GetLength ( self ); 95 } 96 97 98 /* getReferenceBases 99 * return sub-sequence bases for Reference 100 * "offset" is zero-based 101 * "size" must be >= 0 102 */ getReferenceBases( long offset )103 public String getReferenceBases ( long offset ) 104 throws ErrorMsg 105 { 106 return this . getReferenceBases ( offset, -1 ); 107 } 108 getReferenceBases( long offset, long length )109 public String getReferenceBases ( long offset, long length ) 110 throws ErrorMsg 111 { 112 return this . GetReferenceBases ( self, offset, length ); 113 } 114 115 /* getReferenceChunk 116 * return largest contiguous chunk available of 117 * sub-sequence bases for Reference 118 * "offset" is zero-based 119 * "size" must be >= 0 120 * 121 * NB - actual returned sequence may be shorter 122 * than requested. to obtain all bases available 123 * in chunk, use a negative "size" value 124 */ getReferenceChunk( long offset )125 public String getReferenceChunk ( long offset ) 126 throws ErrorMsg 127 { 128 return this . getReferenceChunk ( offset, -1 ); 129 } 130 getReferenceChunk( long offset, long length )131 public String getReferenceChunk ( long offset, long length ) 132 throws ErrorMsg 133 { 134 return this . GetReferenceChunk ( self, offset, length ); 135 } 136 137 138 /*---------------------------------------------------------------------- 139 * ALIGNMENTS 140 */ 141 142 /* getAlignmentCount 143 */ getAlignmentCount()144 public long getAlignmentCount () 145 throws ErrorMsg 146 { 147 return this . GetAlignmentCount ( self, Alignment . all ); 148 } 149 getAlignmentCount( int categories )150 public long getAlignmentCount ( int categories ) 151 throws ErrorMsg 152 { 153 return this . GetAlignmentCount ( self, categories ); 154 } 155 156 /* getAlignment 157 * returns an individual Alignment 158 * throws ErrorMsg if Alignment does not exist 159 * or is not part of this Reference 160 */ getAlignment( String alignmentId )161 public Alignment getAlignment ( String alignmentId ) 162 throws ErrorMsg 163 { 164 long ref = this . GetAlignment ( self, alignmentId ); 165 try 166 { 167 return new AlignmentItf ( ref ); 168 } 169 catch ( Exception x ) 170 { 171 this . release ( ref ); 172 throw new ErrorMsg ( x . toString () ); 173 } 174 } 175 176 /* AlignmentCategory 177 * see Alignment for categories 178 */ 179 180 /* getAlignments 181 * returns an iterator of contained alignments 182 */ getAlignments( int categories )183 public AlignmentIterator getAlignments ( int categories ) 184 throws ErrorMsg 185 { 186 long ref = this . GetAlignments ( self, categories ); 187 try 188 { 189 return new AlignmentIteratorItf ( ref ); 190 } 191 catch ( Exception x ) 192 { 193 this . release ( ref ); 194 throw new ErrorMsg ( x . toString () ); 195 } 196 } 197 198 /* getAlignmentSlice 199 * returns an iterator across a range of Alignments 200 * "first" is an unsigned ordinal into set 201 * "categories" provides a means of filtering by AlignmentCategory 202 */ getAlignmentSlice( long offset, long length )203 public AlignmentIterator getAlignmentSlice ( long offset, long length ) 204 throws ErrorMsg 205 { 206 return this . getAlignmentSlice ( offset, length, Alignment . all ); 207 } 208 getAlignmentSlice( long offset, long length, int categories )209 public AlignmentIterator getAlignmentSlice ( long offset, long length, int categories ) 210 throws ErrorMsg 211 { 212 long ref = this . GetAlignmentSlice ( self, offset, length, categories ); 213 try 214 { 215 return new AlignmentIteratorItf ( ref ); 216 } 217 catch ( Exception x ) 218 { 219 this . release ( ref ); 220 throw new ErrorMsg ( x . toString () ); 221 } 222 } 223 224 /* getFilteredAlignmentSlice 225 * returns a filtered iterator across a slice of the Reference 226 * behaves like "getAlignmentSlice" except that supported filters are applied to selection 227 * "filters" is a set of filter bits defined in Alignment 228 * "mappingQuality" is a cutoff to be used according to bits in "filters" 229 */ getFilteredAlignmentSlice( long offset, long length, int categories, int filters, int mappingQuality )230 public AlignmentIterator getFilteredAlignmentSlice ( long offset, long length, int categories, int filters, int mappingQuality ) 231 throws ErrorMsg 232 { 233 long ref = this . GetFilteredAlignmentSlice ( self, offset, length, categories, filters, mappingQuality ); 234 try 235 { 236 return new AlignmentIteratorItf ( ref ); 237 } 238 catch ( Exception x ) 239 { 240 this . release ( ref ); 241 throw new ErrorMsg ( x . toString () ); 242 } 243 } 244 245 246 /*---------------------------------------------------------------------- 247 * PILEUP 248 */ 249 250 /* getPileups 251 * returns an iterator of contained Pileups 252 */ getPileups( int categories )253 public PileupIterator getPileups ( int categories ) 254 throws ErrorMsg 255 { 256 long ref = this . GetPileups ( self, categories ); 257 try 258 { 259 return new PileupIteratorItf ( ref ); 260 } 261 catch ( Exception x ) 262 { 263 this . release ( ref ); 264 throw new ErrorMsg ( x . toString () ); 265 } 266 } 267 getFilteredPileups( int categories, int filters, int mappingQuality )268 public PileupIterator getFilteredPileups ( int categories, int filters, int mappingQuality ) 269 throws ErrorMsg 270 { 271 long ref = this . GetFilteredPileups ( self, categories, filters, mappingQuality ); 272 try 273 { 274 return new PileupIteratorItf ( ref ); 275 } 276 catch ( Exception x ) 277 { 278 this . release ( ref ); 279 throw new ErrorMsg ( x . toString () ); 280 } 281 } 282 283 /* getPileupSlice 284 * creates a PileupIterator on a slice (window) of reference 285 * "start" is the signed starting position on reference 286 * "length" is the unsigned number of bases in the window 287 * "categories" provides a means of filtering by AlignmentCategory 288 */ getPileupSlice( long offset, long length )289 public PileupIterator getPileupSlice ( long offset, long length ) 290 throws ErrorMsg 291 { 292 return this . getPileupSlice ( offset, length, Alignment . all ); 293 } 294 getPileupSlice( long offset, long length, int categories )295 public PileupIterator getPileupSlice ( long offset, long length, int categories ) 296 throws ErrorMsg 297 { 298 long ref = this . GetPileupSlice ( self, offset, length, categories ); 299 try 300 { 301 return new PileupIteratorItf ( ref ); 302 } 303 catch ( Exception x ) 304 { 305 this . release ( ref ); 306 throw new ErrorMsg ( x . toString () ); 307 } 308 } 309 getFilteredPileupSlice( long offset, long length, int categories, int filters, int mappingQuality )310 public PileupIterator getFilteredPileupSlice ( long offset, long length, int categories, int filters, int mappingQuality ) 311 throws ErrorMsg 312 { 313 long ref = this . GetFilteredPileupSlice ( self, offset, length, categories, filters, mappingQuality ); 314 try 315 { 316 return new PileupIteratorItf ( ref ); 317 } 318 catch ( Exception x ) 319 { 320 this . release ( ref ); 321 throw new ErrorMsg ( x . toString () ); 322 } 323 } 324 325 /******************************* 326 * ReferenceItf Implementation * 327 *******************************/ 328 329 // constructors ReferenceItf( long ref )330 ReferenceItf ( long ref ) 331 { 332 super ( ref ); 333 } 334 ReferenceItf( Reference obj )335 ReferenceItf ( Reference obj ) 336 throws ErrorMsg 337 { 338 super ( 0 ); 339 try 340 { 341 ReferenceItf ref = ( ReferenceItf ) obj; 342 this . self = ref . duplicate (); 343 } 344 catch ( Exception x ) 345 { 346 throw new ErrorMsg ( x . toString () ); 347 } 348 } 349 350 // native interface GetCommonName( long self )351 private native String GetCommonName ( long self ) 352 throws ErrorMsg; GetCanonicalName( long self )353 private native String GetCanonicalName ( long self ) 354 throws ErrorMsg; GetIsCircular( long self )355 private native boolean GetIsCircular ( long self ) 356 throws ErrorMsg; GetIsLocal( long self )357 private native boolean GetIsLocal ( long self ) 358 throws ErrorMsg; GetLength( long self )359 private native long GetLength ( long self ) 360 throws ErrorMsg; GetReferenceBases( long self, long offset, long length )361 private native String GetReferenceBases ( long self, long offset, long length ) 362 throws ErrorMsg; GetReferenceChunk( long self, long offset, long length )363 private native String GetReferenceChunk ( long self, long offset, long length ) 364 throws ErrorMsg; GetAlignmentCount( long self, int categories )365 private native long GetAlignmentCount ( long self, int categories ) 366 throws ErrorMsg; GetAlignment( long self, String alignmentId )367 private native long GetAlignment ( long self, String alignmentId ) 368 throws ErrorMsg; GetAlignments( long self, int categories )369 private native long GetAlignments ( long self, int categories ) 370 throws ErrorMsg; GetAlignmentSlice( long self, long offset, long length, int categories )371 private native long GetAlignmentSlice ( long self, long offset, long length, int categories ) 372 throws ErrorMsg; GetFilteredAlignmentSlice( long self, long offset, long length, int categories, int filters, int mappingQuality )373 private native long GetFilteredAlignmentSlice ( long self, long offset, long length, int categories, int filters, int mappingQuality ) 374 throws ErrorMsg; GetPileups( long self, int categories )375 private native long GetPileups ( long self, int categories ) 376 throws ErrorMsg; GetFilteredPileups( long self, int categories, int filters, int mappingQuality )377 private native long GetFilteredPileups ( long self, int categories, int filters, int mappingQuality ) 378 throws ErrorMsg; GetPileupSlice( long self, long offset, long count, int categories )379 private native long GetPileupSlice ( long self, long offset, long count, int categories ) 380 throws ErrorMsg; GetFilteredPileupSlice( long self, long offset, long count, int categories, int filters, int mappingQuality )381 private native long GetFilteredPileupSlice ( long self, long offset, long count, int categories, int filters, int mappingQuality ) 382 throws ErrorMsg; 383 } 384