@sjcrh/proteinpaint-server 2.111.0 → 2.112.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/utils/density.R CHANGED
@@ -1,24 +1,31 @@
1
1
  library(jsonlite)
2
- # This script reads in a json string from stdin, calculates the densities of each plot and returns the densities as a json string
3
- # The input json string is a dictionary where each field maps to an array of numbers
4
- # The output json string is a dictionary with the density for each plot. The density is represented like {x: [x density values], y: [y density values]}
5
- # In order to test it you can run this from the command line replacing the arrays with your own:
6
- # echo '{"plotA": [1.2, 2, 3], "plotB": [4.5, 5, 6]}' | Rscript ./density.R
2
+ # This script reads in a json string from stdin with the parameters,
3
+ # calculates the densities of each plot and returns the densities as a json string
4
+ # The input json string contains plot2Values, a dictionary where each field maps to an array of numbers and the
5
+ # global min and max values of the x axis.
6
+ # The output json string is a dictionary with the density for each plot. The density is represented
7
+ # by a an object where {x: [x density values], y: [y density values]}
8
+ # In order to test it you can run the following command from the command line replacing plot2Values and min and max
9
+ # with your values:
10
+ # echo '{plot2Values: {"plotA": [1.2, 2, 3], "plotB": [4.5, 5, 6]}, min: 1.2, max:6}' | Rscript ./density.R
7
11
 
8
12
  con <- file("stdin", "r")
9
13
  json <- readLines(con)
10
14
  close(con)
11
15
  data <- fromJSON(json)
16
+ plot2Values <- data$plot2Values
17
+ min <- data$min
18
+ max <- data$max
12
19
  densities <- list()
13
- for(plot in names(data)){
14
- values = data[[plot]]
20
+ for(plot in names(plot2Values)){
21
+ values = plot2Values[[plot]]
15
22
  # If the plot has less than 5 values or all the values are the same, we will return a flat line
16
23
  if(length(values) <= 5 | length(unique(values)) == 1){
17
24
  y = rep(0, length(values))
18
25
  densities[[plot]] <- list(x=values, y=y)
19
26
  next
20
27
  }
21
- den = density(x = values, from=min(values), to=max(values))
28
+ den = density(x = values, from=min, to=max)
22
29
  x = den$x
23
30
  y = den$y
24
31
  result = list(x=x, y=y) #This is an object with two keys x and y that are number arrays
@@ -1,51 +0,0 @@
1
- import { clearWSImagesSessionsPayload } from "#types/checkers";
2
- import SessionManager from "#src/wsisessions/SessionManager.js";
3
- import ky from "ky";
4
- import serverconfig from "#src/serverconfig.js";
5
- const api = {
6
- endpoint: "clearwsisession",
7
- methods: {
8
- delete: {
9
- ...clearWSImagesSessionsPayload,
10
- init
11
- }
12
- }
13
- };
14
- function init() {
15
- return async (req, res) => {
16
- try {
17
- if (serverconfig.redis) {
18
- const sessionsString = req.query.sessions;
19
- const sessionsArray = JSON.parse(sessionsString);
20
- const sessions = new Map(sessionsArray);
21
- const sessionManager = SessionManager.getInstance(serverconfig.redis.url);
22
- for (const [key, value] of sessions.entries()) {
23
- const sessionData = await sessionManager.getSession(key);
24
- if (sessionData) {
25
- const userSessionIds = sessionData.userSessionIds;
26
- if (!userSessionIds.some((sessionId) => sessionId === value)) {
27
- break;
28
- }
29
- const newSessions = userSessionIds.filter((sessionId) => sessionId !== value);
30
- if (newSessions.length === 0) {
31
- await ky.put(`${serverconfig.tileServerURL}/tileserver/reset/${sessionData.imageSessionId}`);
32
- await sessionManager.deleteSession(key);
33
- } else {
34
- sessionData.userSessionIds = newSessions;
35
- await sessionManager.setSession(key, sessionData);
36
- }
37
- }
38
- }
39
- res.send({ message: "Sessions cleared" });
40
- } else {
41
- res.status(404).send("Redis not configured");
42
- }
43
- } catch (e) {
44
- console.log(e);
45
- res.status(404).send("Error clearing sessions");
46
- }
47
- };
48
- }
49
- export {
50
- api
51
- };