comparison proteomics.py @ 8:6ab4a0bf67df draft

Make splib a composite datatype
author iracooke
date Wed, 20 May 2015 00:26:37 -0400
parents 9cfabf0b942d
children 349af9298ff1
comparison
equal deleted inserted replaced
7:9cfabf0b942d 8:6ab4a0bf67df
282 >>> Msp().sniff(fname) 282 >>> Msp().sniff(fname)
283 False 283 False
284 """ 284 """
285 with open(filename, 'r') as contents: 285 with open(filename, 'r') as contents:
286 return Msp.next_line_starts_with(contents, "Name:") and Msp.next_line_starts_with(contents, "MW:") 286 return Msp.next_line_starts_with(contents, "Name:") and Msp.next_line_starts_with(contents, "MW:")
287
288
289 class SPLib( Msp ):
290 """SpectraST Spectral Library. Closely related to msp format"""
291 file_ext = "splib"
292 composite_type = 'auto_primary_file'
293
294 def __init__(self, **kwd):
295 Msp.__init__(self, **kwd)
296 self.add_composite_file( 'library.splib',
297 description = 'Spectral Library. Contains actual library spectra',
298 is_binary = False )
299 self.add_composite_file( 'library.spidx',
300 description = 'Spectrum index', is_binary = False )
301 self.add_composite_file( 'library.pepidx',
302 description = 'Peptide index', is_binary = False)
303
304
305 def generate_primary_file( self, dataset = None ):
306 rval = ['<html><head><title>Spectral Library Composite Dataset </title></head><p/>']
307 rval.append('<div>This composite dataset is composed of the following files:<p/><ul>')
308 for composite_name, composite_file in self.get_composite_files( dataset = dataset ).iteritems():
309 fn = composite_name
310 opt_text = ''
311 if composite_file.optional:
312 opt_text = ' (optional)'
313 if composite_file.get('description'):
314 rval.append( '<li><a href="%s" type="text/plain">%s (%s)</a>%s</li>' % ( fn, fn, composite_file.get('description'), opt_text ) )
315 else:
316 rval.append( '<li><a href="%s" type="text/plain">%s</a>%s</li>' % ( fn, fn, opt_text ) )
317 rval.append( '</ul></div></html>' )
318 return "\n".join( rval )
319
320
321
322 def set_peek( self, dataset, is_multi_byte=False ):
323 """Set the peek and blurb text"""
324 if not dataset.dataset.purged:
325 dataset.peek = data.get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte )
326 dataset.blurb = 'splib Spectral Library Format'
327 else:
328 dataset.peek = 'file does not exist'
329 dataset.blurb = 'file purged from disk'
330
331
332 def sniff(self, filename):
333 """ Determines whether the file is a SpectraST generated file.
334 """
335 with open(filename, 'r') as contents:
336 return Msp.next_line_starts_with(contents, "Name:") and Msp.next_line_starts_with(contents, "LibID:")
337
287 338
288 class Ms2(Text): 339 class Ms2(Text):
289 file_ext = "ms2" 340 file_ext = "ms2"
290 341
291 def sniff(self, filename): 342 def sniff(self, filename):