Mercurial > repos > yufei-luo > s_mart
comparison commons/core/writer/MySqlTranscriptWriter.py @ 18:94ab73e8a190
Uploaded
| author | m-zytnicki |
|---|---|
| date | Mon, 29 Apr 2013 03:20:15 -0400 |
| parents | 769e306b7933 |
| children |
comparison
equal
deleted
inserted
replaced
| 17:b0e8584489e6 | 18:94ab73e8a190 |
|---|---|
| 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.executeManyQueriesIterator(self) | 167 self.mySqlConnection.executeManyFormattedQueriesIterator(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]) | |
| 182 progress.inc() | 183 progress.inc() |
| 183 progress.done() | 184 progress.done() |
| 184 | 185 |
| 185 | 186 |
| 186 def write(self): | 187 def write(self): |
| 188 Copy the content of the files into the database | 189 Copy the content of the files into the database |
| 189 (May add transcripts to already created databases) | 190 (May add transcripts to already created databases) |
| 190 """ | 191 """ |
| 191 for chromosome in self.transcriptValues: | 192 for chromosome in self.transcriptValues: |
| 192 if chromosome in self.transcriptValues: | 193 if chromosome in self.transcriptValues: |
| 193 self.tables[chromosome].insertMany(self.transcriptValues[chromosome]) | 194 self.tables[chromosome].insertManyFormatted(self.transcriptValues[chromosome]) |
| 194 self.transcriptValues = {} | 195 self.transcriptValues = {} |
| 195 self.toBeWritten = False | 196 self.toBeWritten = False |
| 196 | 197 |
| 197 | 198 |
| 198 def getTables(self): | 199 def getTables(self): |
