Skip to content

Commit cfa1704

Browse files
committed
Add parameterized constructor to NCBIQBlastService to support BLAST on the cloud service providers
1 parent 084cd4a commit cfa1704

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

biojava-ws/src/main/java/demo/NCBIQBlastServiceDemo.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ public class NCBIQBlastServiceDemo {
4141
private static final String SEQUENCE = "MKWVTFISLLFLFSSAYSRGVFRRDAHKSEVAHRFKDLGEENFKALVLIAFAQYLQQCPFEDHVKLVNEVTEFAKTCVADESAENCDKS";
4242

4343
public static void main(String[] args) {
44-
NCBIQBlastService service = new NCBIQBlastService();
44+
NCBIQBlastService service = null;
45+
if (args.length == 1) {
46+
service = new NCBIQBlastService(args[0]);
47+
} else {
48+
service = new NCBIQBlastService();
49+
}
4550

4651
// set alignment options
4752
NCBIQBlastAlignmentProperties props = new NCBIQBlastAlignmentProperties();

biojava-ws/src/main/java/org/biojava/nbio/ws/alignment/qblast/NCBIQBlastService.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,36 @@ public class NCBIQBlastService implements RemotePairwiseAlignmentService {
7474

7575
private Map<String, BlastJob> jobs = new HashMap<String, BlastJob>();
7676

77+
/** Constructs a service object that targets the public NCBI BLAST network
78+
* service.
79+
*/
7780
public NCBIQBlastService() {
81+
init(SERVICE_URL);
82+
}
83+
84+
/** Constructs a service object which targets a custom NCBI BLAST network
85+
* service (e.g.: an instance of BLAST in the cloud).
86+
*
87+
* @param svcUrl : a {@code String} containing the base URL to send requests to,
88+
* e.g.: http://host.my.cloud.service.provider.com/cgi-bin/blast.cgi
89+
*
90+
* @see <a href="https://blast.ncbi.nlm.nih.gov/Blast.cgi?PAGE_TYPE=BlastDocs&DOC_TYPE=CloudBlast">BLAST on the cloud documentation</a>
91+
*/
92+
public NCBIQBlastService(String svcUrl) {
93+
init(svcUrl);
94+
}
95+
96+
/** Initialize the serviceUrl data member
97+
* @throws MalformedURLException on invalid URL
98+
*/
99+
private void init(String svcUrl) {
78100
try {
79-
serviceUrl = new URL(SERVICE_URL);
101+
serviceUrl = new URL(svcUrl);
80102
} catch (MalformedURLException e) {
81-
throw new RuntimeException("It looks like the URL for NCBI QBlast service is wrong. Cause: " + e.getMessage(), e);
103+
throw new RuntimeException("It looks like the URL for remote NCBI BLAST service ("
104+
+ svcUrl + ") is wrong. Cause: " + e.getMessage(), e);
82105
}
83-
}
106+
}
84107

85108
/**
86109
* A simple method to check the availability of the QBlast service. Sends {@code Info} command to QBlast
@@ -252,7 +275,7 @@ public boolean isReady(String id, long present) throws Exception {
252275
OutputStreamWriter writer = null;
253276
BufferedReader reader = null;
254277
try {
255-
String checkRequest = "CMD=Get&RID=" + job.getId();
278+
String checkRequest = "CMD=Get&RID=" + job.getId() + "&FORMAT_OBJECT=SearchInfo";
256279
URLConnection serviceConnection = setQBlastServiceProperties(serviceUrl.openConnection());
257280
writer = new OutputStreamWriter(serviceConnection.getOutputStream());
258281
writer.write(checkRequest);

0 commit comments

Comments
 (0)