Skip to content
Browse files

Removing deprecated modules Bio.EZRetrieve, Bio.NetCatch, Bio.Filtere…

…dReader and class Bio.File.SGMLHandle
  • Loading branch information...
1 parent f9efb5e commit 1097994fa2557cbee14a23c5354b643f312f0b07 @peterjc peterjc committed
Showing with 5 additions and 504 deletions.
  1. +0 −78 Bio/EZRetrieve.py
  2. +3 −44 Bio/File.py
  3. +0 −158 Bio/FilteredReader.py
  4. +0 −223 Bio/NetCatch.py
  5. +2 −1 DEPRECATED
View
78 Bio/EZRetrieve.py
@@ -1,78 +0,0 @@
-"""This module contains code to access EZRetrieve (DEPRECATED).
-
-This module is now deprecated, and will be removed in a future release of
-Biopython.
-
-This is a very simple interface to the EZRetrieve website described in:
-
-Zhang, H., Ramanathan, Y., Soteropoulos, P., Recce, M., and Tolias, P.P. (2002).
-EZ-Retrieve: A web-server for batch retrieval of coordinate-specified human
-DNA sequences and underscoring putative transcription factor-binding sites.
-Nucl. Acids. Res. 2002 30: e121.
-http://dx.doi.org/10.1093/nar/gnf120
-
-Functions:
-retrieve_single Retrieve a single sequence from EZRetrieve.
-parse_single Parse the results from EZRetrieve into FASTA format.
-"""
-
-import warnings
-warnings.warn("Bio.EZRetrieve is deprecated, and will be removed in a future"\
- " release of Biopython. If you want to continue to use this"\
- " code, please get in contact with the Biopython developers"\
- " via the mailing lists to avoid its permanent removal from"\
- " Biopython.", DeprecationWarning)
-
-def retrieve_single(id, from_, to, retrieve_by=None, organism=None,
- parse_results=1):
- import urllib
-
- CGI = "http://siriusb.umdnj.edu:18080/EZRetrieve/single_r_run.jsp"
- org2value = {"Hs" : "0", "Mm" : "1", "Rn" : 2}
- organism = organism or "Hs"
- assert organism in org2value
-
- acctype2value = {"genbank":0, "unigene":1, "locuslink":2, "image":3}
- retrieve_by = retrieve_by or "GenBank"
- retrieve_by = retrieve_by.lower()
- assert retrieve_by in acctype2value
-
- params = {
- "input" : str(id),
- "from" : str(from_),
- "to" : str(to),
- "org" : org2value[organism],
- "AccType" : acctype2value[retrieve_by],
- }
- options = urllib.urlencode(params)
- handle = urllib.urlopen(CGI, options)
- if parse_results:
- results = parse_single(handle)
- else:
- results = handle.read()
- return results
-
-def parse_single(handle):
- """Return a FASTA-formatted string for the sequence. May raise an
- AssertionError if there was a problem retrieving the sequence.
-
- """
- import re
- results = handle.read()
- lresults = results.lower()
-
- i = results.find("Error: ")
- if i >= 0:
- j = lresults.index("<br>", i)
- errmsg = results[i:j].strip()
- raise AssertionError(errmsg)
-
- i = lresults.find("<b>>")
- assert i >= 0, "Couldn't find sequence."
- j = lresults.find("<br><br>", i)
- seqdata = results[i:j]
- reobj = re.compile(r"<[^>]*>", re.IGNORECASE|re.DOTALL)
- seqdata = reobj.sub("", seqdata)
- seqdata = re.sub(r"\s+", r"\n", seqdata)
- seqdata = seqdata.strip() + "\n"
- return seqdata
View
47 Bio/File.py
@@ -12,9 +12,6 @@
StringHandle Wraps a file object around a string.
-SGMLHandle File object that automatically strips SGML tags from data
- (DEPRECATED).
-
SGMLStripper Object that strips SGML. This is now considered OBSOLETE, and
is likely to be deprecated in a future release of Biopython,
and later removed.
@@ -112,50 +109,12 @@ def __exit__(self, type, value, traceback):
try:
import sgmllib
except ImportError:
- #This isn't available on Python 3, but we don't care much as SGMLHandle
- #is deprecated
+ #This isn't available on Python 3, but we don't care much as SGMLStripper
+ #is obsolete
pass
else:
- class SGMLHandle:
- """A Python handle that automatically strips SGML tags from data (DEPRECATED).
-
- This module is now considered to be obsolete, and is likely to be
- deprecated in a future release of Biopython, and later removed.
- """
- def __init__(self, handle):
- """SGMLStripper(handle)
-
- handle is a file handle to SGML-formatted data.
-
- """
- import warnings
- warnings.warn("Bio.File.SGMLHandle is deprecated, and will be removed"\
- " in a future release of Biopython. If you want to"\
- " continue to use this code, please get in contact via"\
- " the mailing lists to avoid its permanent removal from"\
- " Biopython.", DeprecationWarning)
- self._handle = handle
- self._stripper = SGMLStripper()
-
- def read(self, *args, **keywds):
- data = self._handle.read(*args, **keywds)
- return self._stripper.strip(data)
-
- def readline(self, *args, **keywds):
- line = self._handle.readline(*args, **keywds)
- return self._stripper.strip(line)
-
- def readlines(self, *args, **keywds):
- lines = self._handle.readlines(*args, **keywds)
- for i in range(len(lines)):
- lines[i] = self._stripper.strip(str)
- return lines
-
- def __getattr__(self, attr):
- return getattr(self._handle, attr)
-
-
class SGMLStripper:
+ """Object to strip SGML tags (OBSOLETE)."""
class MyParser(sgmllib.SGMLParser):
def __init__(self):
sgmllib.SGMLParser.__init__(self)
View
158 Bio/FilteredReader.py
@@ -1,158 +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.
-
-"""Code for more fancy file handles (DEPRECATED).
-
-This module is now deprecated, and will be removed in a future release of
-Biopython.
-
-Classes:
-Filtered is a decorator for File that allows the user to filter the output
-on a line by line basis.
-
-The FilteredReader module reads a file and applies a sequence of filters to the input
-The constructor sets a default filter chain, but the user can select another filter by setting
-Bio.FilteredReader.filter_chain.
-
-handle = open( "filename" )
-filtered_reader = Bio.FilteredReader( handle )
-filtered_reader.filter_chain = [ remove_asterisks, replace_dot_with_dash ]
-filtered_reasder.read()
-
-All filters in the chain must provide the same interface with a line of text as the single
-input parameter and altered text as the return value.
-"""
-
-import warnings
-warnings.warn("Bio.FilteredReader is deprecated, and will be removed in a"\
- " future release of Biopython. If you want to continue to use"\
- " this code, please get in contact with the developers"\
- " via the mailing lists to avoid its permanent removal from"\
- " Biopython.", DeprecationWarning)
-
-def dump_saved( name, text, j ):
- """Used for debugging."""
- dump_file = open( name + '%d' % j, "w" )
- k = 0
- for i in range ( 0, len( text ), 80 ):
- dump_file.write( '%s\n' % text[ i : i + 80 ] )
- dump_file.close()
-
-def remove_leading_whitespace( line ):
- return line.lstrip()
-
-
-def remove_empty_line( line ):
- stripped_line = line.strip()
- if( stripped_line ):
- return line[ : ]
- else:
- return ''
-
-def remove_useless_dot( line ):
- before = line
- while( 1 ):
- after = before.replace( "\t.\t", "\t\t" )
- if( len( before ) == len( after ) ):
- break
- before = after
- if( after.endswith( '.' ) ):
- after = after[ :-1 ]
- return after
-
-def fix_punctuation( line ):
- line = line.replace( "'", '' )
- line = line.replace( '"', '' )
- line = line.replace( ';', '\t' )
- line = line.replace( 'entryname', 'id' )
-# line = line.lower( )
- if( line ):
- return line[ : ]
- else:
- return ''
-
-
-
-class FilteredReader:
- def __init__(self, handle ):
- self._handle = handle
- self._start_line = ''
- self._debug_count = 0
- self.filter_chain = [ remove_empty_line, remove_useless_dot, fix_punctuation ]
-
- def __getattr__(self, attr):
- return getattr(self._handle, attr)
-
-
-
- def close(self, *args, **keywds ):
- return self._handle.close( *args, **keywds)
-
- def read( self, *args, **keywds ):
- line = ''
- len_expected = self._get_len_expected( args, keywds )
- if( len_expected ):
- filtered_text = self.read_block( len_expected )
- else:
- filtered_text = self.read_to_end()
- return filtered_text
-
- def read_block( self, len_expected ):
-
- len_filtered = 0
- len_adjusted = len(self._start_line)
- filtered_text = ''
- while( len_filtered < len_expected ):
-
- text_read = self._handle.read( len_adjusted )
- full_text = self._start_line + text_read
- lines = full_text.splitlines( 1 )
- if( text_read == '' ):
- filtered_text = filtered_text + self.filter( lines )
- break
- else:
- all_but_last_line = lines[ :-1 ]
- self._start_line = lines[ -1 ]
- filtered_text = filtered_text + self.filter( all_but_last_line )
- len_filtered_text = len( filtered_text )
- len_adjusted -= len_filtered_text
- return filtered_text[ : ]
-
- def read_to_end( self ):
- filtered_text = ''
- text_read = self._handle.read()
- full_text = self._start_line + text_read
- lines = full_text.splitlines( 1 )
- filtered_text += self.filter( lines[:] )
- return filtered_text[ : ]
-
- def _get_len_expected( self, args, keywds ):
-
- if( len( args) > 0 ):
- len_expected = args[ 0 ]
- if( len_expected < 0 ):
- len_expected = None
- elif 'size' in keywds:
- len_expected = keywds['size']
- else:
- len_expected = None
- return len_expected
-
- def filter( self, lines ):
- filter_chain = self.filter_chain
- filtered_text = ''
- for line in lines:
- for filter in filter_chain:
- line = filter( *( line, ) )
- filtered_text += line
-
- return filtered_text
-
-def has_trailing_linefeed( line ):
- if( line.endswith( chr( 13 ) ) or \
- line.endswith( chr( 10 ) ) ):
- return 1
- else:
- return 0
View
223 Bio/NetCatch.py
@@ -1,223 +0,0 @@
-# Copyright 2002 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.
-
-"""Code for dealing with lists of URLs (DEPRECATED).
-
-This module is now deprecated, and will be removed in a future release of
-Biopython.
-
-NetCatch enables the user to scan a list of labelled urls and select
-a subset to read into a file.
-
-Functions:
-get_urls_by_label
-get_urls_by_index
-get_urls_by_range
-select_output_file
-"""
-
-import warnings
-warnings.warn("Bio.NetCatch is deprecated, and will be removed in a future"\
- " release of Biopython. If you want to continue to use this"\
- " code, please get in contact with the Biopython developers"\
- " via the mailing lists to avoid its permanent removal from"\
- " Biopython.", DeprecationWarning)
-import os
-import urllib
-import sgmllib
-from Bio import File
-
-
-def is_absolute_url( candidate ):
- ( url_type, url ) = urllib.splittype( candidate )
- if( url_type == None ):
- return 0
- ( url_host, url ) = urllib.splithost( url )
- if( url_host == None ):
- return 0
- return 1
-
-"""
-ExtractUrls.py
-
-
-Scans a file in http format and builds a dictionary of urls
-"""
-
-class ExtractUrls( sgmllib.SGMLParser ):
-
- def __init__( self ):
- sgmllib.SGMLParser.__init__( self )
- self.reset()
-
- def reset( self ):
- sgmllib.SGMLParser.reset( self )
- self.urls = {}
- self._inlink = 0
- self._pending_url = ''
- self.text = ''
-
- def __str__( self ):
- output = ''
- for key in self.urls.keys():
- val = self.urls[ key ]
- output = output + '%s : %s\n' % ( key, val )
- return output
-
- def extract_urls(self, handle):
- self.feed(handle)
- return self.urls
-
- def feed(self, handle):
- """feed(self, handle )
-
- Feed in data for scanning. handle is a file-like object
- containing html.
-
- """
- if isinstance(handle, File.UndoHandle):
- uhandle = handle
- else:
- uhandle = File.UndoHandle(handle)
- text = uhandle.read()
- sgmllib.SGMLParser.feed( self, text )
-
- def handle_data(self, data):
- if( self._inlink ):
- self.text = self.text + data
-
- def start_a( self, attrs ):
- self._inlink = 1
- for key, val in attrs:
- if key.lower() == 'href':
- self._pending_url = val
-
- def end_a( self ):
- self._inlink = 0
- key = self.text
- self.text = ''
- if not key == '':
- key = key.replace( ' ', '_' )
- self.urls[ key ] = self._pending_url
-
-class Url:
-
- def __init__( self, label, url ):
- assert is_absolute_url( url )
- assert type( label ) == type( '' )
- self.label = label
- self.url = url
-
-class NetCatch:
- """
- Decorator for a dictionary of links. Each link is indexed by its label.
- Allows the user to select links of interest and read each selection into
- its own file. The filename is contructed by appending the label with an
- extension of html.
-
- Files can be selected by index, range or label. The destination directory
- defaults to the current directory. The user can specify another
- dictionary by passing a list of path segments to the constructor.
-
- net_catch = NetCatch()
- net_catch = NetCatch( [ 'amylase', 'species' ] )
- net_catch.get_all_urls()
- net_catch.get_urls_by_label( [ 'pig', 'dog', 'cow' ] )
- net_catch.get_urls_by_index( [ 1, 4, 6, 9 ] )
- net_catch.get_urls_by_range( 2, 5 )
- """
-
- def __init__( self, path_segments = [] ):
- self._urls = {}
- self._labels = []
- assert type( path_segments ) == type( [] )
- self.path_segments = path_segments
- self._build_path()
-
- def _build_path( self ):
- base_path = os.path.join( '' )
- for segment in self.path_segments:
- base_path = os.path.join( base_path, segment )
- self.base_path = base_path
-
- def __str__( self ):
- i = 0
- output = ''
- for label in self._labels:
- output = output + '%d %s: %s\n' % ( i, label, self._urls[ label ] )
- i = i + 1
- return output
-
- def import_dict( self, href_dict ):
- for ( key, val ) in href_dict.items():
- self.add_url( key, val )
-
- def add_url( self, label, url ):
- assert is_absolute_url( url )
- assert type( label ) == type( '' )
- self._labels.append( label )
- self._urls[ label ] = url
-
- def get_all_urls( self ):
- url_opener = urllib.URLopener()
- i = 0
- for label in self._labels:
- base_path = self.base_path
- name = '%s%d.htm' % ( label, i )
- full_path = os.path.join( base_path, name )
- out_handle = open( full_path , "wb" )
- i = i + 1
- url = self._urls[ label ]
- url_handle = url_opener.open( url )
- contents = url_handle.read()
- out_handle.write( contents )
- url_opener.close( )
- out_handle.close()
-
- def get_urls_by_label( self, labels ):
- url_opener = urllib.URLopener()
- for label in labels:
- base_path = self.base_path
- name = '%s.htm' % ( label )
- full_path = os.path.join( base_path, name )
- out_handle = open( full_path , "wb" )
- url = self._urls[ label ]
- url_handle = url_opener.open( url )
- contents = url_handle.read()
- out_handle.write( contents )
- url_opener.close( )
- out_handle.close( )
-
- def get_urls_by_index( self, indices ):
- url_opener = urllib.URLopener()
- for index in indices:
- base_path = self.base_path
- name = '%s.htm' % self._labels[ index ]
- full_path = os.path.join( base_path, name )
- out_handle = open( full_path , "wb" )
- label = self._labels[ index ]
- url = self._urls[ label ]
- url_handle = url_opener.open( url )
- contents = url_handle.read()
- out_handle.write( contents )
- url_opener.close( )
- out_handle.close( )
-
- def get_urls_by_range( self, low, hi ):
- url_opener = urllib.URLopener( )
- for index in range( low, hi ):
- base_path = self.base_path
- name = '%s.htm' % self._labels[ index ]
- full_path = os.path.join( base_path, name )
- out_handle = open( full_path , "wb" )
- label = self._labels[ index ]
- url = self._urls[ label ]
- url_handle = url_opener.open( url )
- contents = url_handle.read()
- out_handle.write( contents )
- url_opener.close( )
- out_handle.close( )
-
-
View
3 DEPRECATED
@@ -114,7 +114,8 @@ Bio.ExPASy.Enzyme, respectively.
Bio.EZRetrieve, Bio.NetCatch, Bio.File.SGMLHandle, Bio.FilteredReader
=====================================================================
-Declared obsolete in Release 1.50, deprecated in Release 1.52.
+Declared obsolete in Release 1.50, deprecated in Release 1.52, removed in
+Release 1.56.
Bio.Graphics.GenomeDiagram and colour/color, centre/center
==========================================================

0 comments on commit 1097994

Please sign in to comment.
Something went wrong with that request. Please try again.