Skip to content

Commit

Permalink
Merge pull request #10 from KlasJoenssson/PropertiesImport
Browse files Browse the repository at this point in the history
Properties import
  • Loading branch information
goglepox committed Jul 26, 2012
2 parents c64015d + b826f21 commit 93fa663
Show file tree
Hide file tree
Showing 10 changed files with 1,673 additions and 2 deletions.
@@ -0,0 +1,70 @@
/* *****************************************************************************
* Copyright (c) 2007-2012 Bioclipse Project
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
******************************************************************************/
package net.bioclipse.cdk.ui.sdfeditor.business;

import java.io.FileNotFoundException;
import java.util.ArrayList;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
* This is the test-class for the PropertiesImportFileHandler-class.
*
* @author Klas Jšnsson (klas.joensson@gmail.com)
*
*/
public class TestPropertiesImportFileHandler {

private PropertiesImportFileHandler fileHandler;

@Before
public void setUp() {
fileHandler = new PropertiesImportFileHandler();
// testPage = new SDFPropertiesImportWizardPage( "Test page" );
}

@Test
public void testSetDataFile() throws FileNotFoundException {

Path path = new Path("./datafile2.txt");
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
fileHandler.setDataFile( file );

Assert.assertTrue( fileHandler.dataFileExists() );
}


@Test
public void testReadDataFile() throws FileNotFoundException {

Path path = new Path("./datafile2.txt");
ArrayList<ArrayList<String>> data;
ArrayList<String> id;

IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
fileHandler.setDataFile( file );

id = fileHandler.getPropertiesIDFromDataFile();
for (int i = 0; i < id.size(); i++)
System.out.print( id.get( i ) + "\t" );
System.out.println();

data = fileHandler.getTopValuesFromDataFile( 5 );
for (int i = 0; i < data.size(); i++){
for (int j = 0; j < data.get( i ).size(); j++)
System.out.print( data.get( i ).get( j ) + "\t" );
System.out.println();
}
}
}
45 changes: 45 additions & 0 deletions plugins/net.bioclipse.cdk.ui.sdfeditor/html/addPropHelp.html
@@ -0,0 +1,45 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Bioclipse Help</title>
<link rel="stylesheet" href="../../PRODUCT_PLUGIN/narrow_book.css" type="text/css">
</head>

<body>
<h1>Importing properties to a SD-file</h1>
<br>
<br>
<h2>Introduction</h2>
Sometimes you have a file with some properties that you want to add to molecules in a SD-file. In Bioclips this can be done by selecting both the SD-file and the file with the properties in Bioclipse navigator field, then right-clicking on either of them and choose &ldquo;Add properties&rdquo; in the popup-menu that appears. If you only have one of the files in Bioclipse workspace, i.e. is visibly in the navigator field; don't worry, just right click on it and choose &ldquo;Add properties&rdquo; from the popup-menu. You can add the other file later when the wizard has opened. Observe that even though it is possible to select more than two files, this wizard only add <i>one</i> file with properties to <i>one</i> SD-file.

<h2>The input data</h2>
Before describing how this wizard works, it is worth to mention a few words about the formart of the file that contains the data that is to be added to the SD-file. It is supposed to be a simpel text file (that kind of file that you work with in e.g. Notepad in Windows). In this file all the data for a specific molecule should be on the same row, and the different properties for that molecule have to be tab-separated. If the data file contains the names of the properties then they are suposed to be on the first (top) row of the file.

<h2>Choosing the files to merge</h2>
<img src="images/pic1.jpg" width="350" align=right>
When open the wizard as described above, the two files will appear in the two top fields of the wizard (see the figure to the right). If only one file was selected then it appears in the corresponding field, and the other can be chosen by clicking on the button with the text &ldquo;Browse...&rdquo; just to the right of the field. Doing so will open a open-file-dialog where you can search for the file you want. This button can of cause also be used to choose a different file.<br>
When a data file has been selected, then the wizard will read it. The result can be seen in the square below the file-settings. In the row with the label &ldquo;Name&rdquo; infront of it are the names if the different properties, or to be exact; the top row of the data file. Let's simply call it &ldquo;the name-row&rdquo; from now on. Below that are the values from the next five rows in the data file, in the rows with the label &ldquo;Values&rdquo; infront. If all seams ok, it is just to press the ok-button at the bottom of the wizard and the properties will be added to the molecules in SD-file.
<br>The result is saved in a new file in the same director as the file you selected when you opened the wizard, and it will have almost the same name as the old SD-file. The difference is that the result file will end with &ldquo;_new&rdquo;. I.e. if your SD-file is called &ldquo;My_molecules.sdf&rdquo;, then the resulting file will have the name &ldquo;My_molecules_new.sdf&rdquo;.
<br> Note that if any property has the same name as a property in the SD-file the value of that property will be replaced with the value from the data file. Also note that the names are case sensitive, e.g. the name &ldquo;ID&rdquo; is not the same as &ldquo;id&rdquo;.
<br>
<br>
<br>
<h2>Change the name of a property</h2>
Some times you might want to change the name of one or several properties before adding them, the easiest way to do this is to just click in the field with the name of that property and write the new name on it. Note that you can not link properties that you have namned this way (what it means to link properties is described in the section &ldquo;The data connection box&rdquo; below).

