Skip to content

Commit

Permalink
Merge pull request #11 from qbicsoftware/feature/sample-and-dataset-t…
Browse files Browse the repository at this point in the history
…ransfer

add sample and dataset transfer/update (most cases), fix some issues
  • Loading branch information
wow-such-code authored Oct 15, 2024
2 parents 052edf7 + dd3000a commit e00052d
Show file tree
Hide file tree
Showing 18 changed files with 696 additions and 177 deletions.
6 changes: 5 additions & 1 deletion src/main/java/life/qbic/io/PetabParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import life.qbic.model.petab.PetabMetadata;

public class PetabParser {
Expand Down Expand Up @@ -94,4 +95,7 @@ private File findYaml(File directory) {
return null;
}

}
public void addPatientIDs(String outputPath, Set<String> patientIDs) {
System.err.println("found patient ids: "+patientIDs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ public class DownloadPetabCommand implements Runnable {

@Override
public void run() {
App.readConfig();
OpenBIS authentication = App.loginToOpenBIS(auth.getOpenbisPassword(), auth.getOpenbisUser(),
auth.getOpenbisAS(), auth.getOpenbisDSS());
OpenbisConnector openbis = new OpenbisConnector(authentication);

List<DataSet> datasets = openbis.findDataSets(Collections.singletonList(datasetCode));

if(datasets.isEmpty()) {
System.out.println(datasetCode+" not found");
System.out.println("Dataset "+datasetCode+" not found");
return;
}
DatasetWithProperties result = new DatasetWithProperties(datasets.get(0));
Expand All @@ -54,6 +55,7 @@ public void run() {
try {
System.out.println("Adding dataset identifier to metaInformation.yaml.");
parser.addDatasetId(outputPath, datasetCode);
parser.addPatientIDs(outputPath, patientIDs);
} catch (IOException e) {
System.out.println("Could not add dataset identifier.");
throw new RuntimeException(e);
Expand Down
46 changes: 36 additions & 10 deletions src/main/java/life/qbic/io/commandline/FindDatasetsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import life.qbic.App;
Expand All @@ -24,29 +23,56 @@
description = "lists datasets and their details for a given experiment code")
public class FindDatasetsCommand implements Runnable {

@Parameters(arity = "1", paramLabel = "experiment", description = "The code of the experiment data is attached to")
private String experimentCode;
@Option(arity = "1", paramLabel = "<space>", description = "Optional openBIS spaces to filter samples", names = {"-s", "--space"})
@Parameters(arity = "1", paramLabel = "openBIS obejct", description =
"The code of the experiment "
+ "or sample data is attached to.")
private String objectCode;
@Option(arity = "1", paramLabel = "<space>", description = "Optional openBIS spaces to filter "
+ "found datasets by", names = {"-s", "--space"})
private String space;
@Mixin
OpenbisAuthenticationOptions auth = new OpenbisAuthenticationOptions();

@Override
@Override
public void run() {
App.readConfig();
List<String> spaces = new ArrayList<>();
if (space != null) {
System.out.println("Querying experiment in space: " + space + "...");
spaces.add(space);
} else {
System.out.println("Querying experiment in all available spaces...");
}
if(objectCode.contains("/")) {
String[] splt = objectCode.split("/");
objectCode = splt[splt.length-1];
System.out.println("Query is not an object code, querying for: " + objectCode+" instead.");
}
OpenBIS authentication = App.loginToOpenBIS(auth.getOpenbisPassword(), auth.getOpenbisUser(),
auth.getOpenbisAS());
OpenbisConnector openbis = new OpenbisConnector(authentication);
List<DataSet> datasets = openbis.listDatasetsOfExperiment(spaces, experimentCode).stream()
.sorted(Comparator.comparing(
(DataSet d) -> d.getExperiment().getProject().getSpace().getCode())).collect(
Collectors.toList());

List<DataSet> datasetsOfExp = openbis.listDatasetsOfExperiment(spaces, objectCode).stream()
.sorted(Comparator.comparing(
(DataSet d) -> d.getExperiment().getProject().getSpace().getCode()))
.collect(Collectors.toList());

List<DataSet> datasets = new ArrayList<>();

if(!datasetsOfExp.isEmpty()) {
System.err.println("Found "+datasetsOfExp.size()+" datasets for experiment "+objectCode);
datasets.addAll(datasetsOfExp);
}
List<DataSet> datasetsOfSample = openbis.listDatasetsOfSample(spaces, objectCode).stream()
.sorted(Comparator.comparing(
(DataSet d) -> d.getExperiment().getProject().getSpace().getCode()))
.collect(Collectors.toList());

if(!datasetsOfSample.isEmpty()) {
System.err.println("Found "+datasetsOfSample.size()+" datasets for sample "+objectCode);
datasets.addAll(datasetsOfSample);
}

Map<String, String> properties = new HashMap<>();
if (!datasets.isEmpty()) {
Set<String> patientIDs = openbis.findPropertiesInSampleHierarchy("PATIENT_DKFZ_ID",
Expand All @@ -64,7 +90,7 @@ public void run() {
}).collect(Collectors.toList());
int datasetIndex = 0;
System.out.println();
System.out.printf("Found %s datasets for experiment %s:%n", datasets.size(), experimentCode);
System.out.printf("Found %s datasets for %s:%n", datasets.size(), objectCode);
for (DatasetWithProperties dataSet : datasetWithProperties) {
datasetIndex++;
System.out.println("["+datasetIndex+"]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.net.URL;
import java.util.StringJoiner;
import life.qbic.App;
import life.qbic.io.PropertyReader;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import picocli.CommandLine;
Expand Down Expand Up @@ -38,7 +37,8 @@ public class OpenbisAuthenticationOptions {
public String getOpenbisUser() {
if(openbisUser == null && App.configProperties.containsKey("user")) {
openbisUser = App.configProperties.get("user");
} else {
}
if(openbisUser == null) {
log.error("No openBIS user provided.");
System.exit(2);
}
Expand All @@ -49,13 +49,21 @@ public String getOpenbisDSS() {
if(dss_url == null && App.configProperties.containsKey("dss")) {
dss_url = App.configProperties.get("dss");
}
if(dss_url == null) {
log.error("No openBIS datastore server URL provided.");
System.exit(2);
}
return dss_url;
}

public String getOpenbisAS() {
if(as_url == null && App.configProperties.containsKey("as")) {
as_url = App.configProperties.get("as");
}
if(as_url == null) {
log.error("No openBIS application server URL provided.");
System.exit(2);
}
return as_url;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class SampleHierarchyCommand implements Runnable {

@Override
public void run() {
App.readConfig();
List<String> summary = new ArrayList<>();
List<String> spaces = new ArrayList<>();
if(space!=null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import java.util.StringJoiner;
import life.qbic.App;
import life.qbic.io.PropertyReader;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import picocli.CommandLine;
Expand All @@ -31,17 +30,19 @@ public class SeekAuthenticationOptions {
public String getSeekUser() {
if(seekUser == null && App.configProperties.containsKey("seek_user")) {
seekUser = App.configProperties.get("seek_user");
} else {
}
if (seekUser == null) {
log.error("No SEEK user/email provided.");
System.exit(2);
}
return seekUser;
}

public String getSeekURL() {
if(seek_url == null && App.configProperties.containsKey("seek_url")) {
if(seek_url != null || App.configProperties.containsKey("seek_url")) {
seek_url = App.configProperties.get("seek_url");
} else {
}
if(seek_url == null) {
log.error("No URL to the SEEK address provided.");
System.exit(2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class SpaceStatisticsCommand implements Runnable {

@Override
public void run() {
App.readConfig();
List<String> summary = new ArrayList<>();
List<String> blackList = new ArrayList<>(Arrays.asList("ELN_SETTINGS", "MATERIAL.GLOBAL"));
List<String> spaces = new ArrayList<>();
Expand Down
Loading

0 comments on commit e00052d

Please sign in to comment.