Changes between Version 1 and Version 2 of CreatingNewAnnotationEntry


Ignore:
Timestamp:
07/16/2018 10:51:05 PM (4 years ago)
Author:
sena
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CreatingNewAnnotationEntry

    v1 v2  
    33At 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.
    44
    5 * Creation of a MS Annotation Entry and its corresponding Property
    6 
    7    Several steps are included in this process:
     5Several steps are included in this process (see org.grits.toolbox.importer.ms.annotation.glycan.simiansearch.handler.GelatoWorker):
    86   
    97   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.
    108
    119{{{
    12 Entry msAnnotationEntry = new Entry();
     10        Entry msAnnotationEntry = new Entry();
    1311
    14 String msEntryDisplayName = msEntry.getDisplayName();
    15 String msAnnotName = wizard.getInitial().getListEntries().get(msEntryDisplayName);
    16 msAnnotationEntry.setDisplayName(msAnnotName);
     12        String msEntryDisplayName = msEntry.getDisplayName();
     13        String msAnnotName = wizard.getInitial().getListEntries().get(msEntryDisplayName);
     14        msAnnotationEntry.setDisplayName(msAnnotName);
    1715}}}
    1816
     
    3129        metaData.setVersion(MSGlycanAnnotationMetaData.CURRENT_VERSION);
    3230        metaData.setName(t_property.getMetaDataFileName());
     31        msAnnotationEntry.setProperty (t_property);       
    3332
    3433}}}
     
    5251}}}
    5352
    54    3. Creating the data files and link them to the metadata created in the previous step:
     53   3. Creating the data files and linking them to the metadata created in the previous step:
    5554
    5655{{{
     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
     63During 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());
    5775
    5876}}}
    5977
    6078{{{
    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        }
    6586
    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);
    69104
    70 String msEntryDisplayName = msEntry.getDisplayName();
    71 String msAnnotName = wizard.getInitial().getListEntries().get(msEntryDisplayName);
    72 msAnnotationEntry.setDisplayName(msAnnotName);
    73 msAnnotationEntry.setProperty(msAnnotProperty);
     105        }
     106}}}
    74107
    75 Data data = getNewDataObject(wizard);
    76 DataHeader dHeader = data.getDataHeader();
     108     5. Saving the entries. (see org.grits.toolbox.importer.ms.annotation.glycan.simiansearch.handler.OpenGelatoWizard)
    77109
    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}}}
    82115
    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)
    89117
    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        }
    95136
    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
     137}}}
    99138
    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
     143try {
     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);
    104149}
    105150
    106151}}}
    107152
    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 }}}