@sjcrh/proteinpaint-server 2.86.0 → 2.87.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.
Files changed (48) hide show
  1. package/package.json +6 -10
  2. package/routes/_template_.js +1 -1
  3. package/routes/brainImaging.js +2 -9
  4. package/routes/burden.js +1 -1
  5. package/routes/dataset.js +1 -1
  6. package/routes/dsdata.js +1 -1
  7. package/routes/dzimages.js +1 -1
  8. package/routes/gdc.maf.js +2 -2
  9. package/routes/gdc.mafBuild.js +2 -2
  10. package/routes/gdc.topMutatedGenes.js +1 -1
  11. package/routes/genelookup.js +1 -1
  12. package/routes/genesetEnrichment.js +5 -3
  13. package/routes/genesetOverrepresentation.js +1 -1
  14. package/routes/healthcheck.js +1 -1
  15. package/routes/hicdata.js +1 -1
  16. package/routes/hicgenome.js +1 -1
  17. package/routes/hicstat.js +1 -1
  18. package/routes/isoformlst.js +1 -1
  19. package/routes/ntseq.js +1 -1
  20. package/routes/pdomain.js +1 -1
  21. package/routes/sampledzimages.js +1 -1
  22. package/routes/samplewsimages.js +1 -1
  23. package/routes/snp.js +1 -1
  24. package/routes/termdb.DE.js +1 -1
  25. package/routes/termdb.boxplot.js +22 -15
  26. package/routes/termdb.categories.js +1 -1
  27. package/routes/termdb.cluster.js +1 -1
  28. package/routes/termdb.cohort.summary.js +1 -1
  29. package/routes/termdb.cohorts.js +1 -1
  30. package/routes/termdb.descrstats.js +1 -1
  31. package/routes/termdb.numericcategories.js +1 -1
  32. package/routes/termdb.percentile.js +1 -1
  33. package/routes/termdb.rootterm.js +1 -1
  34. package/routes/termdb.sampleImages.js +1 -1
  35. package/routes/termdb.singleSampleMutation.js +1 -1
  36. package/routes/termdb.singlecellDEgenes.js +1 -1
  37. package/routes/termdb.singlecellData.js +1 -1
  38. package/routes/termdb.singlecellSamples.js +5 -5
  39. package/routes/termdb.termchildren.js +1 -1
  40. package/routes/termdb.termsbyids.js +1 -1
  41. package/routes/termdb.topTermsByType.js +1 -1
  42. package/routes/termdb.topVariablyExpressedGenes.js +1 -1
  43. package/routes/termdb.violin.js +1 -1
  44. package/routes/tileserver.js +1 -1
  45. package/routes/wsimages.js +1 -1
  46. package/src/app.js +217 -185
  47. package/utils/gsea.py +13 -3
  48. package/utils/plotBrainImaging.py +92 -53
package/utils/gsea.py CHANGED
@@ -10,7 +10,7 @@ import numpy as np
10
10
  import pandas as pd
11
11
 
12
12
  def extract_symbols(x):
13
- return x['symbol']
13
+ return x['symbol']
14
14
 
15
15
  def extract_plot_data(signature, geneset, library, result, center=True):
16
16
  signature = signature.copy()
@@ -48,6 +48,7 @@ try:
48
48
  genes=json_object['genes']
49
49
  fold_change=json_object['fold_change']
50
50
  table_name=json_object['geneset_group']
51
+ filter_non_coding_genes=json_object['filter_non_coding_genes']
51
52
  df = {'Genes': genes, 'fold_change': fold_change}
52
53
  signature=pd.DataFrame(df)
53
54
  db=json_object['db']
@@ -59,10 +60,19 @@ try:
59
60
 
60
61
  # SQL query to select all data from the table
61
62
  query = f"select id from terms where parent_id='" + table_name + "'"
62
-
63
63
  # Execute the SQL query
64
64
  cursor.execute(query)
65
-
65
+ if filter_non_coding_genes == True:
66
+ # SQL query to code all the protein coding genes
67
+ coding_genes_query = f"select * from codingGenes"
68
+ genedb = json_object['genedb']
69
+ gene_conn = sqlite3.connect(genedb)
70
+ gene_cursor = gene_conn.cursor()
71
+ gene_cursor.execute(coding_genes_query)
72
+ coding_genes_list=gene_cursor.fetchall()
73
+ coding_genes_list=list(map(lambda x: x[0],coding_genes_list))
74
+ signature=signature[signature['Genes'].isin(coding_genes_list)]
75
+
66
76
  # Fetch all rows from the executed SQL query
