-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow dataset connection to sample, improve error handling #7
Changes from 1 commit
296c981
eaf8d7e
cb3933d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package life.qbic.io.commandline; | ||
|
||
import ch.ethz.sis.openbis.generic.OpenBIS; | ||
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.DataSet; | ||
import java.io.File; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import life.qbic.App; | ||
import life.qbic.model.DatasetWithProperties; | ||
import life.qbic.model.download.OpenbisConnector; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Mixin; | ||
import picocli.CommandLine.Option; | ||
import picocli.CommandLine.Parameters; | ||
|
||
@Command(name = "openbis-to-seek", | ||
description = "Transfers data or metadata from openBIS to SEEK.") | ||
public class TransferDataToSeekCommand implements Runnable { | ||
|
||
@Parameters(arity = "1", paramLabel = "dataset id", description = "The code of the dataset (or its metadata) to transfer. Can be found via list-data.") | ||
private String datasetCode; | ||
@Parameters(arity = "1", paramLabel = "seek node", description = "The node in SEEK to which to transfer the dataset.") | ||
private String seekNode; | ||
@Option(names = { "-d", "--data"}, usageHelp = true, description = "Transfers the data itself to SEEK along with the metadata") | ||
private boolean transferData; | ||
@Mixin | ||
AuthenticationOptions auth = new AuthenticationOptions(); | ||
|
||
@Override | ||
public void run() { | ||
OpenBIS authentication = App.loginToOpenBIS(auth.getOpenbisPassword(), auth.getOpenbisUser(), auth.getAS(), auth.getDSS()); | ||
OpenbisConnector openbis = new OpenbisConnector(authentication); | ||
|
||
List<DataSet> datasets = openbis.findDataSets(Collections.singletonList(datasetCode)); | ||
|
||
if(datasets.isEmpty()) { | ||
System.out.println(datasetCode+" not found"); | ||
return; | ||
} | ||
DatasetWithProperties result = new DatasetWithProperties(datasets.get(0)); | ||
Optional<String> patientID = openbis.findPropertyInSampleHierarchy("PATIENT_DKFZ_ID", | ||
result.getExperiment().getIdentifier()); | ||
patientID.ifPresent(s -> result.addProperty("patientID", s)); | ||
|
||
System.out.println("Found dataset, downloading."); | ||
System.out.println(); | ||
|
||
final String tmpPath = "tmp/"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused of the purpose of this command? It downloads the data into a temp folder and afterwards deletes it again? |
||
|
||
File downloadFolder = openbis.downloadDataset(tmpPath, datasetCode); | ||
|
||
|
||
|
||
cleanupTemp(new File(tmpPath)); | ||
|
||
System.out.println("Done"); | ||
} | ||
|
||
private void cleanupTemp(File tmpFolder) { | ||
File[] files = tmpFolder.listFiles(); | ||
if (files != null) { //some JVMs return null for empty dirs | ||
for (File f : files) { | ||
if (f.isDirectory()) { | ||
cleanupTemp(f); | ||
} else { | ||
f.delete(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,6 @@ | |
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.id.DataSetPermId; | ||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneOffset; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import life.qbic.App; | ||
|
@@ -23,9 +19,9 @@ public class UploadDatasetCommand implements Runnable { | |
|
||
@Parameters(arity = "1", paramLabel = "file/folder", description = "The path to the file or folder to upload") | ||
private String dataPath; | ||
@Parameters(arity = "1", paramLabel = "experiment ID", description = "The full identifier of the experiment the data should be attached to. " | ||
+ "The identifier must be of the format: /space/project/experiment") | ||
private String experimentID; | ||
@Parameters(arity = "1", paramLabel = "object ID", description = "The full identifier of the experiment or sample the data should be attached to. " | ||
+ "The identifier must be of the format: /space/project/experiment for experiments or /space/sample for samples") | ||
private String objectID; | ||
@Option(arity = "1..*", paramLabel = "<parent_datasets>", description = "Optional list of dataset codes to act" | ||
+ " as parents for the upload. E.g. when this dataset has been generated using these datasets as input.", names = {"-pa", "--parents"}) | ||
private List<String> parents = new ArrayList<>(); | ||
|
@@ -36,15 +32,28 @@ public class UploadDatasetCommand implements Runnable { | |
|
||
@Override | ||
public void run() { | ||
OpenBIS authentication = App.loginToOpenBIS(auth.getPassword(), auth.getUser(), auth.getAS(), auth.getDSS()); | ||
OpenBIS authentication = App.loginToOpenBIS(auth.getOpenbisPassword(), auth.getOpenbisUser(), auth.getAS(), auth.getDSS()); | ||
openbis = new OpenbisConnector(authentication); | ||
|
||
if(!pathValid(dataPath)) { | ||
System.out.printf("Path %s could not be found%n", dataPath); | ||
return; | ||
} | ||
if(!experimentExists(experimentID)) { | ||
System.out.printf("Experiment %s could not be found%n", experimentID); | ||
boolean attachToSample = OpenbisConnector.sampleIdPattern.matcher(objectID).find(); | ||
boolean attachToExperiment = false; | ||
if(!attachToSample) { | ||
attachToExperiment = OpenbisConnector.experimentIdPattern.matcher(objectID).find(); | ||
} | ||
if(!attachToExperiment && !attachToSample) { | ||
System.out.printf("%s is neither a valid experiment nor sample identifier%n", objectID); | ||
return; | ||
} | ||
if(attachToExperiment && !experimentExists(objectID)) { | ||
System.out.printf("Experiment with identifier %s could not be found%n", objectID); | ||
return; | ||
} | ||
if(attachToSample && !sampleExists(objectID)) { | ||
System.out.printf("Sample object with identifier %s could not be found%n", objectID); | ||
return; | ||
} | ||
if(!datasetsExist(parents)) { | ||
|
@@ -54,10 +63,19 @@ public void run() { | |
System.out.println(); | ||
System.out.println("Parameters verified, uploading dataset..."); | ||
System.out.println(); | ||
DataSetPermId result = openbis.registerDataset(Path.of(dataPath), experimentID, parents); | ||
System.out.printf("Dataset %s was successfully created%n", result.getPermId()); | ||
if(attachToExperiment) { | ||
DataSetPermId result = openbis.registerDatasetForExperiment(Path.of(dataPath), objectID, parents); | ||
System.out.printf("Dataset %s was successfully created%n", result.getPermId()); | ||
wow-such-code marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: I think it would help to have 2 different output messages here, since one result attaches the dataset to an experiment while the other registers it to a sample |
||
DataSetPermId result = openbis.registerDatasetForSample(Path.of(dataPath), objectID, parents); | ||
System.out.printf("Dataset %s was successfully created%n", result.getPermId()); | ||
wow-such-code marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
private boolean sampleExists(String objectID) { | ||
return openbis.sampleExists(objectID); | ||
} | ||
|
||
private boolean datasetsExist(List<String> datasetCodes) { | ||
return openbis.findDataSets(datasetCodes).size() == datasetCodes.size(); | ||
} | ||
|
@@ -70,4 +88,5 @@ private boolean pathValid(String dataPath) { | |
return new File(dataPath).exists(); | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,13 +33,17 @@ public class UploadPetabResultCommand implements Runnable { | |
|
||
@Override | ||
public void run() { | ||
OpenBIS authentication = App.loginToOpenBIS(auth.getPassword(), auth.getUser(), auth.getAS(), auth.getDSS()); | ||
OpenBIS authentication = App.loginToOpenBIS(auth.getOpenbisPassword(), auth.getOpenbisUser(), auth.getAS(), auth.getDSS()); | ||
openbis = new OpenbisConnector(authentication); | ||
|
||
if(!pathValid(dataPath)) { | ||
System.out.printf("Path %s could not be found%n", dataPath); | ||
return; | ||
} | ||
if(!new File(dataPath).isDirectory()) { | ||
System.out.printf("%s is not a directory. Please specify the PETab directory root%n", dataPath); | ||
return; | ||
} | ||
if(!experimentExists(experimentID)) { | ||
System.out.printf("Experiment %s could not be found%n", experimentID); | ||
return; | ||
|
@@ -60,7 +64,7 @@ public void run() { | |
} | ||
System.out.println("Uploading dataset..."); | ||
//TODO copy and remove source references here | ||
DataSetPermId result = openbis.registerDataset(Path.of(dataPath), experimentID, parents); | ||
DataSetPermId result = openbis.registerDatasetForExperiment(Path.of(dataPath), experimentID, parents); | ||
System.out.printf("Dataset %s was successfully created%n", result.getPermId()); | ||
Comment on lines
+67
to
68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need to differentiate between registration to an experiment and to a sample here as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the use case here was specified as always using an experiment |
||
} | ||
|
||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could there be other PatientIds classifiers? If so i'd recommend to move this into a global identifier.