Skip to content
Snippets Groups Projects
Commit c1cb7cd6 authored by tpylak's avatar tpylak
Browse files

minor: remove unused code

SVN: 18138
parent 6d913cff
No related branches found
No related tags found
No related merge requests found
package ch.systemsx.cisd.openbis.hcdc;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Reference to an entity (e.g. plate or experiment) in openBIS.
*
* @author Tomasz Pylak
*/
public class EntityReference
{
// technical id of the entity
private final long id;
// user friendly identifier
private final String identifier;
public EntityReference(long id, String identifier)
{
this.id = id;
this.identifier = identifier;
}
public TechId getId()
{
return new TechId(id);
}
public String getIdentifier()
{
return identifier;
}
@Override
public String toString()
{
return identifier;
}
}
package ch.systemsx.cisd.openbis.hcdc;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import ch.systemsx.cisd.common.spring.HttpInvokerUtils;
import ch.systemsx.cisd.openbis.generic.shared.ICommonServer;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExperimentType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ISerializableComparable;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListSampleCriteria;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModel;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModelColumnHeader;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModelRow;
import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ProjectIdentifier;
import ch.systemsx.cisd.openbis.plugin.screening.shared.IScreeningServer;
import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.PlateSingleImageReference;
/**
* A facade of openBIS API for KNIME-HCDC integration.
*
* @author Tomasz Pylak
*/
public class HCDSFacade
{
private static final int SERVER_TIMEOUT_MIN = 5;
private final ICommonServer commonServer;
private final IScreeningServer screeningServer;
private final String sessionToken;
public HCDSFacade(String userId, String userPassword, String serverUrl)
{
this.commonServer = getOpenbisServer(serverUrl);
this.screeningServer = getScreeningServer(serverUrl);
this.sessionToken = authenticate(commonServer, userId, userPassword);
}
public List<PlateSingleImageReference> listImagePathsForPlate(long plateId)
{
List<PlateSingleImageReference> images =
screeningServer.listPlateImages(sessionToken, new TechId(plateId));
Collections.sort(images, new Comparator<PlateSingleImageReference>()
{
public int compare(PlateSingleImageReference o1, PlateSingleImageReference o2)
{
return o1.getImagePath().compareTo(o2.getImagePath());
}
});
return images;
}
public TabularData listImageAnalysisResultsForExp(long experimentId)
{
TableModel tableModel =
screeningServer.loadImageAnalysisForExperiment(sessionToken, new TechId(
experimentId));
return createTable(tableModel);
}
private TabularData createTable(TableModel tableModel)
{
String[] header = convert(tableModel.getHeader());
String[][] rows = convert(tableModel.getRows());
boolean[] isNumeric = extractIsNumeric(tableModel.getHeader());
return new TabularData(header, rows, isNumeric);
}
private boolean[] extractIsNumeric(List<TableModelColumnHeader> header)
{
boolean[] isNumeric = new boolean[header.size()];
for (int i = 0; i < isNumeric.length; i++)
{
isNumeric[i] = header.get(i).isNumeric();
}
return isNumeric;
}
private String[][] convert(List<TableModelRow> rows)
{
List<String[]> converterRows = new ArrayList<String[]>();
for (TableModelRow row : rows)
{
converterRows.add(convert(row));
}
String[][] result = new String[converterRows.size()][];
for (int i = 0; i < converterRows.size(); i++)
{
result[i] = converterRows.get(i);
}
return result;
}
private String[] convert(TableModelRow row)
{
List<ISerializableComparable> values = row.getValues();
String[] result = new String[values.size()];
for (int i = 0; i < result.length; i++)
{
result[i] = values.get(i).toString();
}
return result;
}
private String[] convert(List<TableModelColumnHeader> headers)
{
String[] result = new String[headers.size()];
for (int i = 0; i < result.length; i++)
{
result[i] = headers.get(i).getTitle();
}
return result;
}
public TabularData listImageAnalysisResultsForPlate(long plateId)
{
TableModel tableModel =
screeningServer.loadImageAnalysisForPlate(sessionToken, new TechId(plateId));
return createTable(tableModel);
}
public List<EntityReference> listExperimentsIdentifiers()
{
List<Project> projects = commonServer.listProjects(sessionToken);
List<Experiment> allExperiments = new ArrayList<Experiment>();
for (Project project : projects)
{
ProjectIdentifier identifier = createProjectIdentifier(project);
List<Experiment> experiments =
commonServer.listExperiments(sessionToken, getScreeningExperimentType(),
identifier);
allExperiments.addAll(experiments);
}
return asReferences(allExperiments);
}
private List<EntityReference> asReferences(List<Experiment> experiments)
{
List<EntityReference> result = new ArrayList<EntityReference>();
for (Experiment experiment : experiments)
{
result.add(new EntityReference(experiment.getId(), experiment.getIdentifier()));
}
return result;
}
private static ProjectIdentifier createProjectIdentifier(Project project)
{
return new ProjectIdentifier(project.getGroup().getCode(), project.getCode());
}
private static ExperimentType getScreeningExperimentType()
{
ExperimentType type = new ExperimentType();
type.setCode("SIRNA_HCS");
return type;
}
public List<EntityReference> listPlateIdentifiers(EntityReference experimentReference)
{
List<Sample> samples =
commonServer.listSamples(sessionToken, ListSampleCriteria
.createForExperiment(experimentReference.getId()));
List<EntityReference> result = new ArrayList<EntityReference>();
for (Sample sample : samples)
{
result.add(new EntityReference(sample.getId(), sample.getIdentifier()));
}
return result;
}
private static String authenticate(ICommonServer commonServer, String userId,
String userPassword)
{
SessionContextDTO session = commonServer.tryToAuthenticate(userId, userPassword);
String sessionToken = session.getSessionToken();
return sessionToken;
}
private static ICommonServer getOpenbisServer(String serverUrl)
{
return HttpInvokerUtils.createServiceStub(ICommonServer.class, serverUrl + "/rmi-common",
SERVER_TIMEOUT_MIN);
}
private static IScreeningServer getScreeningServer(String serverUrl)
{
return HttpInvokerUtils.createServiceStub(IScreeningServer.class, serverUrl
+ "/rmi-screening", SERVER_TIMEOUT_MIN);
}
}
package ch.systemsx.cisd.openbis.hcdc;
import java.util.List;
import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.PlateSingleImageReference;
/**
* Demo of the openBIS client which uses simple fasade object to connect to the server.
*
* @author Tomasz Pylak
*/
public class OpenbisConnectionDemo
{
private static final String USER_ID = "hcdc_observer";
private static final String USER_PASSWORD = "xxx";
private static final String SERVER_URL = "https://onlyweb1.ethz.ch:8443/openbis/openbis";
public static void main(String[] args)
{
HCDSFacade client = new HCDSFacade(USER_ID, USER_PASSWORD, SERVER_URL);
List<EntityReference> experimentsIdentifiers = client.listExperimentsIdentifiers();
System.out.println("experiments: " + experimentsIdentifiers);
for (EntityReference experiment : experimentsIdentifiers)
{
if (experiment.getIdentifier().contains("KUTAY"))
{
List<EntityReference> plateIdentifiers = client.listPlateIdentifiers(experiment);
System.out.println("Plates in " + experiment + ": " + plateIdentifiers);
for (EntityReference plate : plateIdentifiers)
{
if (plate.getIdentifier().contains("H001-1A"))
{
Long plateId = plate.getId().getId();
TabularData table = client.listImageAnalysisResultsForPlate(plateId);
System.out.println("Image analysis results: " + table);
System.out.println("Fetching images...");
List<PlateSingleImageReference> images =
client.listImagePathsForPlate(plateId);
System.out.println("Images in " + plate + ": " + toString(images));
}
}
}
}
}
private static String toString(List<PlateSingleImageReference> images)
{
String text = "";
for (PlateSingleImageReference image : images)
{
text += image.getImagePath() + "\n";
}
return text;
}
}
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.hcdc;
/**
* Simple table to store e.g. tsv file content.
*
* @author Tomasz Pylak
*/
public class TabularData
{
private final String[] headers;
private final boolean[] isNumeric;
private final String[][] rows;
public TabularData(String[] header, String[][] rows, boolean[] isNumeric)
{
this.headers = header;
this.isNumeric = isNumeric;
this.rows = rows;
}
public String[] getHeader()
{
return headers;
}
public String[][] getRows()
{
return rows;
}
public int getColumnIndex(String columnName)
{
for (int i = 0; i < headers.length; i++)
{
if (headers[i].equalsIgnoreCase(columnName))
{
return i;
}
}
return -1;
}
public boolean isNumericColumn(int index)
{
return isNumeric[index];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment