示例#1
0
    def __init__(self,
                 iFileHandle,
                 clobber=False,
                 interface=Interface.CONTAINER,
                 method=IndexMethod.SQLITE,
                 **kw):
        """Constructor
        
        @param iFileHandle: Name of input file
        """
        self.iFile = smartopen(iFileHandle)
        self.iFilename = self.iFile.name
        if method == IndexMethod.PICKLE:
            self.indexFile = fasta.FastaIndexPickleFile(self.iFilename)
        elif method == IndexMethod.TEXT:
            self.indexFile = fasta.FastaIndexTextFile(self.iFilename)
        else:  # sqlite3 method is the default
            self.indexFile = fasta.FastaIndexFile(self.iFilename)

        self.indexFile.build(clobber=clobber)
        self.interface = interface
        self._iter = None
        self._initIter = True

        if kw:
            print 'Uncaptured keywords'
            print kw
示例#2
0
 def __init__(self, fileHandle, header=None, separator="\t", mode='w', **kw):
     """
     @param iFileHandle: Output file or name
     @keyword mode: File mode - write(w) or append(a)
     """
     assert mode in ('w', 'a')
     self.iFile = smartopen(fileHandle, mode)
     self.iFilename = self.iFile.name
     self.separator = separator
     if header:
         self.iFile.write(header + "\n")
示例#3
0
 def __init__(self, iFileHandle, header=False, separator="\t"):
     """
     Constructor
     
     @param iFileHandle: File name or object
     @keyword header: Skip header line (default False)
     @keyword separator: Column separator/delimiter (default '\\t')
     
     """
     self.iFile = smartopen(iFileHandle)
     self.separator = separator
     if header:
         headerline = self.iFile.readline()
示例#4
0
 def __init__(self, iFileHandle, header=False, separator="\t"):
     """
     Constructor
     
     @param iFileHandle: File name or object
     @keyword header: Skip header line (default False)
     @keyword separator: Column separator/delimiter (default '\\t')
     
     """
     self.iFile = smartopen(iFileHandle)
     self.separator = separator
     if header:
         headerline = self.iFile.readline()
示例#5
0
 def __init__(self,
              fileHandle,
              header=None,
              separator="\t",
              mode='w',
              **kw):
     """
     @param iFileHandle: Output file or name
     @keyword mode: File mode - write(w) or append(a)
     """
     assert mode in ('w', 'a')
     self.iFile = smartopen(fileHandle, mode)
     self.iFilename = self.iFile.name
     self.separator = separator
     if header:
         self.iFile.write(header + "\n")
示例#6
0
 def __init__(self, iFileHandle, mode='w', width=60, blockSize=None, **kw):
     """
     @param iFileHandle: Output file or name
     @keyword mode: File mode - write(w) or append(a)
     """
     assert mode in ('w', 'a')
     self.iFile = smartopen(iFileHandle, mode)
     self.iFilename = self.iFile.name
     self.width = width
     
     if blockSize: 
         self.setBlockSize(blockSize)
     
     if kw: 
         print 'Uncaptured keywords'
         print kw
示例#7
0
    def __init__(self, iFileHandle, mode='w', width=60, blockSize=None, **kw):
        """
        @param iFileHandle: Output file or name
        @keyword mode: File mode - write(w) or append(a)
        """
        assert mode in ('w', 'a')
        self.iFile = smartopen(iFileHandle, mode)
        self.iFilename = self.iFile.name
        self.width = width

        if blockSize:
            self.setBlockSize(blockSize)

        if kw:
            print 'Uncaptured keywords'
            print kw
示例#8
0
    def __init__(self,
                 iFileHandle,
                 columns,
                 converters=None,
                 header=True,
                 separator='\t',
                 **kw):
        """
        Constructor
        
        @param iFileHandle: File name or object
        @keyword columns: List of column names (default None)
        @keyword converters: List of types or conversion functions (default None)
        @keyword header: Skip header line (default True)
        @keyword separator: Column separator/delimiter (default '\\t')
        
        """
        self.iFile = smartopen(iFileHandle)
        self.columns = columns
        if converters == None:
            converters = []
            for name in columns:
                if "start" in name or "end" in name:
                    converters.append(int)
                elif "strand" in name:
                    converters.append(strandConverter)
                else:
                    converters.append(None)
        elif type(converters) == list and type(
                converters[0]) == tuple:  # list of tuples
            converters = dict(converters)
            converters = [converters.get(column) for column in columns]
        self.converters = converters

        self.separator = separator
        if header:
            headerline = self.iFile.readline()

        if 'fields' in kw:
            warnings.warn("Deprecated keyword fields. Use columns",
                          category=DeprecationWarning)
            self.columns = kw['fields']

        if 'sep' in kw:
            warnings.warn("Deprecated keyword fields. Use columns",
                          category=DeprecationWarning)
            self.separator = kw['sep']
示例#9
0
 def __init__(self, iFileHandle, columns, converters=None, header=True, separator='\t', **kw):
     """
     Constructor
     
     @param iFileHandle: File name or object
     @keyword columns: List of column names (default None)
     @keyword converters: List of types or conversion functions (default None)
     @keyword header: Skip header line (default True)
     @keyword separator: Column separator/delimiter (default '\\t')
     
     """
     self.iFile = smartopen(iFileHandle)
     self.columns = columns
     if converters==None:
         converters = []
         for name in columns:
             if "start" in name or "end" in name:
                 converters.append(int)
             elif "strand" in name:
                 converters.append(strandConverter)
             else:
                 converters.append(None)
     elif type(converters)==list and type(converters[0])==tuple: # list of tuples
         converters = dict(converters)
         converters = [converters.get(column) for column in columns]
     self.converters = converters
     
     self.separator = separator
     if header:
         headerline = self.iFile.readline()
     
     if 'fields' in kw:
         warnings.warn("Deprecated keyword fields. Use columns",
             category=DeprecationWarning)
         self.columns = kw['fields']
     
     if 'sep' in kw:
         warnings.warn("Deprecated keyword fields. Use columns",
             category=DeprecationWarning)
         self.separator = kw['sep']
示例#10
0
 def __init__(self, iFileHandle, clobber=False, 
     interface=Interface.CONTAINER, method=IndexMethod.SQLITE, **kw):
     """
     @param iFileHandle: Fasta file name or object
     """
     self.iFile = smartopen(iFileHandle)
     self.iFilename = self.iFile.name
     if method==IndexMethod.PICKLE:
         self.indexFile = FastaIndexPickleFile(self.iFilename)
     elif method==IndexMethod.TEXT:
         self.indexFile = FastaIndexTextFile(self.iFilename)
     else: # sqlite3 method is the default
         self.indexFile = FastaIndexFile(self.iFilename)
     
     self.indexFile.build(clobber=clobber)
     self.interface = interface
     self._iter = None
     self._initIter = True
     
     if kw: 
         print 'Uncaptured keywords'
         print kw
示例#11
0
 def __init__(self, iFileHandle):
     self.iFile = smartopen(iFileHandle)
     self.iFilename = self.iFile.name
     self._iter = None