Skip to content

Commit e3a8dcd

Browse files
committed
NCBIQBlastService replaced with the new implementation.
(For usage example see NCBIQBlastServiceDemo) git-svn-id: http://code.open-bio.org/repos/biojava/biojava-live/trunk@9533 7c6358e6-4a41-0410-a743-a5b2a554c398
1 parent 31eb18d commit e3a8dcd

20 files changed

Lines changed: 1130 additions & 2535 deletions

biojava3-core/src/test/java/org/biojava3/core/sequence/DNATest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.biojava3.core.sequence;
22

3-
import org.biojava3.core.sequence.template.SequenceReader;
43
import static org.hamcrest.CoreMatchers.is;
54
import static org.junit.Assert.assertThat;
65
import static org.junit.Assert.assertTrue;
@@ -9,19 +8,20 @@
98
import java.util.Arrays;
109
import java.util.List;
1110
import java.util.Map;
11+
1212
import junit.framework.Assert;
1313

1414
import org.biojava3.core.exceptions.CompoundNotFoundError;
1515
import org.biojava3.core.sequence.compound.AmbiguityDNACompoundSet;
1616
import org.biojava3.core.sequence.compound.DNACompoundSet;
1717
import org.biojava3.core.sequence.compound.NucleotideCompound;
18-
import org.biojava3.core.sequence.storage.BitSequenceReader;
1918
import org.biojava3.core.sequence.storage.FourBitSequenceReader;
2019
import org.biojava3.core.sequence.storage.SingleCompoundSequenceReader;
2120
import org.biojava3.core.sequence.storage.TwoBitSequenceReader;
2221
import org.biojava3.core.sequence.template.CompoundSet;
2322
import org.biojava3.core.sequence.template.ProxySequenceReader;
2423
import org.biojava3.core.sequence.template.SequenceMixin;
24+
import org.biojava3.core.sequence.template.SequenceReader;
2525
import org.biojava3.core.sequence.template.SequenceView;
2626
import org.biojava3.core.sequence.transcription.Frame;
2727
import org.biojava3.core.sequence.views.ComplementSequenceView;

