| 1 | == Creating an annotation entry == |
| 2 | |
| 3 | At the end of the annotation, we need to create a new MS Annotation Entry and add that as a child entry for the corresponding MS Entry and save the project (that contains the MS Entry) to make changes permanent. |
| 4 | |
| 5 | * Creation of a MS Annotation Entry and its corresponding Property |
| 6 | |
| 7 | Several steps are included in this process: |
| 8 | |
| 9 | 1. Create a new Entry and set its display name: In the example below, we are getting the name from the wizard where a user enters a name for the annotation for each MS entry that is annotated. |
| 10 | |
| 11 | {{{ |
| 12 | Entry msAnnotationEntry = new Entry(); |
| 13 | |
| 14 | String msEntryDisplayName = msEntry.getDisplayName(); |
| 15 | String msAnnotName = wizard.getInitial().getListEntries().get(msEntryDisplayName); |
| 16 | msAnnotationEntry.setDisplayName(msAnnotName); |
| 17 | }}} |
| 18 | |
| 19 | 2. Creating the property: We need to know the annotation folder to be able to assign a unique annotation id to the metadata in the property. "createRandomId" does the following: randomly generate an id and check to make sure it does not exist in the folder already. |
| 20 | |
| 21 | {{{ |
| 22 | // getting the annotation folder |
| 23 | File msAnnFile = getAnnotationFolder(msEntry); |
| 24 | String msAnnotationFolder = msAnnFile.getAbsolutePath(); |
| 25 | |
| 26 | MSGlycanAnnotationProperty t_property = new MSGlycanAnnotationProperty(); |
| 27 | MSGlycanAnnotationMetaData metaData = new MSGlycanAnnotationMetaData(); |
| 28 | t_property.setMSAnnotationMetaData(metaData); |
| 29 | metaData.setAnnotationId(this.createRandomId(msAnnotationFolder)); |
| 30 | metaData.setDescription(somedescripton); |
| 31 | metaData.setVersion(MSGlycanAnnotationMetaData.CURRENT_VERSION); |
| 32 | metaData.setName(t_property.getMetaDataFileName()); |
| 33 | |
| 34 | }}} |
| 35 | |
| 36 | Getting the annotation folder for the given ms entry: |
| 37 | |
| 38 | {{{ |
| 39 | protected File getAnnotationFolder( Entry msEntry ) { |
| 40 | |
| 41 | String workspaceLocation = PropertyHandler.getVariable("workspace_location"); |
| 42 | MSGlycanAnnotationProperty t_property = new MSGlycanAnnotationProperty(); |
| 43 | Entry projectEntry = DataModelSearch.findParentByType(msEntry, ProjectProperty.TYPE); |
| 44 | String projectName = projectEntry.getDisplayName(); |
| 45 | |
| 46 | String msAnnotationFolder = workspaceLocation + projectName + File.separator + t_property.getArchiveFolder(); |
| 47 | File msAnnotationFolderFile = new File(msAnnotationFolder); |
| 48 | msAnnotationFolderFile.mkdirs(); |
| 49 | |
| 50 | return msAnnotationFolderFile; |
| 51 | } |
| 52 | }}} |
| 53 | |
| 54 | 3. Creating the data files and link them to the metadata created in the previous step: |
| 55 | |
| 56 | {{{ |
| 57 | |
| 58 | }}} |
| 59 | |
| 60 | {{{ |
| 61 | |
| 62 | final MassSpecProperty prop = (MassSpecProperty) msEntry.getProperty(); |
| 63 | Entry msAnnotationEntry = new Entry(); |
| 64 | String sWorkspaceFolder = fWorkspaceFolderFile.getAbsolutePath(); |
| 65 | |
| 66 | File msAnnFile = getAnnotationFolder(msEntry); |
| 67 | String msAnnotationFolder = msAnnFile.getAbsolutePath(); |
| 68 | MSGlycanAnnotationProperty msAnnotProperty = (MSGlycanAnnotationProperty) getMSAnnotationProperty(shell, wizard, msAnnotationFolder); |
| 69 | |
| 70 | String msEntryDisplayName = msEntry.getDisplayName(); |
| 71 | String msAnnotName = wizard.getInitial().getListEntries().get(msEntryDisplayName); |
| 72 | msAnnotationEntry.setDisplayName(msAnnotName); |
| 73 | msAnnotationEntry.setProperty(msAnnotProperty); |
| 74 | |
| 75 | Data data = getNewDataObject(wizard); |
| 76 | DataHeader dHeader = data.getDataHeader(); |
| 77 | |
| 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(); |
| 82 | |
| 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); |
| 89 | |
| 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()); |
| 95 | |
| 96 | Entry[] entries = new Entry[2]; |
| 97 | entries[0] = msEntry; // entry for the source MS |
| 98 | entries[1] = msAnnotationEntry; // the new entry for the MS Annotation |
| 99 | |
| 100 | // return list is a List<Entry[]>. |
| 101 | returnList.add(entries); |
| 102 | } else if (iStatus == GRITSProcessStatus.CANCEL) { |
| 103 | deleteResultFiles(dHeader.getMethod().getMsType()); |
| 104 | } |
| 105 | |
| 106 | }}} |
| 107 | |
| 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 | }}} |