Permalink
Browse files

Removing deprecated Martel dependent module Bio.Saf

  • Loading branch information...
1 parent 02ac9db commit 56321cfcafa93302b599bdff558551d0d65c9e71 @peterjc peterjc committed Apr 27, 2009
Showing with 2 additions and 343 deletions.
  1. +0 −71 Bio/Saf/Record.py
  2. +0 −193 Bio/Saf/__init__.py
  3. +0 −77 Bio/Saf/saf_format.py
  4. +2 −2 DEPRECATED
View
@@ -1,71 +0,0 @@
-# Copyright 2001 by Katharine Lindner. All rights reserved.
-# This code is part of the Biopython distribution and governed by its
-# license. Please see the LICENSE file that should have been included
-# as part of this package.
-
-"""Martel based parser to read SAF formatted files.
-
-This is a huge regular regular expression for Saf, built using
-the 'regular expressiona on steroids' capabilities of Martel.
-
-#http://www.embl-heidelberg.de/predictprotein/Dexa/optin_safDes.html
-
-
-Notes:
-Just so I remember -- the new end of line syntax is:
- New regexp syntax - \R
- \R means "\n|\r\n?"
- [\R] means "[\n\r]"
-
-This helps us have endlines be consistent across platforms.
-
-"""
-
-from Bio.Align.Generic import Alignment
-import Bio.Alphabet
-
-
-
-"""Hold SAF data in a straightforward format.
-
-classes:
-o Record - All of the information in an Saf record.
-"""
-
-class Record:
- """Hold Saf information in a format similar to the original record.
-
- The Record class is meant to make data easy to get to when you are
- just interested in looking at Saf data.
-
- Attributes:
- alignment
-
- """
- def __init__(self):
- self.alignment = Alignment( Bio.Alphabet.generic_alphabet )
-
- def __str__( self ):
- output = ''
- sequences = self.alignment.get_all_seqs()
- for sequence_record in sequences:
- output = output + '%s\n' % sequence_record.description
- output = output + out_sequence( sequence_record.seq.data )
- return output
-
-def out_sequence( seq ):
- output = ''
- for j in range( 0, len( seq ), 80 ):
- output = output + '%s\n' % seq[ j: j + 80 ]
- output = output + '\n'
- return output
-
-
-
-
-
-
-
-
-
-
View
@@ -1,193 +0,0 @@
-# Copyright 2001 by Katharine Lindner. All rights reserved.
-# This code is part of the Biopython distribution and governed by its
-# license. Please see the LICENSE file that should have been included
-# as part of this package.
-"""Parser for SAF (Simple Alignment Format).
-
-This is a fairly liberal multiple sequence alignment format, where
-record names may contain up to 14 characters and no blanks. Lines
-beginging with a hash (#) are ignored.
-
-SAF has been described as a simplified subset of MSF, dropping the
-checksum and with more flexibility in terms of line length.
-
-A current URL describing this file format is:
-http://www.predictprotein.org/Dexa/optin_saf.html
-
-This appears to replace the old URL of:
-http://www.embl-heidelberg.de/predictprotein/Dexa/optin_safDes.html
-"""
-
-import warnings
-warnings.warn("Bio.Saf has been deprecated, due to problems with Martel"\
- +" and recent versions of mxTextTools. If you want to"\
- +" continue to use this module (or read this file format),"\
- +" please get touch to avoid permanent removal of this"\
- +" module from Biopython.", DeprecationWarning)
-
-# Martel
-import Martel
-from Martel import RecordReader
-from Martel import Dispatch
-
-
-from Bio import File
-import saf_format
-import Record
-
-
-class Iterator:
- """Iterator interface to move over a file of Saf entries one at a time.
- """
- def __init__(self, handle, parser = None):
- """Initialize the iterator.
-
- Arguments:
- o handle - A handle with Saf entries to iterate through.
- o parser - An optional parser to pass the entries through before
- returning them. If None, then the raw entry will be returned.
- """
- self.handle = File.UndoHandle( handle )
- self._reader = RecordReader.Everything( self.handle )
- self._parser = parser
-
- def next(self):
- """Return the next Saf record from the handle.
-
- Will return None if we ran out of records.
- """
- data = self._reader.next()
-
- if self._parser is not None:
- if data:
- return self._parser.parse(File.StringHandle(data))
-
- return data
-
- def __iter__(self):
- return iter(self.next, None)
-
-class _Scanner:
- """Start up Martel to do the scanning of the file.
-
- This initialzes the Martel based parser and connects it to a handler
- that will generate events for a Feature Consumer.
- """
- def __init__(self, debug = 0):
- """Initialize the scanner by setting up our caches.
-
- Creating the parser takes a long time, so we want to cache it
- to reduce parsing time.
-
- Arguments:
- o debug - The level of debugging that the parser should
- display. Level 0 is no debugging, Level 2 displays the most
- debugging info (but is much slower). See Martel documentation
- for more info on this.
- """
- # a listing of all tags we are interested in scanning for
- # in the MartelParser
- self.interest_tags = [ 'candidate_line', 'saf_record' ]
-
- # make a parser that returns only the tags we are interested in
- expression = Martel.select_names( saf_format.saf_record, self.interest_tags)
- self._parser = expression.make_parser(debug_level = debug)
-
- def feed(self, handle, consumer):
- """Feed a set of data into the scanner.
-
- Arguments:
- o handle - A handle with the information to parse.
- o consumer - The consumer that should be informed of events.
- """
- consumer.set_interest_tags( self.interest_tags )
- self._parser.setContentHandler( consumer )
-# self._parser.setErrorHandler(handle.ErrorHandler())
-
- self._parser.parseFile(handle)
-
-class _RecordConsumer( Dispatch.Dispatcher ):
- """Create a Saf Record object from scanner generated information.
- """
- def __init__(self ):
- Dispatch.Dispatcher.__init__( self )
- self.data = Record.Record()
- self._refresh()
-
- def _refresh( self ):
- self._sequences = {}
- self._names = {}
- self._history = []
- self._guide = ''
- self._ref_length = 0
- self._ordinal = 0
-
- def set_interest_tags( self, interest_tags ):
- self.interest_tags = interest_tags
-
- def startDocument(self):
- self.data = Record.Record()
- self._refresh()
-
-
- def start_candidate_line(self, name, attrs):
- self.save_characters()
-
- def end_candidate_line(self, candidate_lines ):
- candidate_line = self.get_characters()
- name = candidate_line.split( ' ' )[ 0 ]
- sequence = candidate_line[ len( name ): ]
- name = name.strip()
- sequence = sequence.replace( " ", "" )
- if( self._guide == '' ):
- self._guide = name
- self._ref_length = len( sequence )
- elif( name == self._guide ):
- history = []
- self._ref_length = len( sequence )
- try:
- self._history.index( name )
- except ValueError:
- self._names[ self._ordinal ] = name
- self._ordinal = self._ordinal + 1
- self._history.append( name )
- sequence = sequence.strip()
- try:
- sequence = self._sequences[ name ] + sequence
- except KeyError:
- pass
- self._sequences[ name ] = sequence
-
- def start_saf_record( self, sequence, attrs ):
- self._sequences = {}
-
- def end_saf_record( self, saf_record ):
- ordinals = self._names.keys()
- ordinals.sort()
- for ordinal in ordinals:
- name = self._names[ ordinal ]
- sequence = self._sequences[ name ]
- self.data.alignment.add_sequence( name, sequence )
- self._refresh()
-
-class RecordParser:
- """Parse Saf files into Record objects.
- """
- def __init__(self, debug_level = 0):
- """Initialize the parser.
-
- Arguments:
- o debug_level - An optional argument that specifies the amount of
- debugging information Martel should spit out. By default we have
- no debugging info (the fastest way to do things), but if you want
- you can set this as high as two and see exactly where a parse fails.
- """
- self._scanner = _Scanner(debug_level)
-
- def parse(self, handle):
- """Parse the specified handle into a SAF record.
- """
- self._consumer = _RecordConsumer()
- self._scanner.feed(handle, self._consumer)
- return self._consumer.data
-
View
@@ -1,77 +0,0 @@
-# Copyright 2001 by Katharine Lindner. All rights reserved.
-# This code is part of the Biopython distribution and governed by its
-# license. Please see the LICENSE file that should have been included
-# as part of this package.
-
-"""Martel based parser to read SAF formatted files.
-
-This is a huge regular regular expression for SAF, built using
-the 'regular expressiona on steroids' capabilities of Martel.
-
-http://www.embl-heidelberg.de/predictprotein/Dexa/optin_safDes.html
-
-
-Notes:
-Just so I remember -- the new end of line syntax is:
- New regexp syntax - \R
- \R means "\n|\r\n?"
- [\R] means "[\n\r]"
-
-This helps us have endlines be consistent across platforms.
-
-"""
-#http://www.embl-heidelberg.de/predictprotein/Dexa/optin_safDes.html
-
-
-# Martel
-import Martel
-from Martel import Str
-from Martel import AnyEol
-from Martel import ToEol
-from Martel import Group
-from Martel import Alt
-from Martel import Rep
-from Martel import Rep1
-from Martel import Any
-from Martel import Opt
-from Martel import ToSep
-from Martel.Expression import Assert
-
-
-
-# --- first set up some helper constants and functions
-# Copyright 2001 by Katharine Lindner. All rights reserved.
-# This code is part of the Biopython distribution and governed by its
-# license. Please see the LICENSE file that should have been included
-# as part of this package.
-
-
-digits = "0123456789"
-valid_sequence_characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-. \t'
-white_space = "\t "
-valid_residue_characters = digits + white_space + chr( 0x2e )
-residue_number_line = Group( "residue_number_line", \
- Rep1( Any( valid_residue_characters ) ) +
- AnyEol())
-comment_line = Group( "comment_line", \
- Str( "#" ) +
- ToEol() )
-ignored_line = Group( "ignored_line", \
- Alt( comment_line, residue_number_line ) )
-candidate_line = Group( "candidate_line", \
- Assert( Str( "#" ), 1 ) +
- Assert( Any( valid_residue_characters ), 1 ) +
- ToSep( sep = ' ' ) +
- Rep( Any( valid_sequence_characters ) ) +
- ToEol() )
-saf_record = Group( "saf_record", \
- candidate_line + Rep( Alt( candidate_line, ignored_line ) ) + Opt( Str( "#" ) ) )
-
-
-
-
-
-
-
-
-
View
@@ -123,8 +123,8 @@ The deprecated functions blast and blasturl were removed in Release 1.44.
Bio.Saf
=======
-Deprecated as of Release 1.48, as it appears to have no users, and relies
-on Martel which doesn't work properly with mxTextTools 3.0.
+Deprecated as of Release 1.48, removed in Release 1.51. If useful, a parser
+for this "simple alignment format" could be developed for Bio.AlignIO instead.
Bio.NBRF
========

0 comments on commit 56321cf

Please sign in to comment.