use of org.cytoscape.filter.internal.filters.model.CompositeFilter in project cytoscape-impl by cytoscape.
the class FilterReader method getTopologyFilterFromStr.
private void getTopologyFilterFromStr(TopologyFilter pFilter, List<String> pFilterStrVect, Collection<CompositeFilter> filters) {
String line = null;
for (int i = 0; i < pFilterStrVect.size(); i++) {
line = pFilterStrVect.get(i);
if (line.startsWith("name=")) {
String name = line.substring(5).trim();
pFilter.setName(name);
}
if (line.startsWith("Negation=true"))
pFilter.setNegation(true);
if (line.startsWith("Negation=false"))
pFilter.setNegation(false);
if (line.startsWith("minNeighbors=")) {
String minNeighbors = line.substring(13);
int minN = new Integer(minNeighbors).intValue();
pFilter.setMinNeighbors(minN);
}
if (line.startsWith("withinDistance=")) {
String withinDistance = line.substring(15);
int distance = new Integer(withinDistance).intValue();
pFilter.setDistance(distance);
}
if (line.startsWith("passFilter=")) {
String name = line.substring(11).trim();
// get the reference CompositeFilter
CompositeFilter cmpFilter = null;
for (CompositeFilter cf : filters) {
if (cf.getName().equalsIgnoreCase(name)) {
cmpFilter = cf;
break;
}
}
if (cmpFilter != null) {
pFilter.setPassFilter(cmpFilter);
}
}
}
}
use of org.cytoscape.filter.internal.filters.model.CompositeFilter in project cytoscape-impl by cytoscape.
the class FilterReader method getFilterFromStrList.
private CompositeFilter getFilterFromStrList(List<String> strList, Collection<CompositeFilter> filters) {
boolean isTopologyFilter = false;
boolean isInteractionFilter = false;
if (strList.get(0).startsWith("<TopologyFilter>")) {
isTopologyFilter = true;
}
if (strList.get(0).startsWith("<InteractionFilter>")) {
isInteractionFilter = true;
}
List<String> advSettingStrVect = new ArrayList<String>();
List<String> filterStrVect = new ArrayList<String>();
// Seperate AdvancedSetting from the rest
int startIndex = -1, endIndex = -1;
String line = null;
for (int i = 0; i < strList.size(); i++) {
line = strList.get(i);
if (line.startsWith("<AdvancedSetting>")) {
startIndex = i;
}
if (line.startsWith("</AdvancedSetting>")) {
endIndex = i;
break;
}
}
advSettingStrVect.addAll(strList.subList(startIndex + 1, endIndex));
filterStrVect.addAll(strList.subList(1, startIndex));
filterStrVect.addAll(strList.subList(endIndex + 1, strList.size()));
CompositeFilter retFilter = new CompositeFilter(ServicesUtil.cyApplicationManagerServiceRef);
retFilter.setAdvancedSetting(getAdvancedSettingFromStr(advSettingStrVect));
if (isTopologyFilter) {
retFilter = new TopologyFilter(ServicesUtil.cyApplicationManagerServiceRef);
retFilter.setAdvancedSetting(getAdvancedSettingFromStr(advSettingStrVect));
getTopologyFilterFromStr((TopologyFilter) retFilter, filterStrVect, filters);
return retFilter;
}
if (isInteractionFilter) {
AdvancedSetting advSetting = getAdvancedSettingFromStr(advSettingStrVect);
if (advSetting.isNodeChecked()) {
retFilter = new NodeInteractionFilter(ServicesUtil.cyApplicationManagerServiceRef);
} else {
// advSetting.isEdgeChecked() == true
retFilter = new EdgeInteractionFilter(ServicesUtil.cyApplicationManagerServiceRef);
}
retFilter.setAdvancedSetting(advSetting);
getInteractionFilterFromStr((InteractionFilter) retFilter, filterStrVect, filters);
return retFilter;
}
Collection<CompositeFilter> allFilters = new LinkedHashSet<CompositeFilter>();
for (int i = 0; i < filterStrVect.size(); i++) {
line = filterStrVect.get(i);
if (line.startsWith("name=")) {
String name = line.substring(5);
retFilter.setName(name);
}
if (line.startsWith("Negation=true")) {
retFilter.setNegation(true);
}
if (line.startsWith("Negation=false")) {
retFilter.setNegation(false);
}
if (line.startsWith("StringFilter=")) {
String _stringFilterValue = line.substring(13);
String[] _values = _stringFilterValue.split(":");
// controllingAttribute+":" + negation+ ":"+searchStr+":"+index_type;
StringFilter _strFilter = new StringFilter(quickFind);
_strFilter.setParent(retFilter);
_strFilter.setControllingAttribute(_values[0]);
_strFilter.setNegation((new Boolean(_values[1])).booleanValue());
// handle the case where ':' is part of the search string
String _searchStr = _stringFilterValue.substring(_values[0].length() + _values[1].length() + 2, _stringFilterValue.length() - _values[_values.length - 1].length() - 1);
_strFilter.setSearchStr(_searchStr);
_strFilter.setIndexType((new Integer(_values[_values.length - 1])).intValue());
retFilter.addChild(_strFilter);
}
if (line.startsWith("NumericFilter=")) {
String[] _values = line.substring(14).split(":");
// controllingAttribute + ":" + negation+ ":"+lowBound+":" +
// highBound+ ":"+index_type;
// Determine data type of the attribute
String dataType = "int";
if (_values[2].indexOf(".") >= 0 || _values[2].indexOf("E") >= 0 || _values[3].indexOf(".") >= 0 || _values[3].indexOf("E") >= 0) {
dataType = "double";
}
if (dataType.equalsIgnoreCase("double")) {
NumericFilter<Double> _numFilter = new NumericFilter<Double>(quickFind);
_numFilter.setParent(retFilter);
_numFilter.setControllingAttribute(_values[0]);
_numFilter.setNegation((new Boolean(_values[1])).booleanValue());
_numFilter.setLowBound(Double.valueOf(_values[2]));
_numFilter.setHighBound(Double.valueOf(_values[3]));
_numFilter.setIndexType((new Integer(_values[4])).intValue());
retFilter.addChild(_numFilter);
} else {
// dataType = "int"
NumericFilter<Integer> _numFilter = new NumericFilter<Integer>(quickFind);
_numFilter.setParent(retFilter);
_numFilter.setControllingAttribute(_values[0]);
_numFilter.setNegation((new Boolean(_values[1])).booleanValue());
_numFilter.setLowBound(Integer.valueOf(_values[2]));
_numFilter.setHighBound(Integer.valueOf(_values[3]));
_numFilter.setIndexType((new Integer(_values[4])).intValue());
retFilter.addChild(_numFilter);
}
}
if (line.startsWith("CompositeFilter=")) {
// e.g. CompositeFilter=AAA:true
String[] _values = line.substring(16).split(":");
String name = _values[0].trim();
String notValue = _values[1].trim();
// get the reference CompositeFilter
CompositeFilter cmpFilter = null;
for (CompositeFilter cf : allFilters) {
if (cf.getName().equalsIgnoreCase(name)) {
cmpFilter = cf;
break;
}
}
if (cmpFilter != null) {
retFilter.addChild(cmpFilter, (new Boolean(notValue)).booleanValue());
}
}
if (line.startsWith("TopologyFilter=")) {
// e.g. TopologyFilter=AAA:true
String[] _values = line.substring(15).split(":");
String name = _values[0].trim();
String notValue = _values[1].trim();
// get the reference TopologyFilter
TopologyFilter topoFilter = null;
for (CompositeFilter cf : allFilters) {
if (cf.getName().equalsIgnoreCase(name)) {
topoFilter = (TopologyFilter) cf;
break;
}
}
if (topoFilter != null) {
retFilter.addChild(topoFilter, (new Boolean(notValue)).booleanValue());
}
}
if (line.startsWith("InteractionFilter=")) {
// e.g. InteractionFilter=AAA:true
String[] _values = line.substring(15).split(":");
String name = _values[0].trim();
String notValue = _values[1].trim();
// get the reference InteractionFilter
InteractionFilter interactionFilter = null;
for (CompositeFilter cf : allFilters) {
if (cf.getName().equalsIgnoreCase(name)) {
interactionFilter = (InteractionFilter) cf;
break;
}
}
if (interactionFilter != null) {
retFilter.addChild(interactionFilter, (new Boolean(notValue)).booleanValue());
}
}
}
return retFilter;
}
use of org.cytoscape.filter.internal.filters.model.CompositeFilter in project cytoscape-impl by cytoscape.
the class FilterWriter method saveGlobalPropFile.
public void saveGlobalPropFile(final Set<CompositeFilter> filters, final File file) {
// Because one filter may depend on the other, CompositeFilters must
// be sorted in the order of depthLevel before save
// filterPlugin.getAllFilterVect();
Set<CompositeFilter> allFilterVect = filters;
CompositeFilter[] sortedFilters = getSortedCompositeFilter(allFilterVect);
CompositeFilter[] globalFilters = getFiltersByScope(sortedFilters, "global");
try {
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file));
try {
// Need to allow writing of header only so that when the last
// global filter is deleted, the props file is updated to reflect this
writer.write("FilterVersion=0.2\n");
if (globalFilters != null) {
for (int i = 0; i < globalFilters.length; i++) {
CompositeFilter theFilter = (CompositeFilter) globalFilters[i];
writer.write(theFilter.toSerializedForm());
writer.write("\n");
}
}
} finally {
if (writer != null) {
writer.close();
}
}
} catch (Exception ex) {
logger.error("Global filter Write error", ex);
}
}
use of org.cytoscape.filter.internal.filters.model.CompositeFilter in project cytoscape-impl by cytoscape.
the class FilterWriter method write.
public void write(Collection<CompositeFilter> filters, File file) {
// Because one filter may depend on the other, CompositeFilters must
// be sorted in the order of depthLevel before save
CompositeFilter[] sortedFilters = getSortedCompositeFilter(filters);
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
try {
writer.write("FilterVersion=0.2\n");
for (CompositeFilter cf : sortedFilters) {
writer.write(cf.toSerializedForm());
writer.newLine();
}
} finally {
if (writer != null) {
writer.close();
}
}
} catch (Exception ex) {
logger.error("Error writing filters file", ex);
}
}
use of org.cytoscape.filter.internal.filters.model.CompositeFilter in project cytoscape-impl by cytoscape.
the class FilterWriter method getFiltersByScope.
private static CompositeFilter[] getFiltersByScope(Object[] pFilters, String pScope) {
if (pFilters == null || pFilters.length == 0) {
return null;
}
ArrayList<CompositeFilter> retFilterList = new ArrayList<CompositeFilter>();
for (int i = 0; i < pFilters.length; i++) {
CompositeFilter theFilter = (CompositeFilter) pFilters[i];
AdvancedSetting advSetting = theFilter.getAdvancedSetting();
if (pScope.equalsIgnoreCase("global")) {
if (advSetting.isGlobalChecked()) {
retFilterList.add(theFilter);
}
}
if (pScope.equalsIgnoreCase("session")) {
if (advSetting.isSessionChecked()) {
retFilterList.add(theFilter);
}
}
}
return retFilterList.toArray(new CompositeFilter[retFilterList.size()]);
}
Aggregations