wiki:CreatingNewAnnotationEntry

Version 1 (modified by sena, 4 years ago) (diff)

--

Creating an annotation entry

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.

  • Creation of a MS Annotation Entry and its corresponding Property

Several steps are included in this process:

  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.
Entry msAnnotationEntry = new Entry();

String msEntryDisplayName = msEntry.getDisplayName();
String msAnnotName = wizard.getInitial().getListEntries().get(msEntryDisplayName);
msAnnotationEntry.setDisplayName(msAnnotName);
  1. 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.
        // getting the annotation folder
        File msAnnFile = getAnnotationFolder(msEntry);	
        String msAnnotationFolder = msAnnFile.getAbsolutePath();

        MSGlycanAnnotationProperty t_property = new MSGlycanAnnotationProperty();
        MSGlycanAnnotationMetaData metaData = new MSGlycanAnnotationMetaData();		
	t_property.setMSAnnotationMetaData(metaData);
	metaData.setAnnotationId(this.createRandomId(msAnnotationFolder));
	metaData.setDescription(somedescripton);
	metaData.setVersion(MSGlycanAnnotationMetaData.CURRENT_VERSION);
	metaData.setName(t_property.getMetaDataFileName());

Getting the annotation folder for the given ms entry:

        protected File getAnnotationFolder( Entry msEntry ) {

		String workspaceLocation = PropertyHandler.getVariable("workspace_location");
		MSGlycanAnnotationProperty t_property = new MSGlycanAnnotationProperty();
		Entry projectEntry = DataModelSearch.findParentByType(msEntry, ProjectProperty.TYPE);
		String projectName = projectEntry.getDisplayName();

		String msAnnotationFolder = workspaceLocation + projectName + File.separator + t_property.getArchiveFolder();	
		File msAnnotationFolderFile = new File(msAnnotationFolder);
		msAnnotationFolderFile.mkdirs();

		return msAnnotationFolderFile;
	}
  1. Creating the data files and link them to the metadata created in the previous step:
 
final MassSpecProperty prop = (MassSpecProperty) msEntry.getProperty();
Entry msAnnotationEntry = new Entry();		
String sWorkspaceFolder = fWorkspaceFolderFile.getAbsolutePath();

File msAnnFile = getAnnotationFolder(msEntry);	
String msAnnotationFolder = msAnnFile.getAbsolutePath();
MSGlycanAnnotationProperty msAnnotProperty = (MSGlycanAnnotationProperty) getMSAnnotationProperty(shell, wizard, msAnnotationFolder);

String msEntryDisplayName = msEntry.getDisplayName();
String msAnnotName = wizard.getInitial().getListEntries().get(msEntryDisplayName);
msAnnotationEntry.setDisplayName(msAnnotName);
msAnnotationEntry.setProperty(msAnnotProperty);

Data data = getNewDataObject(wizard);
DataHeader dHeader = data.getDataHeader();

MSPropertyDataFile dataFile = wizard.getInitial().getFileMap().get(msEntry.getDisplayName());
String workspaceLocation = PropertyHandler.getVariable("workspace_location");
String projectName = DataModelSearch.findParentByType(msEntry, ProjectProperty.TYPE).getDisplayName();
String pathToFile = workspaceLocation + projectName + File.separator + MassSpecProperty.getFoldername();

// call performAnnotation - does all the work. 
iStatus = performAnnotation( gpd, data, sWorkspaceFolder, msAnnotationFolder, msAnnotProperty, 
		dataFile.getMSFileWithReader(pathToFile, prop.getMassSpecMetaData().getMsExperimentType()));
if( iStatus == GRITSProcessStatus.OK ) {
	// if everything worked, save to workspace all of the appropriate files for Annotation
	msAnnotProperty.getMSAnnotationMetaData().addAnnotationFile(dataFile);

	PropertyDataFile msMetaData = MSAnnotationProperty.getNewSettingsFile(msAnnotProperty.getMetaDataFileName(), msAnnotProperty.getMSAnnotationMetaData());
	msAnnotProperty.getDataFiles().add(msMetaData);
	addResultFileToMetaData(dHeader.getMethod().getMsType(), msAnnotProperty);
	MSAnnotationProperty.marshallSettingsFile(msAnnotProperty.getAnnotationFolder(msEntry) + File.separator +
			msAnnotProperty.getMetaDataFileName(), msAnnotProperty.getMSAnnotationMetaData());

	Entry[] entries = new Entry[2];
	entries[0] = msEntry; // entry for the source MS
	entries[1] = msAnnotationEntry; // the new entry for the MS Annotation

	// return list is a List<Entry[]>. 
	returnList.add(entries);
} else if (iStatus == GRITSProcessStatus.CANCEL) {
	deleteResultFiles(dHeader.getMethod().getMsType());
}


        List<Entry[]> resultEntries = handler.process(shell2);			
	if( resultEntries != null ) {
		for( int i = 0; i < resultEntries.size(); i++ ) {
			Entry[] curEntries = resultEntries.get(i);
			gritsDataModelService.addEntry(curEntries[0], curEntries[1]);
		}
	}

	if( resultEntries != null && ! resultEntries.isEmpty() && resultEntries.get(resultEntries.size()-1)[1] != null ) {
		// save the project first
		try
		{
			// parent of MS Entry is Sample, parent of Sample is the Project
			ProjectFileHandler.saveProject(resultEntries.get(resultEntries.size()-1)[0].getParent().getParent());
		} catch (IOException e)
		{
			logger.error("Something went wrong while saving project entry \n" + e.getMessage(),e);
			logger.fatal("Closing project entry \""
					+ resultEntries.get(resultEntries.size()-1)[0].getParent().getParent().getDisplayName() + "\"");
			gritsDataModelService.closeProject(resultEntries.get(resultEntries.size()-1)[0].getParent().getParent());
			throw e;
		}
		for( int i = 0; i < resultEntries.size(); i++ ) {
			Entry[] curEntries = resultEntries.get(i);
			lockFiles (wizard, curEntries[0], curEntries[1]);
		}
		final Entry lastMSEntry = (Entry) resultEntries.get(resultEntries.size()-1)[1] ;
		eventBroker.send(IGritsDataModelService.EVENT_SELECT_ENTRY, lastMSEntry);
		
		try {
		    // need to set the partService to refresh gritsUIServices' stale partService, see ticket #799
			gritsUIService.setPartService(partService);
			gritsUIService.openEntryInPart(lastMSEntry);
		} catch (Exception e) {
			logger.debug("Could not open the part", e);
		}
	}