biojava3-ws/src/main/java/demo/NCBIQBlastService2Demo.java

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package demo;
2+
3+
import static org.biojava3.ws.alignment.qblast.BlastAlignmentParameterEnum.ENTREZ_QUERY;
4+
5+
import java.io.BufferedReader;
6+
import java.io.File;
7+
import java.io.FileWriter;
8+
import java.io.InputStream;
9+
import java.io.InputStreamReader;
10+
11+
import org.biojava3.core.sequence.io.util.IOUtils;
12+
import org.biojava3.ws.alignment.qblast.BlastProgramEnum;
13+
import org.biojava3.ws.alignment.qblast.NCBIQBlastAlignmentProperties;
14+
import org.biojava3.ws.alignment.qblast.NCBIQBlastOutputProperties;
15+
import org.biojava3.ws.alignment.qblast.NCBIQBlastService;
16+
17+
/**
18+
* A simple demo showing {@link NCBIQBlastService} usage
19+
*
20+
* @author Gediminas Rimsa
21+
*/
22+
public class NCBIQBlastServiceDemo {
23+
private static final String BLAST_OUTPUT_FILE = "blastOutput.xml";
24+
25+
private static final String SEQUENCE = "MKWVTFISLLFLFSSAYSRGVFRRDAHKSEVAHRFKDLGEENFKALVLIAFAQYLQQCPFEDHVKLVNEVTEFAKTCVADESAENCDKS";
26+
27+
public static void main(String[] args) {
28+
NCBIQBlastService service = new NCBIQBlastService();
29+
30+
// set alignment options
31+
NCBIQBlastAlignmentProperties props = new NCBIQBlastAlignmentProperties();
32+
props.setBlastProgram(BlastProgramEnum.blastp);
33+
props.setBlastDatabase("swissprot");
34+
props.setAlignmentOption(ENTREZ_QUERY, "\"serum albumin\"[Protein name] AND mammals[Organism]");
35+
36+
// set output options
37+
NCBIQBlastOutputProperties outputProps = new NCBIQBlastOutputProperties();
38+
39+
// Example of two possible ways of setting output options (in this case, it was already set by constructor)
40+
// outputProps.setAlignmentNumber(100);
41+
// outputProps.setOutputOption(BlastOutputParameterEnum.ALIGNMENTS, "100");
42+
43+
String rid = null;
44+
FileWriter writer = null;
45+
BufferedReader reader = null;
46+
try {
47+
// send blast request and save request id
48+
rid = service.sendAlignmentRequest(SEQUENCE, props);
49+
50+
while (!service.isReady(rid)) {
51+
System.out.println("Waiting for results. Sleeping for 5 seconds");
52+
Thread.sleep(5000);
53+
}
54+
55+
// read results when they are ready
56+
InputStream in = service.getAlignmentResults(rid, outputProps);
57+
reader = new BufferedReader(new InputStreamReader(in));
58+
59+
File f = new File(BLAST_OUTPUT_FILE);
60+
System.out.println("Saving query results in file " + f.getAbsolutePath());
61+
writer = new FileWriter(f);
62+
63+
String line;
64+
while ((line = reader.readLine()) != null) {
65+
writer.write(line + System.getProperty("line.separator"));
66+
}
67+
} catch (Exception e) {
68+
System.out.println(e.getMessage());
69+
e.printStackTrace();
70+
} finally {
71+
IOUtils.close(writer);
72+
IOUtils.close(reader);
73+
service.sendDeleteRequest(rid);
74+
}
75+
}
76+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* BioJava development code
3+
*
4+
* This code may be freely distributed and modified under the
5+
* terms of the GNU Lesser General Public Licence. This should
6+
* be distributed with the code. If you do not have a copy,
7+
* see:
8+
*
9+
* http://www.gnu.org/copyleft/lesser.html
10+
*
11+
* Copyright for this code is held jointly by the individual
12+
* authors. These should be listed in @author doc comments.
13+
*
14+
* For more information on the BioJava project and its aims,
15+
* or to join the biojava-l mailing list, visit the home page
16+
* at:
17+
*
18+
* http://www.biojava.org/
19+
*
20+
* Created on 2012-02-11
21+
*
22+
*/
23+
24+
package org.biojava3.ws.alignment.qblast;
25+
26+
/**
27+
* Alignment request parameters accepted by QBlast service.<br/>
28+
* Not all are mandatory. Certain parameters only work with a subset of other parameters in the list.
29+
* <p/>
30+
* Taken from <a href=http://www.ncbi.nlm.nih.gov/staff/tao/URLAPI/new/node9.html>Blast URL API</a>
31+
*
32+
* @author Gediminas Rimsa
33+
*/
34+
public enum BlastAlignmentParameterEnum {
35+
36+
CMD,
37+
TOOL,
38+
EMAIL,
39+
40+
ALIGNMENTS,
41+
BLAST_PROGRAM,
42+
CDD_SEARCH,
43+
COMPOSITION_BASED_STATISTICS,
44+
DATABASE_PREFIX,
45+
DATABASE,
46+
DB_GENETIC_CODE,
47+
DESCRIPTIONS,
48+
ENTREZ_QUERY,
49+
EXPECT,
50+
FILTER,
51+
FIRST_QUERY_NUM,
52+
GAPCOSTS,
53+
GENETIC_CODE,
54+
HITLIST_SIZE,
55+
I_THRESH,
56+
LCASE_MASK,
57+
MATCH_SCORES,
58+
MATRIX_NAME,
59+
MAX_NUM_SEQ,
60+
MEGABLAST,
61+
NUM_OVERVIEW,
62+
OTHER_ADVANCED,
63+
PERC_IDENT,
64+
PHI_PATTERN,
65+
PROGRAM,
66+
PSSM,
67+
QUERY,
68+
QUERY_BELIEVE_DEFLINE,
69+
QUERY_FROM,
70+
QUERY_TO,
71+
REPEATS,
72+
SHORT_QUERY_ADJUST,
73+
SEARCHSP_EFF,
74+
TEMPLATE_LENTH,
75+
TEMPLATE_TYPE,
76+
THRESHOLD,
77+
TWO_HITS,
78+
WORD_SIZE,
79+
WWW_BLAST_TYPE
80+
81+
}

biojava3-ws/src/main/java/org/biojava3/ws/alignment/qblast2/NCBIQBlastJob.java renamed to biojava3-ws/src/main/java/org/biojava3/ws/alignment/qblast/BlastJob.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,22 @@
2121
*
2222
*/
2323

24-
package org.biojava3.ws.alignment.qblast2;
24+
package org.biojava3.ws.alignment.qblast;
2525

2626
/**
27-
* Used to store information about QBlast search job, namely: request ID, start
28-
* time, expected execution time
27+
* Information about QBlast search job
2928
*
3029
* @author Gediminas Rimsa
3130
*/
32-
public class NCBIQBlastJob {
31+
public class BlastJob {
3332
private String id;
3433
private long startTimestamp;
3534
private long expectedExecutionTime;
3635

36+
/**
37+
* Request id (RID) as received from QBlast server
38+
* @return
39+
*/
3740
public String getId() {
3841
return id;
3942
}
@@ -57,4 +60,18 @@ public long getExpectedExecutionTime() {
5760
public void setExpectedExecutionTime(long expectedExecutionTime) {
5861
this.expectedExecutionTime = expectedExecutionTime;
5962
}
63+
64+
@Override
65+
public String toString() {
66+
StringBuilder builder = new StringBuilder();
67+
builder.append("BlastJob [id=");
68+
builder.append(id);
69+
builder.append(", startTimestamp=");
70+
builder.append(startTimestamp);
71+
builder.append(", expectedExecutionTime=");
72+
builder.append(expectedExecutionTime);
73+
builder.append("]");
74+
return builder.toString();
75+
}
76+
6077
}

biojava3-ws/src/main/java/org/biojava3/ws/alignment/qblast2/enums/BlastMatrix.java renamed to biojava3-ws/src/main/java/org/biojava3/ws/alignment/qblast/BlastMatrixEnum.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
*
2222
*/
2323

24-
package org.biojava3.ws.alignment.qblast2.enums;
24+
package org.biojava3.ws.alignment.qblast;
2525

2626
/**
27-
* Enum representing blast matrices supported by QBlast
27+
* Enum representing matrices supported by QBlast
2828
*
2929
* @author Gediminas Rimsa
3030
*/
31-
public enum BlastMatrix {
31+
public enum BlastMatrixEnum {
32+
3233
BLOSUM45,
3334
BLOSUM50,
3435
BLOSUM62,
@@ -37,4 +38,5 @@ public enum BlastMatrix {
3738
PAM250,
3839
PAM30,
3940
PAM70
41+
4042
}

0 commit comments

Comments
 (0)