<h2>Exclude a property</h2>
If the data file by some reason contains a property that you do not want to add to the molecules in the SD-file, then you can exclude it. This is done by clicking in the check-box beneath the column of that property, it's in the row with the label &ldquo;Exclude&rdquo; infront, just at the botom of the square showing the properties.

<h2>No properties name in the data file</h2>
<img src="images/pic2.jpg" width="350" align=right>
If the data file lacks the property names, i.e. the first row in the file contains property values as well. Then the name-row (the one with the label &ldquo;Names&rdquo; infront) will contain the values from the first row of the data file. But this is probably not what you wanted, to solve this just select the option &ldquo;Data file does not includes properties name&rdquo; in the box called &ldquo;Properties name&rdquo; just below the square with the properties value mention above. Then the values in the name-row will jump down to the top row of the rows with the name &ldquo;Values&rdquo; in front, and in the name-row there will appear a drop-down-menu for each property. See the picture to the right. Now you can either just write the name of the property in it or, if you have selected a SD-file as well, you can choose one of the property names used by the SD-file. Note that if doing so the value of that property will be replaced by the value from the data file. Also note that when you add a property name by writing the name in the box you can not link it, just as when you rename a property.

<h2>The data connection box</h2>
There is one box with radio-buttons that has not been mention yet. It's the one at the bottom called &ldquo;Data connection&rdquo;, with this you can control how the data is added to the SD-file. The first, and default, option states &ldquo;The order of the data file is as in the SD-file&rdquo;. What this mean is that the first row of properties in the data file will be added to the first molecule in the SD-file, the second row to the second molecule, etc.<br>
With the other option in that box you can chose to link one of the properties in the data file to another in the SD-file. This means that if the value of the linked properties are the same, then the other properties of that row in the data file will be added to that molecule. Which properties that are to be linked is chosen in respective combo-box on the same line as the radio button for this option.<br>
This is usefully if you for example have a SD-file with many molecules, but there are only some of them that you want to add new properties to and/or change the values of one or several existing properties. Let's e.g. say that all molecules in the SD-file has a property called &ldquo;IDNUMBER&rdquo;, that represent a id-number for the molecules. Then if you have the id-numbers of the molecule you want to change as a property in your data file (along with the other properties), let's say that you call that property &ldquo;mol_id&rdquo;. Now it's easy manipulate only the molecules that you want to manipulate: Select the last alternative in the &ldquo;Data connection box&rdquo; and choose &ldquo;mol_id&rdquo; in the left combo-box and &ldquo;IDNUMBER&rdquo; in the right. <i>Note that when using this option it will take much longer time to add the properties to the molecules, because the data file will have to be read several times.</i>

</body>
</html>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion plugins/net.bioclipse.cdk.ui.sdfeditor/plugin.xml
Expand Up @@ -128,6 +128,11 @@
id="net.bioclipse.cdk.molTable.column.remove"
name="Remove Column">
</command>
<command
defaultHandler="net.bioclipse.cdk.ui.sdfeditor.business.LaunchWizardPage"
id="net.bioclipse.cdk.ui.sdfeditor.command.ImportProperties"
name="Import Properties">
</command>
</extension>

<extension
Expand Down Expand Up @@ -192,6 +197,11 @@
</iterate>
</visibleWhen>
</command>
<command
commandId="net.bioclipse.cdk.ui.sdfeditor.command.ImportProperties"
label="Add properties"
style="push">
</command>
</menuContribution>
<menuContribution
locationURI="popup:net.bioclipse.cdk.ui.sdfeditor.column.menu?after=additions">
Expand Down Expand Up @@ -267,7 +277,7 @@
</or>
</iterate>
</visibleWhen>
</command> </menuContribution>
</command> </menuContribution>
</extension>
<extension
point="net.bioclipse.scripting.contribution">
Expand Down
@@ -0,0 +1,55 @@
/* *****************************************************************************
* Copyright (c) 2007-2012 Bioclipse Project
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
******************************************************************************/
package net.bioclipse.cdk.ui.sdfeditor.business;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;

/**
* This class lunches a wizard that let the user import properties from a
* txt-file to a SDF-file. The result is saved in a new sd-file.
*
* @author Klas Jšnsson (klas.joensson@gmail.com)
*
*/
public class LaunchWizardPage extends AbstractHandler implements IHandler{

private ISelection selection;
private IStructuredSelection ssel;

public LaunchWizardPage() { }

@Override
public Object execute( ExecutionEvent event ) throws ExecutionException {

selection = HandlerUtil.getActiveMenuSelection( event );
if ( selection instanceof IStructuredSelection ) {
ssel = (IStructuredSelection) selection;
}

SDFPropertiesImportWizard wizard = new SDFPropertiesImportWizard(ssel);
WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench()
.getActiveWorkbenchWindow()
.getShell(), wizard);
dialog.open();
return null;
}

public void selectionChanged(ExecutionEvent event) {
this.selection = HandlerUtil.getCurrentSelection( event );
}

}

0 comments on commit 93fa663

Please sign in to comment.