Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NCBIQBlastService.sendAlignmentRequest | Always throws ArrayIndexOutOfBoundsException #1033

Open
FC123321 opened this issue Jun 30, 2022 · 1 comment

Comments

@FC123321
Copy link

FC123321 commented Jun 30, 2022

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.

@FC123321 FC123321 changed the title NCBIQBlastService.sendAlignmentRequest NCBIQBlastService.sendAlignmentRequest | Always throws ArrayIndexOutOfBoundsException Jun 30, 2022
@josemduarte
Copy link
Contributor

Thanks for reporting. My guess is that something has changed in the output format and now this always fails. At a minimum, there should be a check for the array length before trying to put it in the message. In any case it seems like a bad idea to have to parse html for this. I guess there's a better way to run blast via an API these days?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants