-
- public static List<String> queryEmblDb( final Identifier id, final int max_lines_to_return ) throws IOException {
- final StringBuilder url_sb = new StringBuilder();
- url_sb.append( BASE_EMBL_DB_URL );
- if ( ForesterUtil.isEmpty( id.getProvider() ) || id.getProvider().equalsIgnoreCase( Identifier.NCBI ) ) {
- url_sb.append( SequenceDbWsTools.EMBL_DBS_EMBL );
- url_sb.append( '/' );
- }
- else if ( id.getProvider().equalsIgnoreCase( Identifier.REFSEQ ) ) {
- if ( id.getValue().toUpperCase().indexOf( 'P' ) == 1 ) {
- url_sb.append( SequenceDbWsTools.EMBL_DBS_REFSEQ_P );
- url_sb.append( '/' );
- }
- else {
- url_sb.append( SequenceDbWsTools.EMBL_DBS_REFSEQ_N );
- url_sb.append( '/' );
- }
- }
- return queryDb( id.getValue(), max_lines_to_return, url_sb.toString() );
- }
-
- public static List<String> queryUniprot( final String query, final int max_lines_to_return ) throws IOException {
- return queryDb( query, max_lines_to_return, BASE_UNIPROT_URL );
- }
-
- public static List<String> queryDb( final String query, int max_lines_to_return, final String base_url )
- throws IOException {
- if ( ForesterUtil.isEmpty( query ) ) {
- throw new IllegalArgumentException( "illegal attempt to use empty query " );
- }
- if ( max_lines_to_return < 1 ) {
- max_lines_to_return = 1;
- }
- final URL url = new URL( base_url + query );
- if ( DEBUG ) {
- System.out.println( "url: " + url.toString() );
- }
- final URLConnection urlc = url.openConnection();
- final BufferedReader in = new BufferedReader( new InputStreamReader( urlc.getInputStream() ) );
- String line;
- final List<String> result = new ArrayList<String>();
- while ( ( line = in.readLine() ) != null ) {
- if ( DEBUG ) {
- System.out.println( line );
- }
- result.add( line );
- if ( result.size() > max_lines_to_return ) {
- break;
- }
- }
- in.close();
- try {
- // To prevent accessing online dbs in too quick succession.
- Thread.sleep( 20 );
- }
- catch ( final InterruptedException e ) {
- e.printStackTrace();
- }
- return result;
- }
-
- public static SequenceDatabaseEntry obtainUniProtEntry( final String query, final int max_lines_to_return )
- throws IOException {
- final List<String> lines = queryUniprot( "uniprot/" + query + ".txt", max_lines_to_return );
- return UniProtEntry.createInstanceFromPlainText( lines );
- }
-
- public static SequenceDatabaseEntry obtainRefSeqEntryFromEmbl( final Identifier id, final int max_lines_to_return )
- throws IOException {
- final List<String> lines = queryEmblDb( id, max_lines_to_return );
- return EbiDbEntry.createInstanceFromPlainTextForRefSeq( lines );
- }
-
- public static SequenceDatabaseEntry obtainEmblEntry( final Identifier id, final int max_lines_to_return )
- throws IOException {
- final List<String> lines = queryEmblDb( id, max_lines_to_return );
- return EbiDbEntry.createInstanceFromPlainText( lines );
- }