-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTwo-Gene Network Simulation using Function Nanoservice
92 lines (74 loc) · 2.86 KB
/
Two-Gene Network Simulation using Function Nanoservice
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Computational Medicine
# Two-Gene Network Simulation using Function Nanoservice
# Client-side code
# Yong-Jun Shin (2019)
import numpy as np
import matplotlib.pyplot as plt
import requests
import json
N = 100 # total number of data points
n = np.arange(0, N, 1) # [0,..., N-1] (vector)
x = np.empty(N) # protein x concentration in uM (vector)
y = np.empty(N) # protein y concentration in uM (vector)
x.fill(10) # constant x protein concentration (= 10 uM)
y[0] = 0 # initial y protein concentration (= 0 uM)
Pxy = 0.2 # production parameter
Py = 0.9 # degradation parameter
url = '' # Azure Functions URL
for i in range (1, N): # discrete-time index i
requestData = {'x':x[i-1], 'y':y[i-1], 'Pxy':Pxy, 'Py':Py} # data to be sent to the server
requestJson = json.dumps(requestData) # conversion to json (optional, not required)
response = requests.post(url, data = requestJson) # send data and receive response
responseJson = response.json()
y[i] = responseJson['y']
print (y[i])
# response with multiple data (y and z)
# responseJson = response.json()
# print (responseJson)
# y[i] = responseJson['y']
# z[i] = responseJson['z']
plt.plot(n,x,'g',label = 'x')
plt.plot(n,y,'r',label = 'y')
plt.xlabel('time (n)')
plt.ylabel('protein concentration (uM)')
plt.legend(loc='lower right')
plt.title('x --> y')
plt.grid(True)
plt.show()
---------------------------------------------------------------------------------
// Computational Medicine
// Simple 2-Gene Regulatory Network Simulation using Function Nanoservice
// Server-side code
// Yong-Jun Shin (2019)
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
public static async Task<double> Run(HttpRequest req, ILogger log)
{
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
double x = data.x; // x protein concentration in uM (scalar)
double y = data.y; // y protein concentration in uM (scalar)
double Pxy = data.Pxy; // production parameter
double Py = data.Py; // degradation parameter
y = Pxy*x + Py*y; // difference equation
log.LogInformation($"The new y protein concentration is {y}");
return y; // return new y value to the client
// return multiple data(y and z)
/*
Response r = new Response();
r.y = y;
r.z = z;
return r;
*/
}
// create a new class to bundle response data
/*
public class Response
{
public double y; // y protein concentration (scalar)
public double z; // z protein concentration (scalar)
}
*/