| 56 | |
| 57 | Data data = new Data(); |
| 58 | DataHeader dHeader = new DataHeader(); |
| 59 | data.setDataHeader(dHeader); |
| 60 | data.getDataHeader().setMethod(somemethod); // somemethod is the Method object initialized in the wizard with all the different annotation settings |
| 61 | }}} |
| 62 | |
| 63 | During annotation this data file is populated with annotation information and written to the file (see |
| 64 | |
| 65 | 4. Saving the metadata and annotation files |
| 66 | {{{ |
| 67 | |
| 68 | // if everything worked, save to workspace all of the appropriate files for Annotation |
| 69 | msAnnotProperty.getMSAnnotationMetaData().addAnnotationFile(dataFile); // dataFile is the file we have used for annotation (a handle (MSPropertyDataFile) to the mzxml file for example) |
| 70 | |
| 71 | PropertyDataFile msMetaData = MSAnnotationProperty.getNewSettingsFile(msAnnotProperty.getMetaDataFileName(), msAnnotProperty.getMSAnnotationMetaData()); |
| 72 | msAnnotProperty.getDataFiles().add(msMetaData); |
| 73 | addResultFileToMetaData(dHeader.getMethod().getMsType(), msAnnotProperty); |
| 74 | MSAnnotationProperty.marshallSettingsFile(msAnnotProperty.getAnnotationFolder(msEntry) + File.separator + msAnnotProperty.getMetaDataFileName(), msAnnotProperty.getMSAnnotationMetaData()); |
61 | | |
62 | | final MassSpecProperty prop = (MassSpecProperty) msEntry.getProperty(); |
63 | | Entry msAnnotationEntry = new Entry(); |
64 | | String sWorkspaceFolder = fWorkspaceFolderFile.getAbsolutePath(); |
| 79 | protected void addResultFileToMetaData(String sMSType, MSAnnotationProperty msAnnotProperty) { |
| 80 | if( sMSType.equals(Method.MS_TYPE_LC) ) { |
| 81 | NewGelatoHandlerLCMSMS.addResultFileToMetaData(gsa, (MSGlycanAnnotationProperty) msAnnotProperty); |
| 82 | } else { |
| 83 | NewGelatoHandler.addResultFileToMetaData(gsa, msAnnotProperty); |
| 84 | } |
| 85 | } |
66 | | File msAnnFile = getAnnotationFolder(msEntry); |
67 | | String msAnnotationFolder = msAnnFile.getAbsolutePath(); |
68 | | MSGlycanAnnotationProperty msAnnotProperty = (MSGlycanAnnotationProperty) getMSAnnotationProperty(shell, wizard, msAnnotationFolder); |
| 87 | /** |
| 88 | * Determines the annotation file name and folder name (if applicable), creates MSPropertyDataFile objects for them, and adds |
| 89 | * them to the meta data for the result files. |
| 90 | * |
| 91 | * @param gsa, the GlycanStructureAnnotation specific for the MS Type other than LC-MS/MS |
| 92 | * @param msAnnotProperty, the Property to add the results file to |
| 93 | */ |
| 94 | private static void addResultFileToMetaData(GlycanStructureAnnotation gsa, MSAnnotationProperty msAnnotProperty) { |
| 95 | String sAnnotationFile = gsa.getFinalArchiveName(); |
| 96 | File annotationFile = new File( sAnnotationFile ); |
| 97 | MSPropertyDataFile pdfFolder = new MSPropertyDataFile(annotationFile.getName(), |
| 98 | MSAnnotationFileInfo.MS_ANNOTATION_CURRENT_VERSION, |
| 99 | MSAnnotationFileInfo.MS_ANNOTATION_TYPE_FILE, |
| 100 | FileCategory.ANNOTATION_CATEGORY, |
| 101 | GeneralInformationMulti.FILE_TYPE_GELATO, |
| 102 | annotationFile.getPath(), new ArrayList<String>() ); |
| 103 | msAnnotProperty.getMSAnnotationMetaData().addFile(pdfFolder); |
78 | | MSPropertyDataFile dataFile = wizard.getInitial().getFileMap().get(msEntry.getDisplayName()); |
79 | | String workspaceLocation = PropertyHandler.getVariable("workspace_location"); |
80 | | String projectName = DataModelSearch.findParentByType(msEntry, ProjectProperty.TYPE).getDisplayName(); |
81 | | String pathToFile = workspaceLocation + projectName + File.separator + MassSpecProperty.getFoldername(); |
| 110 | {{{ |
| 111 | gritsDataModelService.addEntry (msEntry, msAnnotationEntry); |
| 112 | // parent of MS Entry is Sample, parent of Sample is the Project |
| 113 | ProjectFileHandler.saveProject(msEntry.getParent().getParent()); |
| 114 | }}} |
83 | | // call performAnnotation - does all the work. |
84 | | iStatus = performAnnotation( gpd, data, sWorkspaceFolder, msAnnotationFolder, msAnnotProperty, |
85 | | dataFile.getMSFileWithReader(pathToFile, prop.getMassSpecMetaData().getMsExperimentType())); |
86 | | if( iStatus == GRITSProcessStatus.OK ) { |
87 | | // if everything worked, save to workspace all of the appropriate files for Annotation |
88 | | msAnnotProperty.getMSAnnotationMetaData().addAnnotationFile(dataFile); |
| 116 | 6. Locking the annotation files since they are now used in an annotation. This allows us to mark (annotation) files as "in use" in MS entry display. (see org.grits.toolbox.importer.ms.annotation.glycan.simiansearch.handler.OpenGelatoWizard) |
90 | | PropertyDataFile msMetaData = MSAnnotationProperty.getNewSettingsFile(msAnnotProperty.getMetaDataFileName(), msAnnotProperty.getMSAnnotationMetaData()); |
91 | | msAnnotProperty.getDataFiles().add(msMetaData); |
92 | | addResultFileToMetaData(dHeader.getMethod().getMsType(), msAnnotProperty); |
93 | | MSAnnotationProperty.marshallSettingsFile(msAnnotProperty.getAnnotationFolder(msEntry) + File.separator + |
94 | | msAnnotProperty.getMetaDataFileName(), msAnnotProperty.getMSAnnotationMetaData()); |
| 118 | {{{ |
| 119 | private void lockFiles(MSGlycanAnnotationWizard wizard, Entry msEntry, Entry msAnnotationEntry) { |
| 120 | MassSpecProperty prop = (MassSpecProperty) msEntry.getProperty(); |
| 121 | FileLockManager mng; |
| 122 | try { |
| 123 | String lockFileLocation = prop.getLockFilePath(msEntry); |
| 124 | mng = FileLockingUtils.readLockFile(lockFileLocation); |
| 125 | MSPropertyDataFile file = wizard.getInitial().getFileMap().get(msEntry.getDisplayName()); |
| 126 | if (file != null) { |
| 127 | mng.lockFile(file.getName(), msAnnotationEntry); |
| 128 | FileLockingUtils.writeLockFile(mng, lockFileLocation); |
| 129 | } |
| 130 | } catch (IOException e) { |
| 131 | logger.error("Could not lock the file", e); |
| 132 | } catch (JAXBException e) { |
| 133 | logger.error("Could not lock the file", e); |
| 134 | } |
| 135 | } |
100 | | // return list is a List<Entry[]>. |
101 | | returnList.add(entries); |
102 | | } else if (iStatus == GRITSProcessStatus.CANCEL) { |
103 | | deleteResultFiles(dHeader.getMethod().getMsType()); |
| 139 | 7. Opening the editor to display the annotation results (see org.grits.toolbox.importer.ms.annotation.glycan.simiansearch.handler.OpenGelatoWizard): |
| 140 | |
| 141 | {{{ |
| 142 | |
| 143 | try { |
| 144 | // need to set the partService to refresh gritsUIServices' stale partService, see ticket #799 |
| 145 | gritsUIService.setPartService(partService); |
| 146 | gritsUIService.openEntryInPart(msAnnotationEntry); |
| 147 | } catch (Exception e) { |
| 148 | logger.debug("Could not open the part", e); |
108 | | |
109 | | {{{ |
110 | | |
111 | | |
112 | | List<Entry[]> resultEntries = handler.process(shell2); |
113 | | if( resultEntries != null ) { |
114 | | for( int i = 0; i < resultEntries.size(); i++ ) { |
115 | | Entry[] curEntries = resultEntries.get(i); |
116 | | gritsDataModelService.addEntry(curEntries[0], curEntries[1]); |
117 | | } |
118 | | } |
119 | | |
120 | | if( resultEntries != null && ! resultEntries.isEmpty() && resultEntries.get(resultEntries.size()-1)[1] != null ) { |
121 | | // save the project first |
122 | | try |
123 | | { |
124 | | // parent of MS Entry is Sample, parent of Sample is the Project |
125 | | ProjectFileHandler.saveProject(resultEntries.get(resultEntries.size()-1)[0].getParent().getParent()); |
126 | | } catch (IOException e) |
127 | | { |
128 | | logger.error("Something went wrong while saving project entry \n" + e.getMessage(),e); |
129 | | logger.fatal("Closing project entry \"" |
130 | | + resultEntries.get(resultEntries.size()-1)[0].getParent().getParent().getDisplayName() + "\""); |
131 | | gritsDataModelService.closeProject(resultEntries.get(resultEntries.size()-1)[0].getParent().getParent()); |
132 | | throw e; |
133 | | } |
134 | | for( int i = 0; i < resultEntries.size(); i++ ) { |
135 | | Entry[] curEntries = resultEntries.get(i); |
136 | | lockFiles (wizard, curEntries[0], curEntries[1]); |
137 | | } |
138 | | final Entry lastMSEntry = (Entry) resultEntries.get(resultEntries.size()-1)[1] ; |
139 | | eventBroker.send(IGritsDataModelService.EVENT_SELECT_ENTRY, lastMSEntry); |
140 | | |
141 | | try { |
142 | | // need to set the partService to refresh gritsUIServices' stale partService, see ticket #799 |
143 | | gritsUIService.setPartService(partService); |
144 | | gritsUIService.openEntryInPart(lastMSEntry); |
145 | | } catch (Exception e) { |
146 | | logger.debug("Could not open the part", e); |
147 | | } |
148 | | } |
149 | | |
150 | | }}} |