Skip to content

Commit ebb9d79

Browse files
EOberortnerEOberortner
authored andcommitted
bug fixes
1 parent fb397c2 commit ebb9d79

5 files changed

Lines changed: 113 additions & 40 deletions

File tree

src/main/java/gov/doe/jgi/boost/client/BOOSTClient.java

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
import org.sbolstandard.core2.SBOLReader;
1313
import org.sbolstandard.core2.SBOLValidationException;
1414

15+
import gov.doe.jgi.boost.client.constants.BOOSTClientConfigs;
1516
import gov.doe.jgi.boost.client.constants.BOOSTConstants;
1617
import gov.doe.jgi.boost.client.constants.BOOSTResources;
1718
import gov.doe.jgi.boost.client.constants.JSONKeys;
19+
import gov.doe.jgi.boost.client.utils.FileUtils;
1820
import gov.doe.jgi.boost.enums.FileFormat;
1921
import gov.doe.jgi.boost.enums.Strategy;
2022
import gov.doe.jgi.boost.enums.Vendor;
@@ -213,16 +215,22 @@ public String reverseTranslate(
213215
public String codonJuggle(
214216
final String sequencesFilename, boolean bAutoAnnotate,
215217
Strategy strategy, final String filenameCodonUsageTable,
216-
final FileFormat outputFormat)
218+
final FileFormat outputFormat, boolean useSBOL)
217219
throws BOOSTClientException, BOOSTBackEndException, IOException,
218220
SBOLValidationException, SBOLConversionException {
219221

220222
// verify for filename
221223
ParameterValueVerifier.verifyFilename(BOOSTConstants.INPUT_FILENAME, sequencesFilename);
222224

223225
// read the file as SBOLDocument
224-
SBOLDocument document = SBOLReader.read(sequencesFilename);
225-
return this.codonJuggle(document, bAutoAnnotate, strategy, filenameCodonUsageTable, outputFormat);
226+
if(useSBOL) {
227+
SBOLReader.setURIPrefix(BOOSTClientConfigs.SBOL_TARGET_NAMESPACE);
228+
SBOLDocument document = SBOLReader.read(sequencesFilename);
229+
return this.codonJuggle(document, bAutoAnnotate, strategy, filenameCodonUsageTable, outputFormat);
230+
}
231+
232+
String sequencesFileContent = FileUtils.readFile(sequencesFilename);
233+
return this.codonJuggle(sequencesFileContent, bAutoAnnotate, strategy, filenameCodonUsageTable, outputFormat);
226234
}
227235

228236

@@ -256,6 +264,38 @@ public String codonJuggle(
256264
return this.submitJob(requestData);
257265
}
258266

