comparison seg2matrix/CGData/BaseTable.py @ 52:3a036a34c362

better handle of input file
author jingchunzhu
date Thu, 17 Sep 2015 15:00:45 -0700
parents b6f5d2d1b047
children b88b95642f59
comparison
equal deleted inserted replaced
51:728eda331f07 52:3a036a34c362
61 if 'comment' in self['cgformat']: 61 if 'comment' in self['cgformat']:
62 comment = self['cgformat']['comment'] 62 comment = self['cgformat']['comment']
63 linenum = 0 63 linenum = 0
64 for row in read: 64 for row in read:
65 linenum += 1 65 linenum += 1
66 if linenum ==1: #ignore header line
67 continue
66 r = self.__row_class__() 68 r = self.__row_class__()
67 if (comment is None or not row[0].startswith(comment)) and not row[0].startswith("#"): 69 if (comment is None or not row[0].startswith(comment)) and not row[0].startswith("#"):
68 for i, col in enumerate(cols): 70 for i, col in enumerate(cols):
71 skip =0
69 isOptional = False 72 isOptional = False
70 if 'columnDef' in self['cgformat'] and col in self['cgformat']['columnDef'] and 'optional' in self['cgformat']['columnDef'][col]: 73 if 'columnDef' in self['cgformat'] and col in self['cgformat']['columnDef'] and 'optional' in self['cgformat']['columnDef'][col]:
71 isOptional = self['cgformat']['columnDef'][col]['optional'] 74 isOptional = self['cgformat']['columnDef'][col]['optional']
72 if len(row) > i: 75 if len(row) > i:
73 try: 76 try:
74 setattr(r, col, colType[col](row[i])) 77 setattr(r, col, colType[col](row[i]))
75 except ValueError: 78 except ValueError:
76 raise ValueError( "col invalid type %s on line %d" % (row[i], linenum)) 79 raise ValueError( "col invalid type %s on line %d" % (row[i], linenum))
77 else: 80 else:
78 if isOptional: 81 if isOptional:
79 setattr(r, col, None) 82 setattr(r, col, None)
80 else: 83 else:
81 print row 84 print row
85 skip =1 # ignore bad lines
86 break
82 raise InvalidFormat("missing colum " + col) 87 raise InvalidFormat("missing colum " + col)
83 88 if skip:
89 continue
90
84 if not self.groupKey: 91 if not self.groupKey:
85 if self.secondKey is not None: 92 if self.secondKey is not None:
86 key1 = getattr(r, self.firstKey ) 93 key1 = getattr(r, self.firstKey )
87 key2 = getattr(r, self.secondKey ) 94 key2 = getattr(r, self.secondKey )
88 if key1 not in storeMap: 95 if key1 not in storeMap: