Пример #1
0
 def __init__(self,refGene_fn) :
     refGene_f = open(refGene_fn)
     # check for header
     first_line = refGene_f.next()
     if not first_line.strip().startswith('#') :
         refGene_f.seek(0) # first line not header, reset the file pointer
     DictReader.__init__(self,refGene_f,delimiter='\t',fieldnames=RefGeneOutput.FIELD_NAMES)
Пример #2
0
 def __init__(self, csvFile, csvAbleClass = CSVable, useHeader = False, encoding = None, handleComments = False, *args, **kwargs): # pylint: disable=W1113
     CSVableParser.__init__(self, csvAbleClass, encoding)
     if handleComments:
         csvFile = (line for line in csvFile if not line.strip().startswith(self.COMMENT))
     DictReader.__init__(self, csvFile, None if useHeader else self._fieldNames or (), csvAbleClass.READ_REST_KEY, csvAbleClass.READ_REST_VAL, *args, **kwargs)
     if useHeader and self.fieldnames and self._fieldNames is None:
         self.validateObjectFields(self.fieldnames)
Пример #3
0
 def __init__(self, fid, commentchar='#', *args, **kwds):
     if issubclass(DictReader, object):
         super(DictReader, self).__init__(fid, *args, **kwds)
     else:
         DictReader.__init__(self, fid, *args, **kwds)
     self.commentchar = commentchar
     self.leadingfield = self.commentchar + 'label'
Пример #4
0
 def __init__(self, fid, commentchar='#', *args, **kwds):
     if issubclass(DictReader, object):
         super(DictReader, self).__init__(fid, *args, **kwds)
     else:
         DictReader.__init__(self, fid, *args, **kwds)
     self.commentchar = commentchar
     self.leadingfield = self.commentchar + 'label'
Пример #5
0
    def __init__(self, csvfile, casts, fieldnames=None, restkey=None,
                 restval=None, dialect='excel', *args, **kwds):
        """Arguments:
            
           - f: An iterable object such as as file. Passed on to
             csv.DictReader
           - casts: A dict mapping from attribute names to functions to apply
             to these names, e.g., {'id':int, 'salary':float}
           - fieldnames: Passed on to csv.DictReader
           - restkey: Passed on to csv.DictReader
           - restval: Passed on to csv.DictReader
           - dialect: Passed on to csv.DictReader
           - *args: Passed on to csv.DictReader
           - **kwds: Passed on to csv.DictReader
        """
        DictReader.__init__(self, csvfile, fieldnames=fieldnames,
                            restkey=restkey, restval=restval, dialect=dialect,
                            *args, **kwds)

        if not type(casts) == dict:
            raise TypeError("The casts argument must be a dict")
        for v in casts.values():
            if not callable(v):
                raise TypeError("The values in casts must be callable")
        self._casts = casts
Пример #6
0
 def __init__(self, f, fieldnames=None, restkey=None, restval=None,
              dialect="excel", *args, **kw):
     DictReader.__init__(self, f, fieldnames=fieldnames,
                         restkey=restkey, restval=restval,
                         dialect=dialect, *args, **kw)
     # Replace the reader with our unicode-enabled reader.
     self.reader = UnicodeReader(f, dialect=dialect, *args, **kw)
Пример #7
0
 def __init__(self, affyfn):
     '''*affyfn* is either a filename or a file-like object representing a bioconductor output file'''
     if isinstance(affyfn, str):
         bed = open(bed, 'rU')
     DictReader.__init__(self,
                         bed,
                         delimiter='\t',
                         fieldnames=BEDOutput.FIELD_NAMES)
Пример #8
0
 def __init__(self, bed):
     '''*bed* is either a filename or a file-like object representing a BED file'''
     if isinstance(bed, str):
         bed = open(bed, 'rU')
     DictReader.__init__(self,
                         bed,
                         delimiter='\t',
                         fieldnames=BEDOutput.FIELD_NAMES)
Пример #9
0
    def __init__(self, *args, **kwargs):

        args = list(args)
        args[0] = utfify(args[0])

        DictReader.__init__(
            self, *args,
            **kwargs)  #  DictReader is apparently an old-style  class
Пример #10
0
 def __init__(self, f, fieldnames=None, restkey=None, restval=None,
              dialect="excel", encoding='utf-8', *args, **kw):
     DictReader.__init__(self, f, fieldnames=fieldnames,
                         restkey=restkey, restval=restval,
                         dialect=dialect, *args, **kw)
     if not encoding is None:
         f = Utf8Recoder(f, encoding=encoding)
     # Replace the reader with our unicode-enabled reader.
     self.reader = reader(f, dialect=dialect, *args, **kw)
Пример #11
0
 def __init__(self, fileobj, fieldnames=None,
              key_value_separator=DEFAULT_KEYVALUE_SEPARATOR,
              key_value_assigner=DEFAULT_KEYVALUE_ASSIGNER, **kwargs):
     kwargs.update(restval=kwargs.get('restval', DEFAULT_RESTVAL),
                   restkey=kwargs.get('restkey', DEFAULT_RESTKEY),
                   dialect=kwargs.get('dialect', DEFAULT_DIALECT))
     self.fileobj = fileobj
     DictReader.__init__(self, fileobj, fieldnames=fieldnames, **kwargs)
     self.key_value_separator = key_value_separator
     self.key_value_assigner = key_value_assigner
Пример #12
0
 def __init__(self, refGene_fn):
     refGene_f = open(refGene_fn, 'rU')
     # check for header
     first_line = refGene_f.next()
     if not first_line.strip().startswith('#'):
         refGene_f.seek(0)  # first line not header, reset the file pointer
     DictReader.__init__(self,
                         refGene_f,
                         delimiter='\t',
                         fieldnames=RefGeneOutput.FIELD_NAMES)
Пример #13
0
 def __init__(self, f, fieldnames=None, restkey=None, restval=None,
              dialect="excel",
              encoding=None,
              *args, **kwds):
     BaseDictReader.__init__(self, f=f, fieldnames=fieldnames,
                             restkey=restkey, restval=restval,
                             dialect=dialect,
                             *args, **kwds)
     from .csv import reader
     self.reader = reader(f, dialect=dialect,
                          encoding=encoding,
                          **kwds)
Пример #14
0
 def __init__(self, csvfile, fields=None, silent=False, **kwargs):
   self.csvfile = csvfile
   self.rows_imported = 0
   self.errors = []
   self.silent = silent
   if fields:
     if isinstance(fields[0], (list, tuple)):
       kwargs['fieldnames'] = [field[0] for field in fields]
       self.field_types = dict(fields)
     else:
       kwargs['fieldnames'] = fields
       self.field_types = dict.fromkeys(fields, None)
     DictReader.__init__(self, csvfile, **kwargs)
   else:
     DictReader.__init__(self, csvfile, **kwargs)
     self.field_types = dict.fromkeys(self.fieldnames, None)
Пример #15
0
 def __init__(self,
              f,
              fieldnames=None,
              restkey=None,
              restval=None,
              dialect="excel",
              encoding="utf-8",
              *args,
              **kwargs):
     from csv import DictReader
     DictReader.__init__(self, f, fieldnames, restkey, restval, dialect,
                         *args, **kwargs)
     self.reader = UnicodeReader(f,
                                 dialect,
                                 encoding=encoding,
                                 *args,
                                 **kwargs)
Пример #16
0
 def __init__(self,
              f,
              fieldnames=None,
              restkey=None,
              restval=None,
              dialect="excel",
              encoding='utf-8',
              *args,
              **kw):
     DictReader.__init__(self,
                         f,
                         fieldnames=fieldnames,
                         restkey=restkey,
                         restval=restval,
                         dialect=dialect,
                         *args,
                         **kw)
     if not encoding is None:
         f = Utf8Recoder(f, encoding=encoding)
     # Replace the reader with our unicode-enabled reader.
     self.reader = reader(f, dialect=dialect, *args, **kw)
Пример #17
0
 def __init__(self,
              csvfile,
              fields=None,
              silent=False,
              allow_json=False,
              **kwargs):
     self.csvfile = csvfile
     self.rows_imported = 0
     self.errors = []
     self.silent = silent
     self.allow_json = allow_json
     if fields:
         if isinstance(fields[0], (list, tuple)):
             kwargs['fieldnames'] = [field[0] for field in fields]
             self.field_types = dict(fields)
         else:
             kwargs['fieldnames'] = fields
             self.field_types = dict.fromkeys(fields, None)
         DictReader.__init__(self, csvfile, **kwargs)
     else:
         DictReader.__init__(self, csvfile, **kwargs)
         self.field_types = dict.fromkeys(self.fieldnames, None)
Пример #18
0
    def __init__(self, csvfile, casts, fieldnames=None, restkey=None, 
                 restval=None, dialect='excel', *args, **kwds):
        """Arguments:
           - f: An iterable object such as as file. Passed on to 
             csv.DictReader
           - casts: A dict mapping from attribute names to functions to apply
             to these names, e.g., {'id':int, 'salary':float}
           - fieldnames: Passed on to csv.DictReader
           - restkey: Passed on to csv.DictReader
           - restval: Passed on to csv.DictReader
           - dialect: Passed on to csv.DictReader
           - *args: Passed on to csv.DictReader
           - **kwds: Passed on to csv.DictReader
        """
        DictReader.__init__(self, csvfile, fieldnames=fieldnames, 
                            restkey=restkey, restval=restval, dialect=dialect, 
                            *args, **kwds)

        if not type(casts) == dict:
            raise TypeError("The casts argument must be a dict")
        for v in casts.values():
            if not callable(v):
                raise TypeError("The values in casts must be callable")
        self._casts = casts
Пример #19
0
 def __init__(self,affyfn) :
     '''*affyfn* is either a filename or a file-like object representing a bioconductor output file'''
     if isinstance(affyfn,str) :
         bed = open(bed)
     DictReader.__init__(self,bed,delimiter='\t',
                         fieldnames=BEDOutput.FIELD_NAMES)
Пример #20
0
 def __init__(self,bed) :
     '''*bed* is either a filename or a file-like object representing a BED file'''
     if isinstance(bed,str) :
         bed = open(bed)
     DictReader.__init__(self,bed,delimiter='\t',
                         fieldnames=BEDOutput.FIELD_NAMES)
Пример #21
0
 def __init__(self, *args, **kwargs):
     
     args = list(args)
     args[0] = utfify(args[0])
     
     DictReader.__init__(self, *args, **kwargs) #  DictReader is apparently an old-style  class
Пример #22
0
 def __init__(self, f):
     DictReader.__init__(self, f)
     self._node = Node(ROOT, [])
     self.col_num = 0
     self._init()
Пример #23
0
 def __init__(self, f, fieldnames=None, restkey=None, restval=None,
              dialect="excel", encoding="utf-8", *args, **kwargs):
     from csv import DictReader
     DictReader.__init__(self, f, fieldnames, restkey, restval,
                         dialect, *args, **kwargs)
     self.reader = UnicodeReader(f, dialect, encoding=encoding, *args, **kwargs)
Пример #24
0
 def __init__(self, caller_cls=None, *args, **kwargs):
     DictReader.__init__(self, *args, **kwargs)
     self.caller_cls = caller_cls
Пример #25
0
 def __init__(self, *args, **kwargs):
     DictReader.__init__(self, *args, **kwargs)
     self._fieldnames = map(slugify, self.fieldnames)