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 examples; 28 29 import ngs.ErrorMsg; 30 import ngs.ReadCollection; 31 import ngs.Reference; 32 import ngs.AlignmentIterator; 33 import ngs.Alignment; 34 35 public class AlignSliceTest 36 { run( String acc, String refname, int start, int stop )37 static void run ( String acc, String refname, int start, int stop ) 38 throws ErrorMsg, Exception 39 { 40 41 // open requested accession using SRA implementation of the API 42 ReadCollection run = gov.nih.nlm.ncbi.ngs.NGS.openReadCollection ( acc ); 43 String run_name = run.getName (); 44 45 // get requested reference 46 Reference ref = run.getReference ( refname ); 47 48 // start iterator on requested range of primary alignments 49 long length = stop - start + 1; 50 AlignmentIterator it = ref.getAlignmentSlice ( start, length, Alignment.primaryAlignment ); 51 52 // walk all primary alignments within range 53 long i; 54 for ( i = 0; it.nextAlignment (); ++ i ) 55 { 56 System.out.println ( it.getReadId () 57 +'\t'+ it.getReferenceSpec () 58 +'\t'+ it.getAlignmentPosition () 59 +'\t'+ it.getLongCigar ( false ) // unclipped 60 +'\t'+ it.getAlignedFragmentBases () 61 ); 62 } 63 64 // report to stderr 65 System.err.println ( "Read " + i + " alignments for " + run_name ); 66 } 67 main( String [] args )68 public static void main ( String [] args ) 69 { 70 if ( args.length != 4 ) 71 { 72 System.out.print ( "Usage: AlignSliceTest accession reference start stop\n" ); 73 } 74 else try 75 { 76 run ( args[0], args[1], Integer.parseInt ( args[2] ), Integer.parseInt ( args[3] ) ); 77 } 78 catch ( ErrorMsg x ) 79 { 80 System.err.println ( x.toString () ); 81 x.printStackTrace (); 82 } 83 catch ( Exception x ) 84 { 85 System.err.println ( x.toString () ); 86 x.printStackTrace (); 87 } 88 } 89 } 90