67
77
  rows = cursor.fetchall()
68
78
 
@@ -1,69 +1,108 @@
1
1
  import nibabel as nib # Library for loading data from neuroimaging file formats such as NIfTI
2
2
  import matplotlib.pyplot as plt
3
+ import matplotlib.colors as mcolors
4
+ import matplotlib.cm as cm
3
5
  import numpy as np
4
6
  import sys
5
7
  import io
8
+ import json
6
9
 
7
10
  if len(sys.argv) <= 1:
8
- print('python3 '+sys.argv[0]+' <path/to/template/file> <path/to/label/file> indexL indexF, indexT')
11
+ print('python3 '+sys.argv[0]+' <path/to/template/file> plane index filesJson.\n filesJson: dictionary containg sample files and color per category).\nplane: L (left, sagittal), F (front, coronal), T (top, axial)')
12
+ sys.exit(1)
13
+
14
+ plane = sys.argv[2]
15
+ if(plane != 'L' and plane != 'F' and plane != 'T'):
16
+ print('Invalid plane')
17
+ sys.exit(1)
18
+ index = sys.argv[3]
19
+
20
+ if(len(index) == 0):
21
+ print('Need to provide index')
9
22
  sys.exit(1)
10
23
 
11
24
  templateFile = sys.argv[1]
12
- labelFile = sys.argv[2]
13
25
 
14
26
  # load data from nifti files
15
27
  template = nib.load(templateFile).get_fdata()
