forked from yunguan-wang/SPROD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_examples.py
More file actions
executable file
·76 lines (66 loc) · 3.19 KB
/
Copy pathtest_examples.py
File metadata and controls
executable file
·76 lines (66 loc) · 3.19 KB
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
# Need to install sprod first
# Need to do module purge so that the R.cpp will work
# Need R/4.0.2
import pandas as pd
import os
sprod_path = os.path.abspath(__file__)
denoise_jb = sprod_path.replace('test_examples.py', 'sprod.py')
input_path = sprod_path.replace('test_examples.py', 'test_example/input')
test_path = sprod_path.replace('test_examples.py', 'test_example/test_output')
output_path = sprod_path.replace('test_examples.py', 'test_example/expected_output')
sprod_path = sprod_path + '/sprod'
print('Removing previous testing results...', end='')
os.system('rm -rf {}/*'.format(test_path))
print('Done!')
print('Testing Sprod in single mode')
os.system(
'python {} {} {}/single_with_img'.format(denoise_jb, input_path, test_path))
try:
test_denoised = pd.read_csv(
os.path.join(test_path,'single_with_img/sprod_Denoised_matrix.txt'),
sep='\t')
ref_denoised = pd.read_csv(
os.path.join(output_path,'single_with_img/sprod_Denoised_matrix.txt'),
sep='\t')
if (test_denoised - ref_denoised).sum().sum() <= 100:
print('Sprod test single mode succeeded!')
else:
print('Sprod test single mode was able to run, but the results were not expected. Please check if the input files match those in the repo.')
except FileNotFoundError:
print('Sprod denoise job failed: no output found, please check sprod_log.txt.')
print('Testing Sprod in patches mode')
os.system(
'python {} -y patches -pn 2 -pb 2 {} {}/batch_with_img'.format(denoise_jb, input_path, test_path))
try:
test_denoised = pd.read_hdf(os.path.join(test_path,'batch_with_img/denoised_stiched.hdf'))
ref_denoised = pd.read_hdf(os.path.join(output_path,'batch_with_img/denoised_stiched.hdf'))
if (test_denoised - ref_denoised).sum().sum() <= 100:
print('Sprod test patches mode succeeded!')
else:
print('Sprod test patches mode was able to run, but the results were not expected. Please check if the input files match those in the repo.')
except FileNotFoundError:
print('Sprod denoise job failed: no output found, please check sprod_log.txt.')
print('Testing Sprod in single, pseudoimage mode')
tif_fn =os.path.join(input_path, 'image.tif')
os.rename(tif_fn, tif_fn.replace('.tif',''))
try:
os.system(
'python {} {} {}/single_pseudoimage'.format(denoise_jb, input_path, test_path))
os.rename(tif_fn.replace('.tif',''), tif_fn)
except:
os.rename(tif_fn.replace('.tif',''), tif_fn)
try:
test_denoised = pd.read_csv(
os.path.join(test_path,'single_pseudoimage/sprod_Denoised_matrix.txt'),
sep='\t')
ref_denoised = pd.read_csv(
os.path.join(output_path,'single_pseudoimage/sprod_Denoised_matrix.txt'),
sep='\t')
if (test_denoised - ref_denoised).sum().sum() <= 100:
print('Sprod test single pseudoimage mode succeeded!')
else:
print('Sprod test single pseudoimage mode was able to run, but the results were not expected. Please check if the input files match those in the repo.')
except FileNotFoundError:
print('Sprod denoise job failed: no output found, please check sprod_log.txt.')
# clean up intermediate files in the input folder.
os.system('rm -rf {}/*features.csv'.format(input_path))