267+
/**
268+
*
269+
* @param sequenceFileConten
270+
* @param bAutoAnnotate
271+
* @param strategy
272+
* @param filenameCodonUsageTable
273+
* @param outputFormat
274+
*
275+
* @return
276+
*
277+
* @throws BOOSTClientException
278+
* @throws BOOSTBackEndException
279+
* @throws IOException
280+
* @throws JSONException
281+
* @throws SBOLConversionException
282+
*/
283+
public String codonJuggle(
284+
final String sequenceFileContent, boolean bAutoAnnotate,
285+
Strategy strategy, final String filenameCodonUsageTable,
286+
final FileFormat outputFormat)
287+
throws BOOSTClientException, BOOSTBackEndException, IOException,
288+
JSONException, SBOLConversionException {
289+
290+
// read the content of the file
291+
292+
// construct the request's JSON object
293+
JSONObject requestData = RequestBuilder.buildCodonJuggle(
294+
sequenceFileContent, bAutoAnnotate, strategy, filenameCodonUsageTable, outputFormat);
295+
296+
return this.submitJob(requestData);
297+
}
298+
259299
/**
260300
* The verify method submits a job to BOOST that verifies
261301
* sequences against DNA synthesis constraints.
@@ -402,6 +442,8 @@ public String partition(
402442
public String submitJob(final JSONObject requestData)
403443
throws BOOSTClientException, BOOSTBackEndException {
404444

445+
//System.out.println(BOOSTResources.BOOST_REST_URL + BOOSTResources.SUBMIT_JOB_RESOURCE);
446+
405447
// send the request
406448
Response response = RESTInvoker.sendPost(
407449
BOOSTResources.BOOST_REST_URL + BOOSTResources.SUBMIT_JOB_RESOURCE,
@@ -418,6 +460,7 @@ public String submitJob(final JSONObject requestData)
418460

419461
throw new BOOSTClientException("The server returned an unknown response!");
420462
}
463+
421464
throw new BOOSTBackEndException(
422465
response.getStatus(),
423466
response.readEntity(String.class));

src/main/java/gov/doe/jgi/boost/client/RequestBuilder.java

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,47 @@ public static JSONObject buildReverseTranslate(
118118
}
119119

120120

121+
/**
122+
*
123+
* @param designSequences
124+
* @param bAutoAnnotate
125+
* @param strategy
126+
* @param codonUsageTable
127+
* @param outputFormat
128+
*
129+
* @return
130+
*
131+
* @throws BOOSTClientException
132+
* @throws JSONException
133+
* @throws UnsupportedEncodingException
134+
* @throws SBOLConversionException
135+
*/
136+
public static JSONObject buildCodonJuggle(
137+
final SBOLDocument designSequences, boolean bAutoAnnotate,
138+
Strategy strategy, final String codonUsageTable,
139+
final FileFormat outputFormat)
140+
throws BOOSTClientException, JSONException, UnsupportedEncodingException, SBOLConversionException {
141+
142+
// write the SBOLDocument to a String
143+
try (
144+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
145+
) {
146+
147+
SBOLWriter.write(designSequences, outputStream);
148+
String designDoc = outputStream.toString("UTF-8");
149+
150+
// put its content into the JSON object
151+
if(designDoc != null && !designDoc.isEmpty()) {
152+
return buildCodonJuggle(designDoc, bAutoAnnotate, strategy, codonUsageTable, outputFormat);
153+
}
154+
155+
} catch(Exception e) {
156+
throw new BOOSTClientException(e.getMessage());
157+
}
158+
159+
return (JSONObject)null;
160+
161+
}
121162
/**
122163
*
123164
* @param designSequences
@@ -131,7 +172,7 @@ public static JSONObject buildReverseTranslate(
131172
* @throws JSONException
132173
*/
133174
public static JSONObject buildCodonJuggle(
134-
final SBOLDocument designSequences, boolean bAutoAnnotate,
175+
final String sequenceFileContent, boolean bAutoAnnotate,
135176
Strategy strategy, final String codonUsageTable,
136177
final FileFormat outputFormat)
137178
throws BOOSTClientException, JSONException, UnsupportedEncodingException, SBOLConversionException {
@@ -151,7 +192,7 @@ public static JSONObject buildCodonJuggle(
151192

152193
// sequence information
153194
reverseTranslateData.put(JSONKeys.SEQUENCE_INFORMATION,
154-
RequestBuilder.buildSequenceData(designSequences, SequenceType.DNA, bAutoAnnotate));
195+
RequestBuilder.buildSequenceData(sequenceFileContent, SequenceType.DNA, bAutoAnnotate));
155196

156197
// modification information
157198
reverseTranslateData.put(JSONKeys.MODIFICATION_INFORMATION,
@@ -447,6 +488,11 @@ public static JSONObject buildJobInformation(
447488
return jobInformation;
448489
}
449490

491+
public static JSONObject buildSequenceData(final SBOLDocument designSequences, SequenceType type,
492+
boolean bAutoAnnotate)
493+
throws BOOSTClientException, SBOLConversionException, UnsupportedEncodingException {
494+
return buildSequenceData(designSequences, type, bAutoAnnotate);
495+
}
450496
/**
451497
*
452498
* @param filename
@@ -458,31 +504,14 @@ public static JSONObject buildJobInformation(
458504
* @throws UnsupportedEncodingException
459505
* @throws IOException
460506
*/
461-
public static JSONObject buildSequenceData(final SBOLDocument designSequences, SequenceType type, boolean bAutoAnnotate)
507+
public static JSONObject buildSequenceData(final String sequenceFileContent, SequenceType type, boolean bAutoAnnotate)
462508
throws BOOSTClientException, SBOLConversionException, UnsupportedEncodingException {
463509

464510
// sequence information
465511
JSONObject sequenceData = new JSONObject();
466512

467-
// write the SBOLDocument to a String
468-
try (
469-
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
470-
) {
471-
472-
SBOLWriter.write(designSequences, outputStream);
473-
String designDoc = outputStream.toString("UTF-8");
474-
475-
System.out.println(designDoc);
476-
477-
// put its content into the JSON object
478-
if(designDoc != null && !designDoc.isEmpty()) {
479-
sequenceData.put(JSONKeys.TEXT, designDoc);
480-
}
481-
482-
} catch(Exception e) {
483-
throw new BOOSTClientException(e.getMessage());
484-
}
485-
513+
sequenceData.put(JSONKeys.TEXT, sequenceFileContent);
514+
486515
// sequence type
487516
JSONArray types = new JSONArray();
488517
types.put(type);

src/main/java/gov/doe/jgi/boost/client/constants/BOOSTResources.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class BOOSTResources {
1010
// public static String BOOST_REST_URL = "https://boost.jgi.doe.gov/rest";
1111

1212
// // BOOST dev
13-
public static String BOOST_REST_URL = "https://boost.jgi.doe.gov/Dev/rest";
13+
public static String BOOST_REST_URL = "https://boost-dev.jgi.doe.gov/rest";
1414

1515
// local
1616
// public static String BOOST_REST_URL = "http://localhost:8080/BOOST/rest";

src/main/java/gov/doe/jgi/boost/client/constants/LoginCredentials.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
public class LoginCredentials {
88

99
// -- alternative 1: provide your BOOST-JWT
10-
public static final String mJWT = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJkZWZhdWx0IiwiaWF0IjoxNTMxMTcwNDM4LCJzdWIiOiJib29zdCIsImlzcyI6ImJvb3N0In0.JdRmgGpeEtzeMZk7jaCGgzgEnQax5JF3JWJE5lElIRg";
11-
10+
public static final String mJWT = "put your BOOST JWT here";
11+
1212
// -- alternative 2: provide your user name and password
1313
public static final String mUserName = "put your user name here";
1414
public static final String mPassword = "put your password here";

src/test/java/gov/doe/jgi/boost/client/DemoClient.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ public static void main(String[] args)
3535
// -- alternative 2: provider you BOOST username and password
3636
BOOSTClient client = new BOOSTClient(LoginCredentials.mJWT);
3737

38-
// get the predefined hosts
39-
JSONObject jsonPredefinedHosts = client.getPredefinedHosts();
40-
try {
41-
System.out.println(jsonPredefinedHosts.toString(4));
42-
}catch(NullPointerException e) {
43-
System.out.println(e.getMessage() + " Error in jsonPredefinedHosts");
44-
System.exit(1);
45-
}
38+
// // get the predefined hosts
39+
// JSONObject jsonPredefinedHosts = client.getPredefinedHosts();
40+
// try {
41+
// System.out.println(jsonPredefinedHosts.toString(4));
42+
// }catch(NullPointerException e) {
43+
// System.out.println(e.getMessage() + " Error in jsonPredefinedHosts");
44+
// System.exit(1);
45+
// }
4646

4747
// set the target namespace
48-
BOOSTClientConfigs.SBOL_TARGET_NAMESPACE = "https://boost.jgi.doe.gov/";
48+
// BOOSTClientConfigs.SBOL_TARGET_NAMESPACE = "https://boost.jgi.doe.gov/";
4949

5050
// we store all submitted jobs in a hash-set
5151
Set<String> jobUUIDs = new HashSet<String>();
@@ -64,11 +64,12 @@ public static void main(String[] args)
6464
//
6565
// codon juggle
6666
String codonJuggleJobUUID = client.codonJuggle(
67-
"./data/codon_juggle.sbol.xml", // input sequences
68-
false, // exclusively 5'-3' coding sequences
67+
"./data/dna.fasta", // input sequences
68+
true, // exclusively 5'-3' coding sequences
6969
Strategy.Balanced, // codon selection strategy
7070
"Saccharomyces cerevisiae", // predefined host
71-
FileFormat.SBOL); // output format
71+
FileFormat.FASTA, // FASTA as output format
72+
false); // do not convert the content of dna.fasta to SBOL format
7273
if(null != codonJuggleJobUUID) {
7374
jobUUIDs.add(codonJuggleJobUUID);
7475
System.out.println("Data for codon Juggling :" + codonJuggleJobUUID );

0 commit comments

Comments
 (0)