Skip to content

Commit

Permalink
initial drs hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Sep 30, 2023
1 parent be8ccfa commit 59c5f44
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/main/java/org/broad/igv/drs/TerraResolver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package org.broad.igv.drs;

import org.broad.igv.oauth.OAuthUtils;
import org.broad.igv.util.HttpUtils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;

// https://drshub.dsde-prod.broadinstitute.org/
public class TerraResolver {


public static Object resolve(String drsURL) {

try {
OAuthUtils.getInstance().getGoogleProvider().checkLogin();

String accessToken = OAuthUtils.getInstance().getGoogleProvider().getAccessToken();

System.out.println(accessToken);

Object response = doPost("https://drshub.dsde-prod.broadinstitute.org/", accessToken);

return response;
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private static Object doPost(String drsURL, String accessToken) throws IOException {
URL url = new URL(drsURL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Accept", "*/*");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Authorization", "Bearer " + accessToken);
con.setDoOutput(true);

String body = """
{
"url": """ + drsURL + """
"fields": ["bucket", "contentType", "fileName", "gsUri", "hashes", "localizationPath", "name", "size", "timeCreated", "timeUpdated"]
}
""";

try(OutputStream os = con.getOutputStream()) {
byte[] input = body.getBytes("utf-8");
os.write(input, 0, input.length);
}

try(BufferedReader br = new BufferedReader(
new InputStreamReader(con.getInputStream(), "utf-8"))) {
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println(response.toString());
}

return null;
}

}


//curl -X 'POST' \
// 'https://drshub.dsde-prod.broadinstitute.org/api/v4/drs/resolve' \
// -H 'accept: */*' \
// -H 'Authorization: Bearer <token for Terra user>' \
// -H 'Content-Type: application/json' \
// -d '{
// "url": "drs://dg.4503:dg.4503/c64fded3-459b-4fca-82bc-35d154e9aa91",
// "fields": ["bucket", "contentType", "fileName", "gsUri", "hashes", "localizationPath", "name", "size", "timeCreated", "timeUpdated"]
// }'


// Compact IDS - not terra
// drs://dg.4503:dg.4503/c64fded3-459b-4fca-82bc-35d154e9aa91
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
package org.broad.igv.ui.action;

import org.broad.igv.Globals;
import org.broad.igv.drs.TerraResolver;
import org.broad.igv.logging.*;
import org.broad.igv.feature.genome.GenomeManager;
import org.broad.igv.util.GoogleUtils;
Expand Down Expand Up @@ -83,6 +84,11 @@ public void actionPerformed(ActionEvent e) {

String[] inputs = Globals.whitespacePattern.split(inputURLs.trim());
checkURLs(inputs);

if(inputs[0].startsWith("drs:")) {
System.out.println(TerraResolver.resolve(inputs[0]));
return;
}
if (inputs.length == 1 && SessionReader.isSessionFile(inputs[0])) {
// Session URL
String url = inputs[0];
Expand Down

0 comments on commit 59c5f44

Please sign in to comment.