comparison proteomics.py @ 18:d1ea609e57d4 draft

Make splib a composite datatype
author iracooke
date Wed, 20 May 2015 01:39:39 -0400
parents 29c43b953c1c
children e5551a35e508
comparison
equal deleted inserted replaced
17:29c43b953c1c 18:d1ea609e57d4
287 287
288 288
289 class SPLib( Msp ): 289 class SPLib( Msp ):
290 """SpectraST Spectral Library. Closely related to msp format""" 290 """SpectraST Spectral Library. Closely related to msp format"""
291 file_ext = "splib" 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
292 321
293 def set_peek( self, dataset, is_multi_byte=False ): 322 def set_peek( self, dataset, is_multi_byte=False ):
294 """Set the peek and blurb text""" 323 """Set the peek and blurb text"""
295 if not dataset.dataset.purged: 324 if not dataset.dataset.purged:
296 dataset.peek = data.get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte ) 325 dataset.peek = data.get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte )
303 def sniff(self, filename): 332 def sniff(self, filename):
304 """ Determines whether the file is a SpectraST generated file. 333 """ Determines whether the file is a SpectraST generated file.
305 """ 334 """
306 with open(filename, 'r') as contents: 335 with open(filename, 'r') as contents:
307 return Msp.next_line_starts_with(contents, "Name:") and Msp.next_line_starts_with(contents, "LibID:") 336 return Msp.next_line_starts_with(contents, "Name:") and Msp.next_line_starts_with(contents, "LibID:")
308
309 337
310 338
311 class Ms2(Text): 339 class Ms2(Text):
312 file_ext = "ms2" 340 file_ext = "ms2"
313 341