9
9
import net .sourceforge .seqware .common .metadata .Metadata ;
10
10
import net .sourceforge .seqware .common .metadata .MetadataDB ;
11
11
import net .sourceforge .seqware .common .metadata .MetadataFactory ;
12
+ import net .sourceforge .seqware .common .model .ParentAccessionModel ;
12
13
import net .sourceforge .seqware .common .model .Processing ;
13
14
import net .sourceforge .seqware .common .module .FileMetadata ;
14
15
import net .sourceforge .seqware .common .module .ReturnValue ;
45
46
import java .util .zip .ZipFile ;
46
47
47
48
// FIXME: auto-adding to rc.data, support "," delimited
48
- // FIXME: When adding STDOUT/STDERR to metadb, we should add a timestamp or something else to make it easier to merge. Right now, it is hard to tell which stdout message corresponds to which step in stderr
49
+ // FIXME: When adding STDOUT/STDERR to metadb, we should add a timestamp or something else to make it easier to merge. Right now, it is hard to tell which stdout message corresponds to which step in stderr
49
50
// FIXME: is parent accession comma separated?
50
51
51
52
/*
52
53
* Run each method for the requested module object. Based on return value, either continue or exit:
53
54
* Return values > 0 are errors that will cause the runner to exit.
54
55
* Return of 0 implies success and the runner will continue, assuming all is well.
55
- * Return of -1 implies the method was not implemented for that Module, AND IS NOT AN ERROR!!! By default the runner will continue on with steps as if it succeeded!
56
+ * Return of -1 implies the method was not implemented for that Module, AND IS NOT AN ERROR!!! By default the runner will continue on with steps as if it succeeded!
56
57
*/
57
58
//Create a main() function here, which will be compiled in, to parse input and run all steps
58
59
/**
59
60
* <p>
60
61
* Runner class.
61
62
* </p>
62
- *
63
+ *
63
64
* @author boconnor
64
65
* @version $Id: $Id
65
66
*/
@@ -187,7 +188,7 @@ public Runner() {
187
188
* <p>
188
189
* getSyntax.
189
190
* </p>
190
- *
191
+ *
191
192
* @param parser
192
193
* a {@link joptsimple.OptionParser} object.
193
194
* @param errorMessage
@@ -213,19 +214,20 @@ public static void getSyntax(OptionParser parser, String errorMessage) {
213
214
System .exit (-1 );
214
215
}
215
216
216
- private void writeProcessingAccessionToFile (File file , boolean append ) {
217
+ private void writeStringToFile (File file , boolean append , String output ) {
217
218
int maxTries = (Integer ) options .valueOf ("metadata-tries-number" );
218
- for (int i = 0 ; i < maxTries ; i ++) {
219
+ for (int i = 0 ; i <= maxTries ; i ++) {
220
+ Log .fatal ("On try " + i + " of " + maxTries );
219
221
// Break on success
220
- if (LockingFileTools .lockAndWrite (file , processingAccession + System . getProperty ( "line.separator" ) , append )) {
222
+ if (LockingFileTools .lockAndWrite (file , output , append )) {
221
223
break ;
222
224
} // Sleep if going to try again
223
225
else if (i < maxTries ) {
224
226
ProcessTools .sleep ((Integer ) options .valueOf ("metadata-tries-delay" ));
225
227
} // Return error if failed on last try
226
- else {
228
+ if ( maxTries == i ) {
227
229
ReturnValue retval = new ReturnValue ();
228
- retval .printAndAppendtoStderr ("Could not write to processingAccession File for metadata" );
230
+ retval .printAndAppendtoStderr ("Could not write to " + file . getAbsolutePath () + " for metadata" );
229
231
retval .setExitStatus (ReturnValue .METADATAINVALIDIDCHAIN );
230
232
meta .update_processing_event (processingID , retval );
231
233
meta .update_processing_status (processingID , ProcessingStatus .failed );
@@ -238,7 +240,7 @@ else if (i < maxTries) {
238
240
* <p>
239
241
* printAndAppendtoStderr.
240
242
* </p>
241
- *
243
+ *
242
244
* @param buffer
243
245
* a {@link java.lang.String} object.
244
246
*/
@@ -251,7 +253,7 @@ public void printAndAppendtoStderr(String buffer) {
251
253
* <p>
252
254
* printAndAppendtoStdout.
253
255
* </p>
254
- *
256
+ *
255
257
* @param buffer
256
258
* a {@link java.lang.String} object.
257
259
*/
@@ -268,7 +270,7 @@ public void printAndAppendtoStdout(String buffer) {
268
270
* <p>
269
271
* evaluateReturn.
270
272
* </p>
271
- *
273
+ *
272
274
* @param app
273
275
* a {@link net.sourceforge.seqware.pipeline.module.Module} object.
274
276
* @param methodName
@@ -372,7 +374,7 @@ public void evaluateReturn(Module app, String methodName) {
372
374
373
375
/**
374
376
* FIXME: this needs to be migrated to something that is ZIP64 aware. Try using the unzip feature of FileTools.java
375
- *
377
+ *
376
378
* @param zipFile
377
379
* a {@link java.lang.String} object.
378
380
* @throws java.util.zip.ZipException
@@ -440,7 +442,7 @@ public static void unzipPkg(String zipFile) throws ZipException, IOException {
440
442
* <p>
441
443
* main.
442
444
* </p>
443
- *
445
+ *
444
446
* @param args
445
447
* an array of {@link java.lang.String} objects.
446
448
*/
@@ -644,24 +646,7 @@ private void preProcessMetadata() {
644
646
645
647
try {
646
648
if ((file .exists () || file .createNewFile ()) && file .canWrite ()) {
647
- int maxTries = (Integer ) options .valueOf ("metadata-tries-number" );
648
- for (int i = 0 ; i < maxTries ; i ++) {
649
- // Break on success
650
- if (LockingFileTools .lockAndAppend (file , workflowRunAccession + System .getProperty ("line.separator" ))) {
651
- break ;
652
- } // Sleep if going to try again
653
- else if (i < maxTries ) {
654
- ProcessTools .sleep ((Integer ) options .valueOf ("metadata-tries-delay" ));
655
- } // Return error if failed on last try
656
- else {
657
- ReturnValue retval = new ReturnValue ();
658
- retval .printAndAppendtoStderr ("Could not write to processingID File for metadata" );
659
- retval .setExitStatus (ReturnValue .METADATAINVALIDIDCHAIN );
660
- meta .update_processing_event (workflowRunAccession , retval );
661
- meta .update_processing_status (workflowRunAccession , ProcessingStatus .failed );
662
- System .exit (retval .getExitStatus ());
663
- }
664
- }
649
+ this .writeStringToFile (file , true , workflowRunAccession + System .getProperty ("line.separator" ));
665
650
} else {
666
651
Log .error ("Could not create processingAccession File for metadata" );
667
652
System .exit (ReturnValue .METADATAINVALIDIDCHAIN );
@@ -721,16 +706,29 @@ else if (i < maxTries) {
721
706
BufferedReader r ;
722
707
String line ;
723
708
r = new BufferedReader (new FileReader (file ));
724
-
709
+ boolean accessionFound = false ;
710
+ // seqware-2023, we need to ensure that there is at least one accession found
725
711
while ((line = r .readLine ()) != null ) {
726
712
try {
727
- parentAccessions .add (Integer .parseInt (line ));
713
+ int parseInt = Integer .parseInt (line );
714
+ parentAccessions .add (parseInt );
715
+ int [] accessions = new int [] { parseInt };
716
+ List <ParentAccessionModel > viaParentAccessions = meta .getViaParentAccessions (accessions );
717
+ if (viaParentAccessions == null ) {
718
+ Log .error ("Invalid accession found when parsing parent accession file '" + line + "'" );
719
+ System .exit (ReturnValue .METADATAINVALIDIDCHAIN );
720
+ }
721
+ accessionFound = true ;
728
722
} catch (NumberFormatException ex ) {
729
723
Log .error ("Non number found when parsing parent accession file '" + line + "'" );
730
724
System .exit (ReturnValue .METADATAINVALIDIDCHAIN );
731
725
}
732
726
}
733
727
r .close ();
728
+ if (!accessionFound ) {
729
+ Log .error ("No number found when parsing parent accession file '" + file + "'" );
730
+ System .exit (ReturnValue .METADATAINVALIDIDCHAIN );
731
+ }
734
732
} catch (Exception e ) {
735
733
Log .error ("Could not open parent accession file for metadata-parent-accession-file: " + e .getMessage ());
736
734
System .exit (ReturnValue .METADATAINVALIDIDCHAIN );
@@ -882,35 +880,18 @@ private void postProcessMetadata() {
882
880
// Try to write to each processingIDFile until success or timeout
883
881
for (File file : processingIDFiles ) {
884
882
Log .debug ("Writing out accession to " + file .toString ());
885
- int maxTries = (Integer ) options .valueOf ("metadata-tries-number" );
886
- for (int i = 0 ; i < maxTries ; i ++) {
887
- // Break on success
888
- if (LockingFileTools .lockAndAppend (file , processingID + System .getProperty ("line.separator" ))) {
889
- break ;
890
- } // Sleep if going to try again
891
- else if (i < maxTries ) {
892
- ProcessTools .sleep ((Integer ) options .valueOf ("metadata-tries-delay" ));
893
- } // Return error if failed on last try
894
- else {
895
- ReturnValue retval = new ReturnValue ();
896
- retval .printAndAppendtoStderr ("Could not write to processingID File for metadata" );
897
- retval .setExitStatus (ReturnValue .METADATAINVALIDIDCHAIN );
898
- meta .update_processing_event (processingID , retval );
899
- meta .update_processing_status (processingID , ProcessingStatus .failed );
900
- System .exit (retval .getExitStatus ());
901
- }
902
- }
883
+ this .writeStringToFile (file , true , processingID + System .getProperty ("line.separator" ));
903
884
}
904
885
Log .debug ("Completed processingIDFiles" );
905
886
906
887
// Try to write to each processingAccessionFile until success or timeout
907
888
for (File file : processingAccessionFiles ) {
908
889
Log .debug ("Writing out to " + file .toString ());
909
- writeProcessingAccessionToFile (file , true );
890
+ writeStringToFile (file , true , processingAccession + System . getProperty ( "line.separator" ) );
910
891
}
911
892
Log .debug ("Completed processingAccessionFiles" );
912
893
if (processingAccessionFileCheck != null ) {
913
- writeProcessingAccessionToFile (processingAccessionFileCheck , false );
894
+ writeStringToFile (processingAccessionFileCheck , true , processingAccession + System . getProperty ( "line.separator" ) );
914
895
}
915
896
Log .debug ("Completed processingAccessionFileCheck" );
916
897
meta .update_processing_status (processingID , ProcessingStatus .success );
@@ -974,7 +955,7 @@ private void invokeModuleMethods() {
974
955
* <p>
975
956
* run.
976
957
* </p>
977
- *
958
+ *
978
959
* @param args
979
960
* an array of {@link java.lang.String} objects.
980
961
*/
0 commit comments