comparison commons/core/writer/MySqlTranscriptWriter.py @ 46:169d364ddd91

Uploaded
author m-zytnicki
date Mon, 30 Sep 2013 03:19:26 -0400
parents 44d5973c188c
children
comparison
equal deleted inserted replaced
45:e454402ba9d9 46:169d364ddd91
162 Add a list of transcripts to the transcripts to be written 162 Add a list of transcripts to the transcripts to be written
163 @param transcriptListParser: transcripts to be written 163 @param transcriptListParser: transcripts to be written
164 @type transcriptListParser: class L{TranscriptListParser<TranscriptListParser>} 164 @type transcriptListParser: class L{TranscriptListParser<TranscriptListParser>}
165 """ 165 """
166 self.transcriptListParser = transcriptListParser 166 self.transcriptListParser = transcriptListParser
167 self.mySqlConnection.executeManyFormattedQueriesIterator(self) 167 self.mySqlConnection.executeManyQueriesIterator(self)
168 168
169 169
170 def getIterator(self): 170 def getIterator(self):
171 """ 171 """
172 Iterator to the SQL commands to insert the list 172 Iterator to the SQL commands to insert the list
176 chromosome = transcript.getChromosome() 176 chromosome = transcript.getChromosome()
177 if chromosome not in self.tables: 177 if chromosome not in self.tables:
178 self.createTable(chromosome) 178 self.createTable(chromosome)
179 self.nbTranscriptsByChromosome[chromosome] = self.nbTranscriptsByChromosome.get(chromosome, 0) + 1 179 self.nbTranscriptsByChromosome[chromosome] = self.nbTranscriptsByChromosome.get(chromosome, 0) + 1
180 values = transcript.getSqlValues() 180 values = transcript.getSqlValues()
181 #yield "INSERT INTO '%s' (%s) VALUES (%s)" % (self.tables[chromosome].name, ", ".join(self.tables[chromosome].variables), ", ".join([MySqlTable.formatSql(values[variable], self.tables[chromosome].types[variable], self.tables[chromosome].sizes[variable]) for variable in self.tables[chromosome].variables])) 181 yield "INSERT INTO '%s' (%s) VALUES (%s)" % (self.tables[chromosome].name, ", ".join(self.tables[chromosome].variables), ", ".join([MySqlTable.formatSql(values[variable], self.tables[chromosome].types[variable], self.tables[chromosome].sizes[variable]) for variable in self.tables[chromosome].variables]))
182 yield ("INSERT INTO '%s' (%s) VALUES (%s)" % (self.tables[chromosome].name, ", ".join(self.tables[chromosome].variables), ", ".join(["?"] * len(self.tables[chromosome].variables))), [values[variable] for variable in self.tables[chromosome].variables])
183 progress.inc() 182 progress.inc()
184 progress.done() 183 progress.done()
185 184
186 185
187 def write(self): 186 def write(self):
189 Copy the content of the files into the database 188 Copy the content of the files into the database
190 (May add transcripts to already created databases) 189 (May add transcripts to already created databases)
191 """ 190 """
192 for chromosome in self.transcriptValues: 191 for chromosome in self.transcriptValues:
193 if chromosome in self.transcriptValues: 192 if chromosome in self.transcriptValues:
194 self.tables[chromosome].insertManyFormatted(self.transcriptValues[chromosome]) 193 self.tables[chromosome].insertMany(self.transcriptValues[chromosome])
195 self.transcriptValues = {} 194 self.transcriptValues = {}
196 self.toBeWritten = False 195 self.toBeWritten = False
197 196
198 197
199 def getTables(self): 198 def getTables(self):