Skip to content

NCBIQBlastService.sendAlignmentRequest | Always throws ArrayIndexOutOfBoundsException #1033

@FC123321

Description

@FC123321

I am using BioJava through Maven, using biojava 6.0.5 and biojava-ws 6.0.4 (because trying to use 6.0.5 produces errors):

<!-- https://mvnrepository.com/artifact/org.biojava/biojava -->
<dependency>
   <groupId>org.biojava</groupId>
   <artifactId>biojava</artifactId>
   <version>6.0.5</version>
   <type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/org.biojava/biojava-ws -->
<dependency>
   <groupId>org.biojava</groupId>
   <artifactId>biojava-ws</artifactId>
   <version>6.0.4</version>
</dependency>

I'm trying to submit blast requests to NCBI. To do this, I have largely followed this guide:
https://biojava.org/wiki/BioJava:CookBook3:NCBIQBlastService

My relevant code is as follows:

private NCBIQBlastAlignmentProperties inputProperties = new NCBIQBlastAlignmentProperties();
private NCBIQBlastService service = new NCBIQBlastService();

...

inputProperties.setBlastDatabase("swissprot");
inputProperties.setBlastExpect(Double.parseDouble("1e-10"));
inputProperties.setBlastProgram(BlastProgramEnum.blastp);
inputProperties.setAlignmentOption(BlastAlignmentParameterEnum.ENTREZ_QUERY, "<redacted>");   //Note this redaction is not in my original code.

...

System.out.println("Submitting " + inputSequences.getSize() + " requests");
for(int i=0; i<inputSequences.getSize(); i++)
{
   try
   {
      rids.add(this.service.sendAlignmentRequest(inputSequences.getSequence(i), inputProperties));
   }
   catch (Exception e)
   {
      e.printStackTrace();
   }
}

Note that "rids" is an ArrayList for storing rid strings and inputSequences is an instance of a class which stores sequence data as String.

When executed, the following error is thrown on each iteration of the for loop:

java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
at org.biojava.nbio.ws.alignment.qblast.NCBIQBlastService.sendAlignmentRequest(NCBIQBlastService.java:223)

Note that this error is not being thrown by my code, but by the NCBIQBlastService module. Going to this point in the code leads to the following block in NCBIQBlastService:

BlastJob job = new BlastJob();
String line;
while ((line = reader.readLine()) != null) {
   if (!line.contains("class=\"error\"") && !line.contains("Message ID#")) {
      // if there is no error, capture RID and RTOE
      if (line.contains("RID = ")) {
         String[] arr = line.split("=");
         job.setId(arr[1].trim());
      } else if (line.contains("RTOE = ")) {
         String[] arr = line.split("=");
         job.setStartTimestamp(System.currentTimeMillis());
         job.setExpectedExecutionTime(Long.parseLong(arr[1].trim()) * 1000);
      }
      jobs.put(job.getId(), job);
   } else {
      // handle QBlast error message

      // Capture everything to the left of this HTML statement...
      String[] tmp = line.split("</p></li></ul>");

      // Only the error message is on the right side of this...
      String[] moreTmp = tmp[0].split("<p class=\"error\">");
      throw new Exception("NCBI QBlast refused this request because: " + moreTmp[1].trim());
   }

}

Specifically, the line "throw new Exception("NCBI QBlast refused this request because: " + moreTmp[1].trim());" is throwing the ArrayIndexOutOfBoundsException. Evidently there is something wrong with my request, hence why I'm getting the error handler, but I can't determine what that reason is is because moreTmp[1] is out of moreTmp's bounds (according to the error message it only has one element). Consequently, the exception the code is trying to throw doesn't get thrown and the reason for the refusal of the request is lost.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions