1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23  """Module containing functions for specifying the experimental details.""" 
 24   
 25   
 26  from data_store.exp_info import ExpInfo 
 27  from info import Info_box 
 28  from lib.errors import RelaxError 
 29  from lib.io import open_read_file 
 30  from pipe_control.pipes import check_pipe 
 31  from version import version_full 
 32   
 33   
 35      """Software storage container.""" 
 36   
 38          """Initialise all variables.""" 
 39   
 40          self.name = None 
 41          self.authors = None 
 42          self.url = None 
 43          self.tasks = None 
   44   
 45   
 46   
 47  SOFTWARE = {} 
 48   
 49   
 50  SOFTWARE['relax'] = Software_store() 
 51  SOFTWARE['relax'].name = "relax" 
 52  SOFTWARE['relax'].authors = "The relax development team" 
 53  SOFTWARE['relax'].url = "http://www.nmr-relax.com" 
 54  SOFTWARE['relax'].tasks = ["data processing"] 
 55   
 56   
 57  SOFTWARE['NMRPipe'] = Software_store() 
 58  SOFTWARE['NMRPipe'].name = "NMRPipe" 
 59  SOFTWARE['NMRPipe'].authors = "Delaglio, F., Grzesiek, S., Vuister, G. W., Zhu, G., Pfeifer, J., and Bax, A" 
 60  SOFTWARE['NMRPipe'].url = "http://spin.niddk.nih.gov/NMRPipe/" 
 61  SOFTWARE['NMRPipe'].tasks = ["processing"] 
 62   
 63   
 64  SOFTWARE['Sparky'] = Software_store() 
 65  SOFTWARE['Sparky'].name = "Sparky" 
 66  SOFTWARE['Sparky'].authors = "Goddard, T. D. and Kneller, D. G." 
 67  SOFTWARE['Sparky'].ref = "Goddard, T. D. and Kneller, D. G., SPARKY 3, University of California, San Francisco." 
 68  SOFTWARE['Sparky'].url = "http://www.cgl.ucsf.edu/home/sparky/" 
 69  SOFTWARE['Sparky'].tasks = ["spectral analysis"] 
 70   
 71   
 72  SOFTWARE['DC'] = Software_store() 
 73  SOFTWARE['DC'].name = "Bruker Dynamics Center" 
 74  SOFTWARE['DC'].authors = "Bruker BioSpin GmbH" 
 75  SOFTWARE['DC'].url = "http://www.bruker-biospin.com/software_nmr.html" 
 76  SOFTWARE['DC'].tasks = ["relaxation analysis"] 
 77   
 78   
 80      """Generate the Citations saveframe records. 
 81   
 82      @param star:        The NMR-STAR dictionary object. 
 83      @type star:         NMR_STAR instance 
 84      """ 
 85   
 86       
 87      check_pipe() 
 88   
 89       
 90      if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'citations'): 
 91          for citations in cdp.exp_info.citations: 
 92               
 93              author_given_name = [] 
 94              author_family_name = [] 
 95              author_first_init = [] 
 96              author_mid_init = [] 
 97              author_family_title = [] 
 98              for i in range(len(citations.authors)): 
 99                  author_given_name.append(citations.authors[i][0]) 
100                  author_family_name.append(citations.authors[i][1]) 
101                  author_first_init.append(citations.authors[i][2]) 
102                  author_mid_init.append(citations.authors[i][3]) 
103                  author_family_title.append(None) 
104   
105               
106              star.citations.add(citation_label=citations.cite_id, author_given_name=author_given_name, author_family_name=author_family_name, author_first_init=author_first_init, author_mid_init=author_mid_init, author_family_title=author_family_title, doi=citations.doi, pubmed_id=citations.pubmed_id, full_citation=citations.full_citation, title=citations.title, status=citations.status, type=citations.type, journal_abbrev=citations.journal_abbrev, journal_full=citations.journal_full, volume=citations.volume, issue=citations.issue, page_first=citations.page_first, page_last=citations.page_last, year=citations.year) 
 107   
108   
110      """Generate the Software saveframe records. 
111   
112      @param star:        The NMR-STAR dictionary object. 
113      @type star:         NMR_STAR instance 
114      @return:            A list BMRB software IDs and a list of software labels. 
115      @rtype:             tuple of list of int and list of str 
116      """ 
117   
118       
119      check_pipe() 
120   
121       
122      if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'scripts'): 
123          for script in cdp.exp_info.scripts: 
124               
125              cite_id_nums = [] 
126              if script.cite_ids: 
127                  for cite in script.cite_ids: 
128                      cite_id_nums.append(cdp.exp_info.get_cite_id_num(cite)) 
129   
130               
131              name = script.file + " relax script" 
132   
133               
134              star.method.add(name=name, details=None, cite_ids=cite_id_nums, file_name=script.file, file_text=script.text) 
 135   
136   
138      """Generate the Software saveframe records. 
139   
140      @param star:        The NMR-STAR dictionary object. 
141      @type star:         NMR_STAR instance 
142      @return:            A list BMRB software IDs and a list of software labels. 
143      @rtype:             tuple of list of int and list of str 
144      """ 
145   
146       
147      check_pipe() 
148   
149       
150      software_ids = [] 
151      software_labels = [] 
152      if hasattr(cdp, 'exp_info') and hasattr(cdp.exp_info, 'software'): 
153          for software in cdp.exp_info.software: 
154               
155              cite_id_nums = [] 
156              for cite in software.cite_ids: 
157                  cite_id_nums.append(cdp.exp_info.get_cite_id_num(cite)) 
158   
159               
160              id = star.software.add(name=software.software_name, version=software.version, vendor_name=software.vendor_name, vendor_eaddress=software.url, task=software.tasks, cite_ids=cite_id_nums) 
161   
162               
163              software_ids.append(id) 
164              software_labels.append(software.software_name) 
165   
166       
167      else: 
168          raise RelaxError("relax cannot be the only program used in the analysis - spectral analysis programs, etc. must also have been used.  Please use the relevant BMRB user functions to specify these.") 
169   
170       
171      return software_ids, software_labels 
 172   
173   
174 -def citation(cite_id=None, authors=None, doi=None, pubmed_id=None, full_citation=None, title=None, status=None, type=None, journal_abbrev=None, journal_full=None, volume=None, issue=None, page_first=None, page_last=None, year=None): 
 175      """Store a citation. 
176   
177      @keyword cite_id:           The citation ID string. 
178      @type cite_id:              str 
179      @keyword authors:           The list of authors.  Each author element is a list of four elements: the first name, last name, first initial, and middle initials. 
180      @type authors:              list of lists of str 
181      @keyword doi:               The DOI number, e.g. "10.1000/182". 
182      @type doi:                  None or str 
183      @keyword pubmed_id:         The identification code assigned to the publication by PubMed. 
184      @type pubmed_id:            None or int 
185      @keyword full_citation:     A full citation in a format similar to that used in a journal article by either cutting and pasting from another document or by typing. Please include author names, title, journal, page numbers, and year or equivalent information for the type of publication given. 
186      @type full_citation:        str 
187      @keyword title:             The title of the publication. 
188      @type title:                str 
189      @keyword status:            The publication status.  Can be one of in "preparation", "in press", "published", "retracted", or "submitted". 
190      @type status:               str 
191      @keyword type:              The publication type.  Can be one of "abstract", "BMRB only", "book", "book chapter", "internet", "journal", "personal communication", or "thesis". 
192      @type type:                 str 
193      @keyword journal_abbrev:    A standard journal abbreviation as defined by the Chemical Abstract Services for the journal where the data are or will be published.  If the data in the deposition are related to a J. Biomol. NMR paper, the value must be 'J. Biomol. NMR' to alert the BMRB annotators so that the deposition is properly processed.  If the depositor truly does not know the journal, a value of 'not known' or 'na' is acceptable. 
194      @type journal_abbrev:       str 
195      @keyword journal_full:      The full journal name. 
196      @type journal_full:         str 
197      @keyword volume:            The volume number. 
198      @type volume:               int 
199      @keyword issue:             The issue number. 
200      @type issue:                int 
201      @keyword page_first:        The first page number. 
202      @type page_first:           int 
203      @keyword page_last:         The last page number. 
204      @type page_last:            int 
205      @keyword year:              The publication year. 
206      @type year:                 int 
207      """ 
208   
209       
210      check_pipe() 
211   
212       
213      if not hasattr(cdp, 'exp_info'): 
214          cdp.exp_info = ExpInfo() 
215   
216       
217      cdp.exp_info.add_citation(cite_id=cite_id, authors=authors, doi=doi, pubmed_id=pubmed_id, full_citation=full_citation, title=title, status=status, type=type, journal_abbrev=journal_abbrev, journal_full=journal_full, volume=volume, issue=issue, page_first=page_first, page_last=page_last, year=year) 
 218   
219   
220 -def script(file=None, dir=None, analysis_type=None, model_selection=None, engine=None, model_elim=False, universal_solution=False): 
 221      """Specify the scripts used in the analysis. 
222   
223      @keyword file:                  The name of the file to open. 
224      @type file:                     str 
225      @keyword dir:                   The directory containing the file (defaults to the current directory if None). 
226      @type dir:                      None or str 
227      @keyword analysis_type:         The type of analysis performed. 
228      @type analysis_type:            str 
229      @keyword model_selection:       The model selection technique used, if relevant. 
230      @type model_selection:          None or str 
231      @keyword engine:                The software engine used in the analysis. 
232      @type engine:                   str 
233      @keyword model_elim:            A model-free specific flag specifying if model elimination was performed. 
234      @type model_elim:               bool 
235      @keyword universal_solution:    A model-free specific flag specifying if the universal solution was sought after. 
236      @type universal_solution:       bool 
237      """ 
238   
239       
240      check_pipe() 
241   
242       
243      allowed = ['frame order', 
244                 'jw', 
245                 'mf', 
246                 'N-state', 
247                 'noe', 
248                 'relax_fit' 
249      ] 
250      if analysis_type not in allowed: 
251          raise RelaxError("The analysis type '%s' should be one of %s." % (analysis_type, allowed)) 
252   
253       
254      if not hasattr(cdp, 'exp_info'): 
255          cdp.exp_info = ExpInfo() 
256   
257       
258      f = open_read_file(file, dir) 
259      text = f.read() 
260      f.close() 
261   
262       
263      cite_id = [] 
264      cite_key = [] 
265   
266       
267      if model_selection in ['AIC', 'AICc', 'BIC', 'Bootstrap', 'CV', 'Expect', 'Overall']: 
268          cite_id.append('model-free model selection') 
269          cite_key.append('dAuvergneGooley03') 
270   
271       
272      if model_elim: 
273          cite_id.append('model-free model elimination') 
274          cite_key.append('dAuvergneGooley06') 
275   
276       
277      if universal_solution: 
278          cite_id.append('model-free set theory') 
279          cite_key.append('dAuvergneGooley07') 
280   
281       
282      info = Info_box() 
283   
284       
285      for id, key in zip(cite_id, cite_key): 
286           
287          bib = info.bib[key] 
288   
289           
290          cdp.exp_info.add_citation(cite_id=id, authors=bib.author2, doi=bib.doi, pubmed_id=bib.pubmed_id, full_citation=bib.cite_short(doi=False, url=False), title=bib.title, status=bib.status, type=bib.type, journal_abbrev=bib.journal, journal_full=bib.journal_full, volume=bib.volume, page_first=bib.page_first, page_last=bib.page_last, year=bib.year) 
291   
292       
293      cdp.exp_info.setup_script(file=file, dir=dir, text=text, cite_ids=cite_id, analysis_type=analysis_type, model_selection=model_selection, engine=engine, model_elim=model_elim, universal_solution=universal_solution) 
 294   
295   
296 -def software(name=None, version=None, url=None, vendor_name=None, cite_ids=None, tasks=None): 
 297      """Select by name the software used in the analysis. 
298   
299      @param name:            The name of the software program. 
300      @type name:             str 
301      @keyword version:       The program version. 
302      @type version:          None or str 
303      @keyword url:           The program's URL. 
304      @type url:              None or str 
305      @keyword vendor_name:   The name of the company or person behind the program. 
306      @type vendor_name:      str 
307      @keyword cite_ids:      The citation ID numbers. 
308      @type cite_ids:         None or str 
309      @keyword tasks:         The tasks performed by the program. 
310      @type tasks:            list of str 
311      """ 
312   
313       
314      check_pipe() 
315   
316       
317      if not hasattr(cdp, 'exp_info'): 
318          cdp.exp_info = ExpInfo() 
319   
320       
321      cdp.exp_info.software_setup(name=name, version=version, url=url, vendor_name=vendor_name, cite_ids=cite_ids, tasks=tasks) 
 322   
323   
325      """Select by name the software used in the analysis. 
326   
327      @param name:        The name of the software program. 
328      @type name:         str 
329      @keyword version:   The program version. 
330      @type version:      None or str 
331      """ 
332   
333       
334      check_pipe() 
335   
336       
337      if name not in ['relax', 'NMRPipe', 'Sparky', 'Bruker DC']: 
338          raise RelaxError("The software '%s' is unknown.  Please use the user function for manually specifying software details instead." % name) 
339   
340       
341      if not hasattr(cdp, 'exp_info'): 
342          cdp.exp_info = ExpInfo() 
343   
344       
345      cite_ids = [] 
346      keys = [] 
347      software_keys = [] 
348      versions = [] 
349   
350       
351      if name == 'relax': 
352           
353          cite_ids.append(['relax_ref1', 'relax_ref2']) 
354          keys.append(['dAuvergneGooley08a', 'dAuvergneGooley08b']) 
355          software_keys.append('relax') 
356          versions.append(version_full()) 
357   
358       
359      elif name == 'NMRPipe': 
360           
361          cite_ids.append(['nmrpipe_ref']) 
362          keys.append(['Delaglio95']) 
363          software_keys.append('NMRPipe') 
364          versions.append(version) 
365   
366       
367      elif name == 'Sparky': 
368           
369          if not version: 
370              raise RelaxError("The Sparky version number has not been supplied.") 
371   
372           
373          cite_ids.append(['sparky_ref']) 
374          keys.append(['GoddardKneller']) 
375          software_keys.append('Sparky') 
376          versions.append(version) 
377   
378       
379      elif name == 'Bruker DC': 
380           
381          software_keys.append('DC') 
382          versions.append(version) 
383   
384       
385      info = Info_box() 
386   
387       
388      for i in range(len(cite_ids)): 
389          for j in range(len(cite_ids[i])): 
390               
391              bib = info.bib[keys[i][j]] 
392   
393               
394              cdp.exp_info.add_citation(cite_id=cite_ids[i][j], authors=bib.author2, doi=bib.doi, pubmed_id=bib.pubmed_id, full_citation=bib.cite_short(doi=False, url=False), title=bib.title, status=bib.status, type=bib.type, journal_abbrev=bib.journal, journal_full=bib.journal_full, volume=bib.volume, issue=bib.number, page_first=bib.page_first, page_last=bib.page_last, year=bib.year) 
395   
396           
397          cdp.exp_info.software_setup(name=SOFTWARE[software_keys[i]].name, version=versions[i], vendor_name=SOFTWARE[software_keys[i]].authors, url=SOFTWARE[software_keys[i]].url, cite_ids=cite_ids, tasks=SOFTWARE[software_keys[i]].tasks) 
 398   
399   
401      """Set the thiol state of the system. 
402   
403      @keyword state:         The thiol state of the molecule. 
404      @type state:            str 
405      """ 
406   
407       
408      check_pipe() 
409   
410       
411      if not hasattr(cdp, 'exp_info'): 
412          cdp.exp_info = ExpInfo() 
413   
414       
415      cdp.exp_info.setup_thiol(state=state) 
 416