Skip to content
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

Jbrowse2 service #258

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Jbrowse2 service #258

wants to merge 12 commits into from

Conversation

steve-fischer-200
Copy link
Collaborator

No description provided.

private static final String VDI_DATASET_SCHEMA_KEY ="VDI_DATASETS_SCHEMA";
private static final String WEB_SVC_DIR_KEY ="WEBSERVICEMIRROR";

/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use Javadoc here (two **s), our API may eventually pick it up. Doesn't now because we are using hard-coded RAML. :(

ProcessBuilder pb = new ProcessBuilder(command);
Map<String, String> env = pb.environment();
env.put("GUS_HOME", getWdkModel().getGusHome());
pb.redirectErrorStream(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to not merge the streams and instead collect error output into a String and check if non-empty. Don't know the characteristics of the subprocess. I see you're not checking return value either, so how do you know if it bombed? Would be nice to log the subprocess output in the case of runtime error- Cristina will definitely ask for this later.

return track;
}

String stringFromCommand(List<String> command) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to wait for the process to complete. Also I think the output collection could be simpler. Something like this:

    String stringFromCommand(List<String> command) throws IOException {
      try {
        Process p = processFromCommand(command);

        ByteArrayOutputStream stringBuffer = new ByteArrayOutputStream();
        p.getInputStream().transferTo(stringBuffer);
        String errors = stringBuffer.toString();

        stringBuffer.reset();
        p.getInputStream().transferTo(stringBuffer);

        if (p.waitFor() != 0) {
          throw new RuntimeException("Subprocess from [" + String.join(" ", command) + "] returned non-zero.  Errors:\n" + errors);
        }

        return stringBuffer.toString();
      }
      catch (InterruptedException e) {
        throw new RuntimeException("Subprocess from [" + String.join(" ", command) + "] was interrupted befor it could complete.");
      }
    }

display.put("scaleType", "log");
JSONArray displays = new JSONArray().put(display);
track.put("displays", displays);
JSONObject subAdapter = new JSONObject();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to add subAdapter anywhere. A nice feature of org.json is the ability to chain the calls together, so you can avoid misses like this. It also mirrors the structure of the resulting JSON, increasing readability. See below:

    JSONObject createBigwigTrackJson(String vdiId, String vdiName, String fileName, String organismAbbrev, String userDatasetsFilePath) {
      return new JSONObject()
          .put("assemblyNames", new JSONArray().put(organismAbbrev))
          .put("trackId", vdiId)
          .put("name", vdiName)
          .put("displays", new JSONArray()
              .put(new JSONObject()
                  .put("displayId", "wiggle_ApiCommonModel::Model::JBrowseTrackConfig::MultiBigWigTrackConfig::XY=HASH(0x2249320)")
                  .put("maxScore", 1)
                  .put("maxScore", 1000)
                  .put("defaultRendering", "multirowxy")
                  .put("type", "MultiLinearWiggleDisplay")
                  .put("scaleType", "log")))
          .put("adapter", new JSONObject()
              .put("subadapters", new JSONArray()
                  .put(new JSONObject()
                      .put("color1", "grey")
                      .put("name", fileName)
                      .put("type", "BigWigAdapter")
                      .put("bigWigLocation", new JSONObject()
                          .put("locationType", "UriLocation")
                          .put("uri", String.join("/", userDatasetsFilePath, vdiId, fileName))))));
    }

staticConfigJson.getJSONArray("tracks").putAll(udTracks);

// send response
String jsonString = staticConfigJson.toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little worried about the size of this. toString() means doubling the size of the completed file before returning. Wondering if we should be using Jackson to stream as Ellie suggested. Though that can probably wait until we know this is giving us what we want.

vdiControlSchema + ".dataset_dependency dd " +
"where project_id = '" + projectId + "' " +
"and (type = 'RnaSeq' or type = 'BigWig') " +
"and ((is_public = 1 and is_owner = 1) or user_id = " + userId + ") " +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? Seems like you would want table refs in these columns. Also, is sharing covered in AvailableUserDatasets? is_public is our community datasets indicator?

while (rs.next()) {
String datasetId = rs.getString(1);
String name = rs.getString(2);
List<String> fileNames = getBigwigFileNames(udDataPathString + "/" +datasetId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we can't return to the web client the full path to these files. We're returning relative URLs. Right now there's a script in service-jbrowse2 that does this transform using sed (depends on regex matching per line), but we should probably use jq so John can send the JSON in a single line. He mentioned this in one of our meetings. But wonder if we could be doing that here? We can at least set the correct value up front for user datasets.

}
}

// boilerplate method written by copilot
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to advertise this. :)

subAdapter.put("color1", "grey");
subAdapter.put("name", fileName);
subAdapter.put("type", "BigWigAdapter");
JSONObject location = new JSONObject().put("locationType", "UriLocation");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. maybe this is handling the filepath -> relative URL comment I made earlier. Should maybe add comments to talk about what is returned for the "location" of this track?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants