Author: jgao
Date: 2010-09-09 12:30:14 -0700 (Thu, 09 Sep 2010)
New Revision: 21779
Modified:
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/AttributeBasedIDMappingImpl.java
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/service/CyThesaurusNamespace.java
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/AttributeBasedIDMappingTask.java
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/CyThesaurusDialog.form
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/CyThesaurusDialog.java
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/WebserviceIDMappingClientConfigDialog.form
Log:
CyThesaurus: add option of firstonly for attributeBasedMapping command
Modified:
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/AttributeBasedIDMappingImpl.java
===================================================================
---
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/AttributeBasedIDMappingImpl.java
2010-09-09 19:09:48 UTC (rev 21778)
+++
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/AttributeBasedIDMappingImpl.java
2010-09-09 19:30:14 UTC (rev 21779)
@@ -65,6 +65,7 @@
protected TaskMonitor taskMonitor;
protected boolean interrupted;
protected String report;
+ protected Map<String,Byte> attrNameType = null;
public void setTaskMonitor(TaskMonitor taskMonitor) {
this.taskMonitor = taskMonitor;
@@ -81,6 +82,35 @@
}
/**
+ * Define target attributes.
+ * Call this method first before mapping if necessary.
+ * @param attrNameType
+ */
+ public void suggestTgtAttrType(Map<String,Byte> attrNameType) {
+ this.attrNameType = attrNameType;
+ CyAttributes nodeAttributes = Cytoscape.getNodeAttributes();
+ MultiHashMapDefinition mmapDef =
nodeAttributes.getMultiHashMapDefinition();
+
+ for (Map.Entry<String,Byte> entry : attrNameType.entrySet()) {
+ String attrname = entry.getKey();
+ byte attrtype = entry.getValue();
+
+ byte[] keyTypes;
+ if (attrtype==CyAttributes.TYPE_STRING) {
+ keyTypes = null;
+ } else if (attrtype==CyAttributes.TYPE_SIMPLE_LIST ) {
+ keyTypes = new byte[] {
MultiHashMapDefinition.TYPE_INTEGER };
+ } else {
+ keyTypes = null;
+ }
+
+ mmapDef.defineAttribute(attrname,
+ MultiHashMapDefinition.TYPE_STRING,
+ keyTypes);
+ }
+ }
+
+ /**
* {...@inheritdoc}
*/
public void map(Set<CyNetwork> networks,
Map<String,Set<DataSourceWrapper>> mapSrcAttrIDTypes,
@@ -229,7 +259,13 @@
}
} else {
// define the new attribute as List
- byte[] keyTypes = new byte[] {
MultiHashMapDefinition.TYPE_INTEGER };
+ // only if it is explicitly defined as String, o.w. default is
list of string
+ byte[] keyTypes;
+ if (attrNameType!=null &&
attrNameType.get(attr)==CyAttributes.TYPE_STRING) {
+ keyTypes = null;
+ }
+
+ keyTypes = new byte[] { MultiHashMapDefinition.TYPE_INTEGER };
mmapDef.defineAttribute(attr,
MultiHashMapDefinition.TYPE_STRING,
keyTypes);
Modified:
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/service/CyThesaurusNamespace.java
===================================================================
---
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/service/CyThesaurusNamespace.java
2010-09-09 19:09:48 UTC (rev 21778)
+++
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/service/CyThesaurusNamespace.java
2010-09-09 19:30:14 UTC (rev 21779)
@@ -37,12 +37,12 @@
import csplugins.id.mapping.IDMapperClientManager;
import csplugins.id.mapping.ui.IDMappingSourceConfigDialog;
import csplugins.id.mapping.ui.CyThesaurusDialog;
-import csplugins.id.mapping.AttributeBasedIDMapping;
import csplugins.id.mapping.AttributeBasedIDMappingImpl;
import csplugins.id.mapping.util.DataSourceWrapper;
import cytoscape.CyNetwork;
import cytoscape.Cytoscape;
+import cytoscape.data.CyAttributes;
import cytoscape.command.AbstractCommandHandler;
import cytoscape.command.CyCommandException;
@@ -101,6 +101,7 @@
private static final String TARGET_ATTR = "targetattr";
private static final String SOURCE_ID = "sourceid";
private static final String REPORT = "report";
+ private static final String FIRST_ONLY = "firstonly";
protected CyThesaurusNamespace(CyCommandNamespace ns) {
super(ns);
@@ -150,12 +151,14 @@
addArgument(ATTRIBUTE_BASED_MAPPING, TARGET_ATTR); // optional
addArgument(ATTRIBUTE_BASED_MAPPING, SOURCE_TYPE); // optional
addArgument(ATTRIBUTE_BASED_MAPPING, TARGET_TYPE); // required
+ addArgument(ATTRIBUTE_BASED_MAPPING, FIRST_ONLY); // optional
addDescription(ATTRIBUTE_BASED_MAPPING, "Mapping IDs of the
sourceidtype(s) in "
+ "sourceattribute to IDs of the targetidtype and save them to
targetattribute.");
addArgument(GENERAL_MAPPING, SOURCE_ID);
addArgument(GENERAL_MAPPING, SOURCE_TYPE);
addArgument(GENERAL_MAPPING, TARGET_TYPE);
+ addArgument(GENERAL_MAPPING, FIRST_ONLY);
addDescription(GENERAL_MAPPING, "Mapping sourceid(s) of sourcetype to
targettype.");
addArgument(CHECK_ID_EXIST, SOURCE_ID);
@@ -163,7 +166,7 @@
addDescription(CHECK_ID_EXIST, "Check if ID exists.");
addArgument(GUESS_TYPE, SOURCE_ID);
- addDescription(GUESS_TYPE, "Guess ID types from a set of IDs.");
+ addDescription(GUESS_TYPE, "Guess ID types from a set of IDs (only ID
types in the selected resources will be included).");
}
@@ -612,8 +615,18 @@
tgtAttr = tgtType;
}
}
+
+ obj = args.get(FIRST_ONLY);
+ boolean firstOnly = false;
+ if (obj instanceof Boolean) {
+ firstOnly = (Boolean)obj;
+ } else if (obj instanceof String) {
+ firstOnly = ((String)obj).equalsIgnoreCase("yes")
+ || ((String)obj).equalsIgnoreCase("true");
+ }
+
// mapping ids
- AttributeBasedIDMapping service
+ AttributeBasedIDMappingImpl service
= new AttributeBasedIDMappingImpl();
Map<String,Set<DataSourceWrapper>> mapAttrTypes = new HashMap();
for (String attr : srcAttrs) {
@@ -629,6 +642,10 @@
DataSourceWrapper.DsAttr.DATASOURCE);
Map<String,DataSourceWrapper> mapTgtTypeAttr =
Collections.singletonMap(tgtAttr, dsw);
+ Map<String,Byte> attrNameType = Collections.singletonMap(tgtAttr,
+
firstOnly?CyAttributes.TYPE_STRING:CyAttributes.TYPE_SIMPLE_LIST);
+ service.suggestTgtAttrType(attrNameType);
+
try {
service.map(networks, mapAttrTypes, mapTgtTypeAttr);
} catch (Exception e) {
@@ -701,20 +718,28 @@
result.addError("No mapping was performed.");
} else {
Map<String, Set<String>> mapSrcIdTargetIDs = new
HashMap(mapping.size());
+ StringBuilder mappedId = new StringBuilder();
for (Xref srcXref : mapping.keySet()) {
Set<Xref> tgtXrefs = mapping.get(srcXref);
if (tgtXrefs!=null) {
+ String srcId = srcXref.getId();
Set<String> tgtIds = new HashSet();
for (Xref tgtXref : tgtXrefs) {
tgtIds.add(tgtXref.getId());
}
- mapSrcIdTargetIDs.put(srcXref.getId(), tgtIds);
+ mapSrcIdTargetIDs.put(srcId, tgtIds);
+
+ mappedId.append(srcId);
+ mappedId.append("<=>");
+ mappedId.append(tgtIds.toString());
+ mappedId.append("\n");
}
}
result.addResult(mapSrcIdTargetIDs);
result.addMessage(""+mapSrcIdTargetIDs.size()+"out of
"+srcIDs.size()
- +" source IDs was mapping from type: "+srcType+" to
type:"+tgtType);
+ +" source IDs was mapping from type: "+srcType+" to
type:"+tgtType
+ +"\n"+mappedId.toString());
}
return result;
@@ -737,7 +762,13 @@
DataSource ds = DataSource.getByFullName(type);
IDMapperStack stack = IDMapperClientManager.selectedIDMapperStack();
try {
- result.addResult(stack.xrefExists(new Xref(id, ds)));
+ if (stack.xrefExists(new Xref(id, ds))) {
+ result.addResult(Boolean.TRUE);
+ result.addMessage(type+":"+id+" exists.");
+ } else {
+ result.addResult(Boolean.FALSE);
+ result.addMessage(type+":"+id+" does not exist.");
+ }
} catch (Exception e) {
throw new CyCommandException(e);
}
@@ -760,9 +791,19 @@
throw new CyCommandException("Parameter "+SOURCE_ID+" must
contains one or more source IDs.");
}
+ Set<DataSource> selectedDss = new HashSet<DataSource>();
+ try {
+ IDMapperCapabilities cap =
IDMapperClientManager.selectedIDMapperStack().getCapabilities();
+ selectedDss.addAll(cap.getSupportedSrcDataSources());
+ selectedDss.addAll(cap.getSupportedTgtDataSources());
+ } catch (Exception e) {
+ throw new CyCommandException(e);
+ }
+
Set<String> types = new HashSet<String>();
for (String id : srcIDs) {
Set<DataSource> dss = DataSourcePatterns.getDataSourceMatches(id);
+ dss.retainAll(selectedDss);
for (DataSource ds : dss)
types.add(ds.getFullName());
}
Modified:
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/AttributeBasedIDMappingTask.java
===================================================================
---
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/AttributeBasedIDMappingTask.java
2010-09-09 19:09:48 UTC (rev 21778)
+++
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/AttributeBasedIDMappingTask.java
2010-09-09 19:30:14 UTC (rev 21779)
@@ -53,6 +53,7 @@
private final Map<String,Set<DataSourceWrapper>> mapSrcAttrIDTypes;
private final Map<String, DataSourceWrapper> mapTgtAttrNameIDType;
private final AttributeBasedIDMappingImpl service;
+ private final Map<String,Byte> mapTgtAttrNameAttrType;
private TaskMonitor taskMonitor;
private boolean success;
@@ -65,10 +66,12 @@
*/
public AttributeBasedIDMappingTask(final Set<CyNetwork> networks,
final
Map<String,Set<DataSourceWrapper>> mapSrcAttrIDTypes,
- final Map<String, DataSourceWrapper>
mapTgtAttrNameIDType) {
+ final Map<String, DataSourceWrapper>
mapTgtAttrNameIDType,
+ Map<String,Byte>
mapTgtAttrNameAttrType) {
this.networks = networks;
this.mapSrcAttrIDTypes = mapSrcAttrIDTypes;
this.mapTgtAttrNameIDType = mapTgtAttrNameIDType;
+ this.mapTgtAttrNameAttrType = mapTgtAttrNameAttrType;
service = new AttributeBasedIDMappingImpl();
success = false;
}
@@ -80,7 +83,7 @@
public void run() {
try {
service.setTaskMonitor(taskMonitor);
-
+ service.suggestTgtAttrType(mapTgtAttrNameAttrType);
service.map(networks, mapSrcAttrIDTypes,
mapTgtAttrNameIDType);
Modified:
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/CyThesaurusDialog.form
===================================================================
---
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/CyThesaurusDialog.form
2010-09-09 19:09:48 UTC (rev 21778)
+++
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/CyThesaurusDialog.form
2010-09-09 19:30:14 UTC (rev 21779)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8" ?>
+<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7"
type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
Modified:
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/CyThesaurusDialog.java
===================================================================
---
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/CyThesaurusDialog.java
2010-09-09 19:09:48 UTC (rev 21778)
+++
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/CyThesaurusDialog.java
2010-09-09 19:30:14 UTC (rev 21779)
@@ -464,12 +464,12 @@
Map<String, DataSourceWrapper> mapTgtAttrNameIDType =
targetAttributeSelectionTable.getMapAttrNameIDType();
Map<String,Byte> mapTgtAttrNameAttrType =
targetAttributeSelectionTable.getMapAttrNameAttrType();
- // define target attributes
- defineTgtAttributes(mapTgtAttrNameAttrType);
+// // define target attributes
+// defineTgtAttributes(mapTgtAttrNameAttrType);
// execute task
AttributeBasedIDMappingTask task
- = new AttributeBasedIDMappingTask(networks, mapSrcAttrIDTypes,
mapTgtAttrNameIDType);
+ = new AttributeBasedIDMappingTask(networks, mapSrcAttrIDTypes,
mapTgtAttrNameIDType, mapTgtAttrNameAttrType);
// Configure JTask Dialog Pop-Up Box
final JTaskConfig jTaskConfig = new JTaskConfig();
jTaskConfig.setOwner(Cytoscape.getDesktop());
@@ -800,30 +800,30 @@
//
// return ret;
// }
+//
+// private void defineTgtAttributes(Map<String,Byte> attrNameType) {
+// CyAttributes nodeAttributes = Cytoscape.getNodeAttributes();
+// MultiHashMapDefinition mmapDef =
nodeAttributes.getMultiHashMapDefinition();
+//
+// for (Map.Entry<String,Byte> entry : attrNameType.entrySet()) {
+// String attrname = entry.getKey();
+// byte attrtype = entry.getValue();
+//
+// byte[] keyTypes;
+// if (attrtype==CyAttributes.TYPE_STRING) {
+// keyTypes = null;
+// } else if (attrtype==CyAttributes.TYPE_SIMPLE_LIST ) {
+// keyTypes = new byte[] {
MultiHashMapDefinition.TYPE_INTEGER };
+// } else {
+// keyTypes = null;
+// }
+//
+// mmapDef.defineAttribute(attrname,
+// MultiHashMapDefinition.TYPE_STRING,
+// keyTypes);
+// }
+// }
- private void defineTgtAttributes(Map<String,Byte> attrNameType) {
- CyAttributes nodeAttributes = Cytoscape.getNodeAttributes();
- MultiHashMapDefinition mmapDef =
nodeAttributes.getMultiHashMapDefinition();
-
- for (Map.Entry<String,Byte> entry : attrNameType.entrySet()) {
- String attrname = entry.getKey();
- byte attrtype = entry.getValue();
-
- byte[] keyTypes;
- if (attrtype==CyAttributes.TYPE_STRING) {
- keyTypes = null;
- } else if (attrtype==CyAttributes.TYPE_SIMPLE_LIST ) {
- keyTypes = new byte[] {
MultiHashMapDefinition.TYPE_INTEGER };
- } else {
- keyTypes = null;
- }
-
- mmapDef.defineAttribute(attrname,
- MultiHashMapDefinition.TYPE_STRING,
- keyTypes);
- }
- }
-
public Map<String,Set<DataSourceWrapper>> getMapSrcAttrIDTypes() {
Map<String,Set<DataSourceWrapper>> mapSrcAttrIDTypes =
sourceAttributeSelectionTable.getSourceAttrType();
return mapSrcAttrIDTypes;
Modified:
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/WebserviceIDMappingClientConfigDialog.form
===================================================================
---
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/WebserviceIDMappingClientConfigDialog.form
2010-09-09 19:09:48 UTC (rev 21778)
+++
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/ui/WebserviceIDMappingClientConfigDialog.form
2010-09-09 19:30:14 UTC (rev 21779)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8" ?>
+<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7"
type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.