16
- labels = nib.load(labelFile).get_fdata()
17
- labels = np.ma.masked_where(labels == 0, labels) # Mask labels where they are 0
18
-
19
- l = int(sys.argv[3]) if len(sys.argv) > 3 else 70
20
- f = int(sys.argv[4]) if len(sys.argv) > 4 else 110
21
- t = int(sys.argv[5]) if len(sys.argv) > 5 else 80
22
-
23
- # extract slices l (left, sagittal), f (front, coronal), t (top, axial) from the template and label data
24
- left_slice = template[l,:,:]
25
- front_slice = template[:,f,:]
26
- top_slice = template[:,:,t]
27
-
28
- left_label = labels[l,:,:]
29
- front_label = labels[:,f,:]
30
- top_label = labels[:,:,t]
31
-
32
-
33
- # adjust the orientation of the plots by flipping and rotating
34
- left_slice = np.rot90(left_slice)
35
- left_label = np.rot90(left_label)
36
-
37
- front_slice = np.flip(np.rot90(front_slice),axis=1)
38
- front_label = np.flip(np.rot90(front_label),axis=1)
39
-
40
- top_slice = np.flip(np.rot90(top_slice),axis=1)
41
- top_label = np.flip(np.rot90(top_label),axis=1)
42
-
43
-
44
- # create three subplots for sagittal, coronal and axial plane
45
- fig, ax = plt.subplots(1, 3)
46
- vmin = 0
47
- vmax = 100
48
- alpha = 0.5
49
- ax[0].imshow(left_slice, 'gray', filternorm=False, vmin=vmin, vmax=vmax)
50
- ax[0].imshow(left_label, 'jet', alpha=alpha, filternorm=False,vmin=0,vmax=102)
51
- ax[0].axis('off')
52
- ax[0].text(0, 0.5, 'P', fontsize=12, color='white', ha='center', va='center', transform=ax[0].transAxes)
53
- ax[0].text(0.5, 1, 'S', fontsize=12, color='white', ha='center', va='center', transform=ax[0].transAxes)
54
-
55
- ax[1].imshow(front_slice, 'gray', filternorm=False, vmin=vmin, vmax=vmax)
56
- ax[1].imshow(front_label, cmap='jet', alpha=alpha, filternorm=False,vmin=0,vmax=102)
57
- ax[1].axis('off')
58
- ax[1].text(0, 0.5, 'R', fontsize=12, color='white', ha='center', va='center', transform=ax[1].transAxes)
59
- ax[1].text(0.5, 1, 'S', fontsize=12, color='white', ha='center', va='center', transform=ax[1].transAxes)
60
-
61
- ax[2].imshow(top_slice, 'gray', filternorm=False, vmin=vmin, vmax=vmax)
62
- ax[2].imshow(top_label, cmap='jet', alpha=alpha, filternorm=False,vmin=0,vmax=102)
63
- ax[2].axis('off')
64
- ax[2].text(0, 0.5, 'R', fontsize=12, color='white', ha='center', va='center', transform=ax[2].transAxes)
65
- ax[2].text(0.5, 1, 'A', fontsize=12, color='white', ha='center', va='center', transform=ax[2].transAxes)
66
- fig.subplots_adjust(wspace=0, hspace=0)
28
+
29
+ vmaxSamples = sys.argv[4]
30
+
31
+ if(len(vmaxSamples) == 0):
32
+ print('Need to provide max samples for normalization')
33
+ sys.exit(1)
34
+ vmaxSamples = int(vmaxSamples)
35
+
36
+ sampleFiles = json.loads(sys.argv[5])
37
+
38
+
39
+ index = int(index)
40
+ # (left, sagittal), f (front, coronal), t (top, axial)
41
+ if plane == 'L':
42
+ slice = template[index,:,:]
43
+ slice = np.rot90(slice)
44
+ elif plane == 'F':
45
+ slice = template[:,index,:]
46
+ slice = np.flip(np.rot90(slice),axis=1)
47
+
48
+ else:# plane == 'T'
49
+ slice = template[:,:,index]
50
+ slice = np.flip(np.rot90(slice),axis=1)
51
+
52
+ fig, ax = plt.subplots(1, 1)
53
+ ax.imshow(slice, 'gray', filternorm=False, vmin=0, vmax=100)
54
+
55
+ for key, value in sampleFiles.items():
56
+ if(len(value["samples"]) == 0) :
57
+ continue
58
+ # Load all sample files
59
+ sample_data = [nib.load(file_path).get_fdata() for file_path in value["samples"]]
60
+
61
+ # Initialize the result array with zeros
62
+ labels = np.zeros_like(sample_data[0])
63
+
64
+ # Sum all sample data
65
+ for data in sample_data:
66
+ labels += data
67
+
68
+ labels = np.ma.masked_where(labels == 0, labels) # Mask labels where they are 0
69
+
70
+
71
+ index = int(index)
72
+ # (left, sagittal), f (front, coronal), t (top, axial)
73
+ if plane == 'L':
74
+ label = labels[index,:,:]
75
+ label = np.rot90(label)
76
+ elif plane == 'F':
77
+ label = labels[:,index,:]
78
+ label = np.flip(np.rot90(label),axis=1)
79
+ else:# plane == 'T'
80
+ label = labels[:,:,index]
81
+ label = np.flip(np.rot90(label),axis=1)
82
+
83
+
84
+
85
+ # create three subplots for sagittal, coronal and axial plane
86
+ vmin = 0
87
+ vmax = 100
88
+ alpha = 0.6
89
+
90
+ color = value['color']
91
+ print(color)
92
+ cmap = mcolors.LinearSegmentedColormap.from_list('my_cmap', ['white', color])
93
+ ax.imshow(label, cmap, alpha=alpha, filternorm=False,vmin=0,vmax=vmaxSamples)
94
+ ax.axis('off')
95
+
96
+ # Create the color bar
97
+ # if showLegend == 1:
98
+ # # Create a color bar without changing figure size
99
+ # norm = mcolors.Normalize(vmin=0, vmax=vmaxSamples)
100
+ # sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm)
101
+
102
+ # cbar = plt.colorbar(sm, ax=ax, orientation='vertical', fraction=0.01, pad=0.05, alpha=alpha)
103
+ # cbar.set_label('Combined Intensity', color='white', fontsize=6, labelpad=-10)
104
+ # cbar.ax.text(0.5, 1.0001, vmaxSamples, ha='center', va='bottom', transform=cbar.ax.transAxes, color='white', fontsize=6)
105
+ # cbar.ax.text(0.5, -0.0001, 0, ha='center', va='top', transform=cbar.ax.transAxes, color='white', fontsize=6)
67
106
 
68
107
  # Output the image data to stdout
69
108
  buf = io.BytesIO()