annotate nist_wrapper.py @ 20:3abd271b4626 default tip

killing nist at exception
author pieter.lukasse@wur.nl
date Fri, 23 Jan 2015 17:57:00 +0100
parents a394029414c6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
1 #!/usr/bin/env python
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
2 # encoding: utf-8
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
3 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
4 Module wrapping the NIST MSSEARCH application for matching
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
5 spectra one or more spectra libraries.
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
6 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
7 import csv
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
8 import sys
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
9 import fileinput
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
10 import urllib2
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
11 import time
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
12 import utils
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
13 import uuid
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
14 import os
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
15 import subprocess
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
16 from report_generator import ReportGenerator
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
17
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
18 __author__ = "Pieter Lukasse"
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
19 __contact__ = "pieterlukasse@gmail.com,pieter.lukasse@wur.nl"
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
20 __copyright__ = "Copyright, 2015"
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
21 __license__ = "Apache v2"
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
22
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
23
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
24
7
165c22633081 adding log
pieter.lukasse@wur.nl
parents: 6
diff changeset
25 def _prepare_NIST(uuid_value, nist_home_dir, nist_ini_file, spectrum_file, is_wine, log_file):
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
26 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
27 executes the following steps:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
28 - copy nist_home_dir folder to nist_home_dir+_uuid
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
29 - copy spectrum_file.msp to ~/.wine/drive_c/NIST_uid
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
30 - creates nist_home_dir+_uuid/MSSEARCH/AUTOIMP.MSD -> pointing to C:\NIST_uid\MSSEARCH\temp.msd (in case of is_wine) or to nist_home_dir+_uuidM\SSEARCH\temp.msd
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
31 - creates nist_home_dir+_uuid/MSSEARCH/temp.msd -> pointing to C:\NIST_uid\spectrum_file.msp (in case of is_wine) or to nist_home_dir+_uuid\spectrum_file.msp
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
32 and the text "10 724" in the second row
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
33 - copy nistms.INI to nist_home_dir+_uuid/MSSEARCH , overwriting the existing one
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
34 - in case of is_wine:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
35 replace all occurrences of C:\NIST with C:\NIST_uid in this new nistms.INI
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
36 else:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
37 replace all occurrences of C:\NIST with nist_home_dir+_uuid in this new nistms.INI
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
38 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
39 if nist_home_dir.endswith("/") or nist_home_dir.endswith("\\"):
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
40 nist_home_dir = nist_home_dir[:-1]
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
41
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
42 # small validation for wine scenario
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
43 if is_wine and not nist_home_dir.endswith("drive_c/NIST"):
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
44 raise Exception('Error: invalid NIST home. For wine usage NIST home dir must be in the .wine folder and then in drive_c/NIST')
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
45
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
46 new_nist_home = nist_home_dir+uuid_value
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
47 utils.copy_dir(nist_home_dir, new_nist_home)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
48
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
49 utils.copy_file(spectrum_file, new_nist_home+"/spectrum_file.msp")
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
50
9
8c20185752da better logging
pieter.lukasse@wur.nl
parents: 8
diff changeset
51 utils.log_message(log_file, "configuring NIST input...")
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
52 # remove old file:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
53 os.remove(new_nist_home+"/MSSEARCH/AUTOIMP.MSD")
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
54 with open(new_nist_home + "/MSSEARCH/AUTOIMP.MSD", "a") as text_file:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
55 if is_wine:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
56 text_file.write("C:\\NIST" + uuid_value + "\\MSSEARCH\\temp.msd")
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
57 else:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
58 text_file.write(new_nist_home + "\\MSSEARCH\\temp.msd")
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
59
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
60 with open(new_nist_home + "/MSSEARCH/temp.msd", "a") as text_file:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
61 if is_wine:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
62 text_file.write("C:\\NIST" + uuid_value + "\\spectrum_file.msp\n")
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
63 else:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
64 text_file.write(new_nist_home + "\\spectrum_file.msp\n")
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
65 text_file.write("10 724")
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
66
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
67 replacement_text = new_nist_home
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
68 if is_wine:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
69 replacement_text = "C:\\NIST" + uuid_value
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
70
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
71 # remove old file
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
72 os.remove(new_nist_home+"/MSSEARCH/nistms.INI")
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
73 # make new one
9
8c20185752da better logging
pieter.lukasse@wur.nl
parents: 8
diff changeset
74 utils.log_message(log_file, "configuring NIST ini...")
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
75 o = open(new_nist_home+"/MSSEARCH/nistms.INI","a") #open for append
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
76 # TODO : this loop/replace below is a bit limited to specific variables...either test different NIST versions or make more generic (harder in case of wine, or we need extra "home in .INI file" parameter):
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
77 for line in open(nist_ini_file):
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
78 if "Library Directory=" in line:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
79 line = "Library Directory="+ new_nist_home + "\\MSSEARCH\\\n"
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
80 if "Dir=" in line:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
81 line = "Dir="+ replacement_text + "\\MSSEARCH\\\n"
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
82
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
83 o.write(line)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
84 o.close()
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
85
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
86 return new_nist_home
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
87
16
c21e96bb68c8 added clean-up after execution
pieter.lukasse@wur.nl
parents: 14
diff changeset
88 def _clean_up_NIST(new_nist_home):
c21e96bb68c8 added clean-up after execution
pieter.lukasse@wur.nl
parents: 14
diff changeset
89 '''
c21e96bb68c8 added clean-up after execution
pieter.lukasse@wur.nl
parents: 14
diff changeset
90 remove folder
c21e96bb68c8 added clean-up after execution
pieter.lukasse@wur.nl
parents: 14
diff changeset
91 '''
c21e96bb68c8 added clean-up after execution
pieter.lukasse@wur.nl
parents: 14
diff changeset
92 utils.remove_dir(new_nist_home)
c21e96bb68c8 added clean-up after execution
pieter.lukasse@wur.nl
parents: 14
diff changeset
93
14
92cf554fca03 minor changes/improvements
pieter.lukasse@wur.nl
parents: 12
diff changeset
94 def _run_NIST(new_nist_home, output_file, is_wine, log_file, job_size):
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
95 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
96 - run : (wine) new_nist_home/MSSEARCH/nistms$.exe /INSTRUMENT /PAR=2
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
97 - monitor : new_nist_home/MSSEARCH/SRCREADY.TXT for content = "1"
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
98 - when ready:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
99 > copy SRCRESLT.TXT to output_file
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
100 > kill nist process
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
101 > (optional)remove ~/.wine/drive_c/NIST_uid/
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
102 > finish
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
103 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
104 # to avoid conflicts in the orphan process killing (see end of this method), we will
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
105 # only run NIST again after previous nistms.exe process has been killed:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
106 # TODO : solution is currently only for wine (in the windows context the solution is not there yet, but parallel calls are not expected as in windows we only run tests one by one for now)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
107
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
108
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
109 # remove old file, if it is there:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
110 file_to_monitor = new_nist_home+"/MSSEARCH/SRCREADY.TXT"
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
111 if os.path.exists(file_to_monitor):
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
112 os.remove(file_to_monitor)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
113
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
114 exec_path = new_nist_home + "/MSSEARCH/nistms$.exe"
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
115
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
116 pro = ""
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
117 if is_wine:
9
8c20185752da better logging
pieter.lukasse@wur.nl
parents: 8
diff changeset
118 utils.log_message(log_file, "calling wine with " + exec_path)
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
119 cmd = ["wine "+ exec_path + " /INSTRUMENT /PAR=2"]
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
120 # The os.setsid() is passed in the argument preexec_fn so
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
121 # it's run after the fork() and before exec() to run the shell.
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
122 pro = subprocess.Popen(cmd, stdout=subprocess.PIPE,
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
123 shell=True, preexec_fn=os.setsid)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
124 else:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
125 cmd = [
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
126 exec_path,
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
127 "/INSTRUMENT",
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
128 "/PAR=2"]
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
129 subprocess.call(cmd)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
130
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
131
5
pieter.lukasse@wur.nl
parents: 0
diff changeset
132 timeSleeping = 0
18
dae90b9abf61 increased timeout
pieter.lukasse@wur.nl
parents: 17
diff changeset
133 startUpTime = 60
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
134 # monitor process by checking state file:
9
8c20185752da better logging
pieter.lukasse@wur.nl
parents: 8
diff changeset
135 utils.log_message(log_file, "monitoring SRCREADY.TXT...")
14
92cf554fca03 minor changes/improvements
pieter.lukasse@wur.nl
parents: 12
diff changeset
136 while True:
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
137 # check if SRCREADY.TXT is there already:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
138 if os.path.exists(file_to_monitor):
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
139 break
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
140 time.sleep(2)
10
pieter.lukasse@wur.nl
parents: 9
diff changeset
141 timeSleeping = timeSleeping+2
14
92cf554fca03 minor changes/improvements
pieter.lukasse@wur.nl
parents: 12
diff changeset
142 if timeSleeping > (startUpTime + job_size*2):
92cf554fca03 minor changes/improvements
pieter.lukasse@wur.nl
parents: 12
diff changeset
143 # abort with timeout:
17
82368bd06e1d small improvements
pieter.lukasse@wur.nl
parents: 16
diff changeset
144 utils.log_message(log_file, "No results after " + str(timeSleeping) + " seconds...")
20
3abd271b4626 killing nist at exception
pieter.lukasse@wur.nl
parents: 19
diff changeset
145 _kill_NIST(pro, is_wine)
19
pieter.lukasse@wur.nl
parents: 18
diff changeset
146 # uggly workaround:
pieter.lukasse@wur.nl
parents: 18
diff changeset
147 utils.kill_process_by_name("nistms.exe")
pieter.lukasse@wur.nl
parents: 18
diff changeset
148 utils.kill_process_by_name("nistms$.exe")
14
92cf554fca03 minor changes/improvements
pieter.lukasse@wur.nl
parents: 12
diff changeset
149 raise Exception('Error: timeout waiting for NIST results.')
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
150
17
82368bd06e1d small improvements
pieter.lukasse@wur.nl
parents: 16
diff changeset
151 utils.log_message(log_file, "done...")
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
152 # kill process:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
153 #p.terminate() - not needed, nistm$ will terminate...nistms.exe is the one that
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
154 #stays open...and orphan..killing it:
20
3abd271b4626 killing nist at exception
pieter.lukasse@wur.nl
parents: 19
diff changeset
155 _kill_NIST(pro, is_wine)
3abd271b4626 killing nist at exception
pieter.lukasse@wur.nl
parents: 19
diff changeset
156
3abd271b4626 killing nist at exception
pieter.lukasse@wur.nl
parents: 19
diff changeset
157 # copy SRCRESLT.TXT to output_file
3abd271b4626 killing nist at exception
pieter.lukasse@wur.nl
parents: 19
diff changeset
158 result_file = new_nist_home+"/MSSEARCH/SRCRESLT.TXT"
3abd271b4626 killing nist at exception
pieter.lukasse@wur.nl
parents: 19
diff changeset
159 utils.copy_file(result_file, output_file)
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
160
20
3abd271b4626 killing nist at exception
pieter.lukasse@wur.nl
parents: 19
diff changeset
161
3abd271b4626 killing nist at exception
pieter.lukasse@wur.nl
parents: 19
diff changeset
162
3abd271b4626 killing nist at exception
pieter.lukasse@wur.nl
parents: 19
diff changeset
163 def _kill_NIST(process_group, is_wine):
3abd271b4626 killing nist at exception
pieter.lukasse@wur.nl
parents: 19
diff changeset
164 '''
3abd271b4626 killing nist at exception
pieter.lukasse@wur.nl
parents: 19
diff changeset
165 nistm$ will terminate...nistms.exe is the one that
3abd271b4626 killing nist at exception
pieter.lukasse@wur.nl
parents: 19
diff changeset
166 stays open...and orphan. This method kills it.
3abd271b4626 killing nist at exception
pieter.lukasse@wur.nl
parents: 19
diff changeset
167 '''
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
168 if is_wine:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
169 # pid = utils.get_process_pid("nistms.exe")
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
170 # os.kill(pid, 9)
20
3abd271b4626 killing nist at exception
pieter.lukasse@wur.nl
parents: 19
diff changeset
171 os.killpg(process_group.pid, 9)
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
172 else:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
173 # windows case:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
174 proc_name = "nistms.exe"
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
175 os.system("taskkill /f /im " + proc_name)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
176
20
3abd271b4626 killing nist at exception
pieter.lukasse@wur.nl
parents: 19
diff changeset
177
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
178
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
179
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
180 def _create_html_report(output_html_report, output_html_report_files_path, hits_dict, spectra_dict):
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
181 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
182 This report will contain a page that displays essentially the same list as found in the
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
183 tabular output file (rendered with datatables jquery plugin), with some extra features:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
184 - when user clicks on an entry, it should display the query spectrum and the hit spectrum
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
185 in "head to tail" and "difference" mode (see galaxy/report_example.png)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
186 -> the query spectrum can be generated from the data in the input MSP file
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
187 -> the library "online representative" spectrum can be generated from data returned by http://webbook.nist.gov/cgi/cbook.cgi?JCAMP=C537268&Index=0&Type=Mass ,
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
188 where C537268 in this case is the CAS ID without the '-' separators
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
189 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
190 # step 1 : generate HTML via the jinja template engine
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
191 # step 1.1: make sure to link the query spectrum data to the corresponding html object for quick rendering when needed
14
92cf554fca03 minor changes/improvements
pieter.lukasse@wur.nl
parents: 12
diff changeset
192
92cf554fca03 minor changes/improvements
pieter.lukasse@wur.nl
parents: 12
diff changeset
193 # copy necessary .js files as well:
92cf554fca03 minor changes/improvements
pieter.lukasse@wur.nl
parents: 12
diff changeset
194 templates_folder = os.path.dirname(__file__) + '/templates/'
92cf554fca03 minor changes/improvements
pieter.lukasse@wur.nl
parents: 12
diff changeset
195 utils.copy_dir(templates_folder, output_html_report_files_path)
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
196
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
197 html_file = open(output_html_report,'w')
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
198 html_render = ReportGenerator(os.path.dirname(__file__), 'templates/main_template.html',hits_dict, spectra_dict)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
199 html_render.render(html_file)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
200
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
201 html_file.close()
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
202
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
203
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
204
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
205
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
206
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
207 return None
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
208
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
209 def _get_extra_info_and_link_cols(data_found, data_type_found, query_link):
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
210 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
211 This method will go over the data found and will return a
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
212 list with the following items:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
213 - Experiment details where hits have been found :
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
214 'organism', 'tissue','experiment_name','user_name','column_type'
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
215 - Link that executes same query
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
216
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
217 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
218 # set() makes a unique list:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
219 organism_set = []
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
220 tissue_set = []
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
221 experiment_name_set = []
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
222 user_name_set = []
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
223 column_type_set = []
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
224 cas_nr_set = []
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
225
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
226 if 'organism' in data_found:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
227 organism_set = set(data_found['organism'])
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
228 if 'tissue' in data_found:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
229 tissue_set = set(data_found['tissue'])
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
230 if 'experiment_name' in data_found:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
231 experiment_name_set = set(data_found['experiment_name'])
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
232 if 'user_name' in data_found:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
233 user_name_set = set(data_found['user_name'])
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
234 if 'column_type' in data_found:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
235 column_type_set = set(data_found['column_type'])
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
236 if 'CAS' in data_found:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
237 cas_nr_set = set(data_found['CAS'])
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
238
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
239
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
240 result = [data_type_found,
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
241
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
242 #To let Excel interpret as link, use e.g. =HYPERLINK("http://stackoverflow.com", "friendly name"):
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
243 "=HYPERLINK(\""+ query_link + "\", \"Link to entries found in DB \")"]
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
244 return result
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
245
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
246
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
247
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
248
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
249
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
250 # alternative: ?
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
251 # s = requests.Session()
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
252 # s.verify = False
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
253 # #s.auth = (token01, token02)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
254 # resp = s.get(url, params={'name': 'anonymous'}, stream=True)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
255 # content = resp.content
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
256 # # transform to dictionary:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
257
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
258
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
259
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
260 def _save_data(data_rows, headers, out_csv):
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
261 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
262 Writes tab-separated data to file
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
263 @param data_rows: dictionary containing merged/enriched dataset
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
264 @param out_csv: output csv file
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
265 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
266
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
267 # Open output file for writing
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
268 outfile_single_handle = open(out_csv, 'wb')
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
269 output_single_handle = csv.writer(outfile_single_handle, delimiter="\t")
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
270
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
271 # Write headers
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
272 output_single_handle.writerow(headers)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
273
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
274 # Write one line for each row
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
275 for data_row in data_rows:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
276 output_single_handle.writerow(data_row)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
277
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
278 def _get_metexp_URL(metexp_dblink_file):
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
279 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
280 Read out and return the URL stored in the given file.
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
281 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
282 file_input = fileinput.input(metexp_dblink_file)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
283 try:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
284 for line in file_input:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
285 if line[0] != '#':
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
286 # just return the first line that is not a comment line:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
287 return line
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
288 finally:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
289 file_input.close()
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
290
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
291
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
292 def main():
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
293 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
294 Wrapper main function
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
295
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
296 The input expected is:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
297 NIST_HOME dir
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
298 nistms.INI
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
299 spectrum_file.msp
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
300 outputfileName
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
301 (optional) htmlReportFile
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
302 (optional) htmlReportFile.files_path
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
303 '''
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
304 seconds_start = int(round(time.time()))
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
305
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
306 nist_home_dir = sys.argv[1]
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
307 nist_ini_file = sys.argv[2]
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
308 spectrum_file = sys.argv[3]
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
309 nist_output_file = sys.argv[4]
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
310 final_output_file = sys.argv[5]
7
165c22633081 adding log
pieter.lukasse@wur.nl
parents: 6
diff changeset
311 output_log_file = sys.argv[6]
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
312 # html report pars:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
313 output_html_report = None
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
314 output_html_report_files_path = None
7
165c22633081 adding log
pieter.lukasse@wur.nl
parents: 6
diff changeset
315 if len(sys.argv) > 7:
165c22633081 adding log
pieter.lukasse@wur.nl
parents: 6
diff changeset
316 output_html_report = sys.argv[7]
165c22633081 adding log
pieter.lukasse@wur.nl
parents: 6
diff changeset
317 output_html_report_files_path = sys.argv[8]
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
318
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
319 is_wine = False
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
320 if "wine" in nist_home_dir:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
321 is_wine = True
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
322
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
323 uuid_value = str(uuid.uuid4())
9
8c20185752da better logging
pieter.lukasse@wur.nl
parents: 8
diff changeset
324
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
325 # prepare NIST environment for running:
9
8c20185752da better logging
pieter.lukasse@wur.nl
parents: 8
diff changeset
326 new_nist_home = _prepare_NIST(uuid_value, nist_home_dir, nist_ini_file, spectrum_file, is_wine, output_log_file)
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
327
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
328 # run NIST search command:
14
92cf554fca03 minor changes/improvements
pieter.lukasse@wur.nl
parents: 12
diff changeset
329 spectra_dict = utils.get_spectra_file_as_dict(spectrum_file)
92cf554fca03 minor changes/improvements
pieter.lukasse@wur.nl
parents: 12
diff changeset
330 job_size = len(spectra_dict)
92cf554fca03 minor changes/improvements
pieter.lukasse@wur.nl
parents: 12
diff changeset
331 _run_NIST(new_nist_home, nist_output_file, is_wine, output_log_file, job_size)
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
332
16
c21e96bb68c8 added clean-up after execution
pieter.lukasse@wur.nl
parents: 14
diff changeset
333 # clean-up NIST environment:
c21e96bb68c8 added clean-up after execution
pieter.lukasse@wur.nl
parents: 14
diff changeset
334 _clean_up_NIST(new_nist_home)
c21e96bb68c8 added clean-up after execution
pieter.lukasse@wur.nl
parents: 14
diff changeset
335
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
336 # write output tabular:
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
337 hits_dict = utils.get_nist_out_as_dict(nist_output_file)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
338 utils.save_dict_as_tsv(hits_dict, final_output_file)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
339
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
340 # create report:
14
92cf554fca03 minor changes/improvements
pieter.lukasse@wur.nl
parents: 12
diff changeset
341 if len(sys.argv) > 7:
0
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
342 _create_html_report(output_html_report, output_html_report_files_path, hits_dict, spectra_dict)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
343
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
344
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
345 #_save_data(enriched_data, headers, output_result)
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
346
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
347 seconds_end = int(round(time.time()))
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
348 print "Took " + str(seconds_end - seconds_start) + " seconds"
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
349
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
350
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
351
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
352 if __name__ == '__main__':
cce6989ed423 new NIST wrapper demo tools
pieter.lukasse@wur.nl
parents:
diff changeset
353 main()