Best Python code snippet using autotest_python
LienaEncoder.py
Source:LienaEncoder.py
...42 bytes_to_send[4] = (data_type_lsb & 0xff000000) >> 2443 bytes_to_send[5] = (data_type_lsb & 0x00ff0000) >> 1644 bytes_to_send[6] = (data_type_lsb & 0x0000ff00) >> 845 bytes_to_send[7] = (data_type_lsb & 0x000000ff)46 bytes_to_send[8] = (message.get_target_id() & 0xff000000) >> 2447 bytes_to_send[9] = (message.get_target_id() & 0x00ff0000) >> 1648 bytes_to_send[10] = (message.get_target_id() & 0x0000ff00) >> 849 bytes_to_send[11] = (message.get_target_id() & 0x000000ff)50 bytes_to_send[12] = (message.get_origin_id() & 0xff000000) >> 2451 bytes_to_send[13] = (message.get_origin_id() & 0x00ff0000) >> 1652 bytes_to_send[14] = (message.get_origin_id() & 0x0000ff00) >> 853 bytes_to_send[15] = (message.get_origin_id() & 0x000000ff)54 bytes_to_send[16] = (message.get_timestamps() & 0xff00000000000000) >> 5655 bytes_to_send[17] = (message.get_timestamps() & 0x00ff000000000000) >> 4856 bytes_to_send[18] = (message.get_timestamps() & 0x0000ff0000000000) >> 4057 bytes_to_send[19] = (message.get_timestamps() & 0x000000ff00000000) >> 3258 bytes_to_send[20] = (message.get_timestamps() & 0x00000000ff000000) >> 2459 bytes_to_send[21] = (message.get_timestamps() & 0x0000000000ff0000) >> 1660 bytes_to_send[22] = (message.get_timestamps() & 0x000000000000ff00) >> 861 bytes_to_send[23] = (message.get_timestamps() & 0x00000000000000ff)62 bytes_to_send[24] = (message.get_dlc() & 0xff000000) >> 2463 bytes_to_send[25] = (message.get_dlc() & 0x00ff0000) >> 1664 bytes_to_send[26] = (message.get_dlc() & 0x0000ff00) >> 865 bytes_to_send[27] = (message.get_dlc() & 0x000000ff)66 body = message.get_message_body()67 for x in range(28, self.global_parameter.get_global_datagram_size()):68 bytes_to_send[x] = int(body[x-28])69 # print(int(bytes_to_send[40]), int(bytes_to_send[41]), int(bytes_to_send[42]), int(bytes_to_send[43]), int(bytes_to_send[44]), int(bytes_to_send[45]))70 datagram = LienaDatagram(self.global_parameter.get_global_datagram_size(), bytes_to_send)71 return datagram72 def encode_network_quality_message(self, message):73 bytes_to_send = bytearray(self.global_parameter.get_global_datagram_size())74 data_type_msb = message.get_message_id() // (2 ** 32)75 data_type_lsb = message.get_message_id() % (2 ** 32)76 bytes_to_send[0] = (data_type_msb & 0xff000000) >> 2477 bytes_to_send[1] = (data_type_msb & 0x00ff0000) >> 1678 bytes_to_send[2] = (data_type_msb & 0x0000ff00) >> 879 bytes_to_send[3] = (data_type_msb & 0x000000ff)80 bytes_to_send[4] = (data_type_lsb & 0xff000000) >> 2481 bytes_to_send[5] = (data_type_lsb & 0x00ff0000) >> 1682 bytes_to_send[6] = (data_type_lsb & 0x0000ff00) >> 883 bytes_to_send[7] = (data_type_lsb & 0x000000ff)84 bytes_to_send[8] = (message.get_target_id() & 0xff000000) >> 2485 bytes_to_send[9] = (message.get_target_id() & 0x00ff0000) >> 1686 bytes_to_send[10] = (message.get_target_id() & 0x0000ff00) >> 887 bytes_to_send[11] = (message.get_target_id() & 0x000000ff)88 bytes_to_send[12] = (message.get_origin_id() & 0xff000000) >> 2489 bytes_to_send[13] = (message.get_origin_id() & 0x00ff0000) >> 1690 bytes_to_send[14] = (message.get_origin_id() & 0x0000ff00) >> 891 bytes_to_send[15] = (message.get_origin_id() & 0x000000ff)92 bytes_to_send[16] = (message.get_timestamps() & 0xff00000000000000) >> 5693 bytes_to_send[17] = (message.get_timestamps() & 0x00ff000000000000) >> 4894 bytes_to_send[18] = (message.get_timestamps() & 0x0000ff0000000000) >> 4095 bytes_to_send[19] = (message.get_timestamps() & 0x000000ff00000000) >> 3296 bytes_to_send[20] = (message.get_timestamps() & 0x00000000ff000000) >> 2497 bytes_to_send[21] = (message.get_timestamps() & 0x0000000000ff0000) >> 1698 bytes_to_send[22] = (message.get_timestamps() & 0x000000000000ff00) >> 899 bytes_to_send[23] = (message.get_timestamps() & 0x00000000000000ff)100 bytes_to_send[24] = (message.get_dlc() & 0xff000000) >> 24101 bytes_to_send[25] = (message.get_dlc() & 0x00ff0000) >> 16102 bytes_to_send[26] = (message.get_dlc() & 0x0000ff00) >> 8103 bytes_to_send[27] = (message.get_dlc() & 0x000000ff)104 bytes_to_send[28] = message.get_index()105 bytes_to_send[29] = (message.get_t1() & 0xff00000000000000) >> 56106 bytes_to_send[30] = (message.get_t1() & 0x00ff000000000000) >> 48107 bytes_to_send[31] = (message.get_t1() & 0x0000ff0000000000) >> 40108 bytes_to_send[32] = (message.get_t1() & 0x000000ff00000000) >> 32109 bytes_to_send[33] = (message.get_t1() & 0x00000000ff000000) >> 24110 bytes_to_send[34] = (message.get_t1() & 0x0000000000ff0000) >> 16111 bytes_to_send[35] = (message.get_t1() & 0x000000000000ff00) >> 8112 bytes_to_send[36] = (message.get_t1() & 0x00000000000000ff)113 bytes_to_send[37] = (message.get_t2() & 0xff00000000000000) >> 56114 bytes_to_send[38] = (message.get_t2() & 0x00ff000000000000) >> 48115 bytes_to_send[39] = (message.get_t2() & 0x0000ff0000000000) >> 40116 bytes_to_send[40] = (message.get_t2() & 0x000000ff00000000) >> 32117 bytes_to_send[41] = (message.get_t2() & 0x00000000ff000000) >> 24118 bytes_to_send[42] = (message.get_t2() & 0x0000000000ff0000) >> 16119 bytes_to_send[43] = (message.get_t2() & 0x000000000000ff00) >> 8120 bytes_to_send[44] = (message.get_t2() & 0x00000000000000ff)121 bytes_to_send[45] = (message.get_t3() & 0xff00000000000000) >> 56122 bytes_to_send[46] = (message.get_t3() & 0x00ff000000000000) >> 48123 bytes_to_send[47] = (message.get_t3() & 0x0000ff0000000000) >> 40124 bytes_to_send[48] = (message.get_t3() & 0x000000ff00000000) >> 32125 bytes_to_send[49] = (message.get_t3() & 0x00000000ff000000) >> 24126 bytes_to_send[50] = (message.get_t3() & 0x0000000000ff0000) >> 16127 bytes_to_send[51] = (message.get_t3() & 0x000000000000ff00) >> 8128 bytes_to_send[52] = (message.get_t3() & 0x00000000000000ff)129 bytes_to_send[53] = (message.get_t4() & 0xff00000000000000) >> 56130 bytes_to_send[54] = (message.get_t4() & 0x00ff000000000000) >> 48131 bytes_to_send[55] = (message.get_t4() & 0x0000ff0000000000) >> 40132 bytes_to_send[56] = (message.get_t4() & 0x000000ff00000000) >> 32133 bytes_to_send[57] = (message.get_t4() & 0x00000000ff000000) >> 24134 bytes_to_send[58] = (message.get_t4() & 0x0000000000ff0000) >> 16135 bytes_to_send[59] = (message.get_t4() & 0x000000000000ff00) >> 8136 bytes_to_send[60] = (message.get_t4() & 0x00000000000000ff)137 for x in range(61, self.global_parameter.get_global_datagram_size()):138 bytes_to_send[x] = 0139 return bytes_to_send140 def encode_channel_reopened_message(self, message):141 bytes_to_send = bytearray(self.global_parameter.get_global_datagram_size())142 data_type_msb = message.get_message_id() // (2 ** 32)143 data_type_lsb = message.get_message_id() % (2 ** 32)144 bytes_to_send[0] = (data_type_msb & 0xff000000) >> 24145 bytes_to_send[1] = (data_type_msb & 0x00ff0000) >> 16146 bytes_to_send[2] = (data_type_msb & 0x0000ff00) >> 8147 bytes_to_send[3] = (data_type_msb & 0x000000ff)148 bytes_to_send[4] = (data_type_lsb & 0xff000000) >> 24149 bytes_to_send[5] = (data_type_lsb & 0x00ff0000) >> 16150 bytes_to_send[6] = (data_type_lsb & 0x0000ff00) >> 8151 bytes_to_send[7] = (data_type_lsb & 0x000000ff)152 bytes_to_send[8] = (message.get_target_id() & 0xff000000) >> 24153 bytes_to_send[9] = (message.get_target_id() & 0x00ff0000) >> 16154 bytes_to_send[10] = (message.get_target_id() & 0x0000ff00) >> 8155 bytes_to_send[11] = (message.get_target_id() & 0x000000ff)156 bytes_to_send[12] = (message.get_origin_id() & 0xff000000) >> 24157 bytes_to_send[13] = (message.get_origin_id() & 0x00ff0000) >> 16158 bytes_to_send[14] = (message.get_origin_id() & 0x0000ff00) >> 8159 bytes_to_send[15] = (message.get_origin_id() & 0x000000ff)160 bytes_to_send[16] = (message.get_timestamps() & 0xff00000000000000) >> 56161 bytes_to_send[17] = (message.get_timestamps() & 0x00ff000000000000) >> 48162 bytes_to_send[18] = (message.get_timestamps() & 0x0000ff0000000000) >> 40163 bytes_to_send[19] = (message.get_timestamps() & 0x000000ff00000000) >> 32164 bytes_to_send[20] = (message.get_timestamps() & 0x00000000ff000000) >> 24165 bytes_to_send[21] = (message.get_timestamps() & 0x0000000000ff0000) >> 16166 bytes_to_send[22] = (message.get_timestamps() & 0x000000000000ff00) >> 8167 bytes_to_send[23] = (message.get_timestamps() & 0x00000000000000ff)168 bytes_to_send[24] = (message.get_dlc() & 0xff000000) >> 24169 bytes_to_send[25] = (message.get_dlc() & 0x00ff0000) >> 16170 bytes_to_send[26] = (message.get_dlc() & 0x0000ff00) >> 8171 bytes_to_send[27] = (message.get_dlc() & 0x000000ff)172 for x in range(28, self.global_parameter.get_global_datagram_size()):173 bytes_to_send[x] = 0174 return bytes_to_send175 def encode_rehandshake_commit_message(self, message):176 bytes_to_send = bytearray(self.global_parameter.get_global_datagram_size())177 data_type_msb = message.get_message_id() // (2 ** 32)178 data_type_lsb = message.get_message_id() % (2 ** 32)179 bytes_to_send[0] = (data_type_msb & 0xff000000) >> 24180 bytes_to_send[1] = (data_type_msb & 0x00ff0000) >> 16181 bytes_to_send[2] = (data_type_msb & 0x0000ff00) >> 8182 bytes_to_send[3] = (data_type_msb & 0x000000ff)183 bytes_to_send[4] = (data_type_lsb & 0xff000000) >> 24184 bytes_to_send[5] = (data_type_lsb & 0x00ff0000) >> 16185 bytes_to_send[6] = (data_type_lsb & 0x0000ff00) >> 8186 bytes_to_send[7] = (data_type_lsb & 0x000000ff)187 bytes_to_send[8] = (message.get_target_id() & 0xff000000) >> 24188 bytes_to_send[9] = (message.get_target_id() & 0x00ff0000) >> 16189 bytes_to_send[10] = (message.get_target_id() & 0x0000ff00) >> 8190 bytes_to_send[11] = (message.get_target_id() & 0x000000ff)191 bytes_to_send[12] = (message.get_origin_id() & 0xff000000) >> 24192 bytes_to_send[13] = (message.get_origin_id() & 0x00ff0000) >> 16193 bytes_to_send[14] = (message.get_origin_id() & 0x0000ff00) >> 8194 bytes_to_send[15] = (message.get_origin_id() & 0x000000ff)195 bytes_to_send[16] = (message.get_timestamps() & 0xff00000000000000) >> 56196 bytes_to_send[17] = (message.get_timestamps() & 0x00ff000000000000) >> 48197 bytes_to_send[18] = (message.get_timestamps() & 0x0000ff0000000000) >> 40198 bytes_to_send[19] = (message.get_timestamps() & 0x000000ff00000000) >> 32199 bytes_to_send[20] = (message.get_timestamps() & 0x00000000ff000000) >> 24200 bytes_to_send[21] = (message.get_timestamps() & 0x0000000000ff0000) >> 16201 bytes_to_send[22] = (message.get_timestamps() & 0x000000000000ff00) >> 8202 bytes_to_send[23] = (message.get_timestamps() & 0x00000000000000ff)203 bytes_to_send[24] = (message.get_dlc() & 0xff000000) >> 24204 bytes_to_send[25] = (message.get_dlc() & 0x00ff0000) >> 16205 bytes_to_send[26] = (message.get_dlc() & 0x0000ff00) >> 8206 bytes_to_send[27] = (message.get_dlc() & 0x000000ff)207 for x in range(28, self.global_parameter.get_global_datagram_size()):208 bytes_to_send[x] = 0209 return bytes_to_send210 def encode_rehandshake_message(self, message):211 bytes_to_send = bytearray(self.global_parameter.get_global_datagram_size())212 data_type_msb = message.get_message_id() // (2 ** 32)213 data_type_lsb = message.get_message_id() % (2 ** 32)214 bytes_to_send[0] = (data_type_msb & 0xff000000) >> 24215 bytes_to_send[1] = (data_type_msb & 0x00ff0000) >> 16216 bytes_to_send[2] = (data_type_msb & 0x0000ff00) >> 8217 bytes_to_send[3] = (data_type_msb & 0x000000ff)218 bytes_to_send[4] = (data_type_lsb & 0xff000000) >> 24219 bytes_to_send[5] = (data_type_lsb & 0x00ff0000) >> 16220 bytes_to_send[6] = (data_type_lsb & 0x0000ff00) >> 8221 bytes_to_send[7] = (data_type_lsb & 0x000000ff)222 bytes_to_send[8] = (message.get_target_id() & 0xff000000) >> 24223 bytes_to_send[9] = (message.get_target_id() & 0x00ff0000) >> 16224 bytes_to_send[10] = (message.get_target_id() & 0x0000ff00) >> 8225 bytes_to_send[11] = (message.get_target_id() & 0x000000ff)226 bytes_to_send[12] = (message.get_origin_id() & 0xff000000) >> 24227 bytes_to_send[13] = (message.get_origin_id() & 0x00ff0000) >> 16228 bytes_to_send[14] = (message.get_origin_id() & 0x0000ff00) >> 8229 bytes_to_send[15] = (message.get_origin_id() & 0x000000ff)230 bytes_to_send[16] = (message.get_timestamps() & 0xff00000000000000) >> 56231 bytes_to_send[17] = (message.get_timestamps() & 0x00ff000000000000) >> 48232 bytes_to_send[18] = (message.get_timestamps() & 0x0000ff0000000000) >> 40233 bytes_to_send[19] = (message.get_timestamps() & 0x000000ff00000000) >> 32234 bytes_to_send[20] = (message.get_timestamps() & 0x00000000ff000000) >> 24235 bytes_to_send[21] = (message.get_timestamps() & 0x0000000000ff0000) >> 16236 bytes_to_send[22] = (message.get_timestamps() & 0x000000000000ff00) >> 8237 bytes_to_send[23] = (message.get_timestamps() & 0x00000000000000ff)238 bytes_to_send[24] = (message.get_dlc() & 0xff000000) >> 24239 bytes_to_send[25] = (message.get_dlc() & 0x00ff0000) >> 16240 bytes_to_send[26] = (message.get_dlc() & 0x0000ff00) >> 8241 bytes_to_send[27] = (message.get_dlc() & 0x000000ff)242 for x in range(28, self.global_parameter.get_global_datagram_size()):243 bytes_to_send[x] = 0244 return bytes_to_send245 def encode_channel_closed_message(self, message):246 bytes_to_send = bytearray(self.global_parameter.get_global_datagram_size())247 data_type_msb = message.get_message_id() // (2 ** 32)248 data_type_lsb = message.get_message_id() % (2 ** 32)249 bytes_to_send[0] = (data_type_msb & 0xff000000) >> 24250 bytes_to_send[1] = (data_type_msb & 0x00ff0000) >> 16251 bytes_to_send[2] = (data_type_msb & 0x0000ff00) >> 8252 bytes_to_send[3] = (data_type_msb & 0x000000ff)253 bytes_to_send[4] = (data_type_lsb & 0xff000000) >> 24254 bytes_to_send[5] = (data_type_lsb & 0x00ff0000) >> 16255 bytes_to_send[6] = (data_type_lsb & 0x0000ff00) >> 8256 bytes_to_send[7] = (data_type_lsb & 0x000000ff)257 bytes_to_send[8] = (message.get_target_id() & 0xff000000) >> 24258 bytes_to_send[9] = (message.get_target_id() & 0x00ff0000) >> 16259 bytes_to_send[10] = (message.get_target_id() & 0x0000ff00) >> 8260 bytes_to_send[11] = (message.get_target_id() & 0x000000ff)261 bytes_to_send[12] = (message.get_origin_id() & 0xff000000) >> 24262 bytes_to_send[13] = (message.get_origin_id() & 0x00ff0000) >> 16263 bytes_to_send[14] = (message.get_origin_id() & 0x0000ff00) >> 8264 bytes_to_send[15] = (message.get_origin_id() & 0x000000ff)265 bytes_to_send[16] = (message.get_timestamps() & 0xff00000000000000) >> 56266 bytes_to_send[17] = (message.get_timestamps() & 0x00ff000000000000) >> 48267 bytes_to_send[18] = (message.get_timestamps() & 0x0000ff0000000000) >> 40268 bytes_to_send[19] = (message.get_timestamps() & 0x000000ff00000000) >> 32269 bytes_to_send[20] = (message.get_timestamps() & 0x00000000ff000000) >> 24270 bytes_to_send[21] = (message.get_timestamps() & 0x0000000000ff0000) >> 16271 bytes_to_send[22] = (message.get_timestamps() & 0x000000000000ff00) >> 8272 bytes_to_send[23] = (message.get_timestamps() & 0x00000000000000ff)273 bytes_to_send[24] = (message.get_dlc() & 0xff000000) >> 24274 bytes_to_send[25] = (message.get_dlc() & 0x00ff0000) >> 16275 bytes_to_send[26] = (message.get_dlc() & 0x0000ff00) >> 8276 bytes_to_send[27] = (message.get_dlc() & 0x000000ff)277 for x in range(28, self.global_parameter.get_global_datagram_size()):278 bytes_to_send[x] = 0279 return bytes_to_send280 def encode_disengagement_commit_message(self, message):281 bytes_to_send = bytearray(self.global_parameter.get_global_datagram_size())282 data_type_msb = message.get_message_id() // (2 ** 32)283 data_type_lsb = message.get_message_id() % (2 ** 32)284 bytes_to_send[0] = (data_type_msb & 0xff000000) >> 24285 bytes_to_send[1] = (data_type_msb & 0x00ff0000) >> 16286 bytes_to_send[2] = (data_type_msb & 0x0000ff00) >> 8287 bytes_to_send[3] = (data_type_msb & 0x000000ff)288 bytes_to_send[4] = (data_type_lsb & 0xff000000) >> 24289 bytes_to_send[5] = (data_type_lsb & 0x00ff0000) >> 16290 bytes_to_send[6] = (data_type_lsb & 0x0000ff00) >> 8291 bytes_to_send[7] = (data_type_lsb & 0x000000ff)292 bytes_to_send[8] = (message.get_target_id() & 0xff000000) >> 24293 bytes_to_send[9] = (message.get_target_id() & 0x00ff0000) >> 16294 bytes_to_send[10] = (message.get_target_id() & 0x0000ff00) >> 8295 bytes_to_send[11] = (message.get_target_id() & 0x000000ff)296 bytes_to_send[12] = (message.get_origin_id() & 0xff000000) >> 24297 bytes_to_send[13] = (message.get_origin_id() & 0x00ff0000) >> 16298 bytes_to_send[14] = (message.get_origin_id() & 0x0000ff00) >> 8299 bytes_to_send[15] = (message.get_origin_id() & 0x000000ff)300 bytes_to_send[16] = (message.get_timestamps() & 0xff00000000000000) >> 56301 bytes_to_send[17] = (message.get_timestamps() & 0x00ff000000000000) >> 48302 bytes_to_send[18] = (message.get_timestamps() & 0x0000ff0000000000) >> 40303 bytes_to_send[19] = (message.get_timestamps() & 0x000000ff00000000) >> 32304 bytes_to_send[20] = (message.get_timestamps() & 0x00000000ff000000) >> 24305 bytes_to_send[21] = (message.get_timestamps() & 0x0000000000ff0000) >> 16306 bytes_to_send[22] = (message.get_timestamps() & 0x000000000000ff00) >> 8307 bytes_to_send[23] = (message.get_timestamps() & 0x00000000000000ff)308 bytes_to_send[24] = (message.get_dlc() & 0xff000000) >> 24309 bytes_to_send[25] = (message.get_dlc() & 0x00ff0000) >> 16310 bytes_to_send[26] = (message.get_dlc() & 0x0000ff00) >> 8311 bytes_to_send[27] = (message.get_dlc() & 0x000000ff)312 for x in range(28, self.global_parameter.get_global_datagram_size()):313 bytes_to_send[x] = 0314 return bytes_to_send315 def encode_disengagement_message(self, message):316 bytes_to_send = bytearray(self.global_parameter.get_global_datagram_size())317 data_type_msb = message.get_message_id() // (2 ** 32)318 data_type_lsb = message.get_message_id() % (2 ** 32)319 bytes_to_send[0] = (data_type_msb & 0xff000000) >> 24320 bytes_to_send[1] = (data_type_msb & 0x00ff0000) >> 16321 bytes_to_send[2] = (data_type_msb & 0x0000ff00) >> 8322 bytes_to_send[3] = (data_type_msb & 0x000000ff)323 bytes_to_send[4] = (data_type_lsb & 0xff000000) >> 24324 bytes_to_send[5] = (data_type_lsb & 0x00ff0000) >> 16325 bytes_to_send[6] = (data_type_lsb & 0x0000ff00) >> 8326 bytes_to_send[7] = (data_type_lsb & 0x000000ff)327 bytes_to_send[8] = (message.get_target_id() & 0xff000000) >> 24328 bytes_to_send[9] = (message.get_target_id() & 0x00ff0000) >> 16329 bytes_to_send[10] = (message.get_target_id() & 0x0000ff00) >> 8330 bytes_to_send[11] = (message.get_target_id() & 0x000000ff)331 bytes_to_send[12] = (message.get_origin_id() & 0xff000000) >> 24332 bytes_to_send[13] = (message.get_origin_id() & 0x00ff0000) >> 16333 bytes_to_send[14] = (message.get_origin_id() & 0x0000ff00) >> 8334 bytes_to_send[15] = (message.get_origin_id() & 0x000000ff)335 bytes_to_send[16] = (message.get_timestamps() & 0xff00000000000000) >> 56336 bytes_to_send[17] = (message.get_timestamps() & 0x00ff000000000000) >> 48337 bytes_to_send[18] = (message.get_timestamps() & 0x0000ff0000000000) >> 40338 bytes_to_send[19] = (message.get_timestamps() & 0x000000ff00000000) >> 32339 bytes_to_send[20] = (message.get_timestamps() & 0x00000000ff000000) >> 24340 bytes_to_send[21] = (message.get_timestamps() & 0x0000000000ff0000) >> 16341 bytes_to_send[22] = (message.get_timestamps() & 0x000000000000ff00) >> 8342 bytes_to_send[23] = (message.get_timestamps() & 0x00000000000000ff)343 bytes_to_send[24] = (message.get_dlc() & 0xff000000) >> 24344 bytes_to_send[25] = (message.get_dlc() & 0x00ff0000) >> 16345 bytes_to_send[26] = (message.get_dlc() & 0x0000ff00) >> 8346 bytes_to_send[27] = (message.get_dlc() & 0x000000ff)347 for x in range(28, self.global_parameter.get_global_datagram_size()):348 bytes_to_send[x] = 0349 return bytes_to_send350 def encode_handshake_commit_message(self, message):351 bytes_to_send = bytearray(self.global_parameter.get_global_datagram_size())352 data_type_msb = message.get_message_id() // (2 ** 32)353 data_type_lsb = message.get_message_id() % (2 ** 32)354 bytes_to_send[0] = (data_type_msb & 0xff000000) >> 24355 bytes_to_send[1] = (data_type_msb & 0x00ff0000) >> 16356 bytes_to_send[2] = (data_type_msb & 0x0000ff00) >> 8357 bytes_to_send[3] = (data_type_msb & 0x000000ff)358 bytes_to_send[4] = (data_type_lsb & 0xff000000) >> 24359 bytes_to_send[5] = (data_type_lsb & 0x00ff0000) >> 16360 bytes_to_send[6] = (data_type_lsb & 0x0000ff00) >> 8361 bytes_to_send[7] = (data_type_lsb & 0x000000ff)362 bytes_to_send[8] = (message.get_target_id() & 0xff000000) >> 24363 bytes_to_send[9] = (message.get_target_id() & 0x00ff0000) >> 16364 bytes_to_send[10] = (message.get_target_id() & 0x0000ff00) >> 8365 bytes_to_send[11] = (message.get_target_id() & 0x000000ff)366 bytes_to_send[12] = (message.get_origin_id() & 0xff000000) >> 24367 bytes_to_send[13] = (message.get_origin_id() & 0x00ff0000) >> 16368 bytes_to_send[14] = (message.get_origin_id() & 0x0000ff00) >> 8369 bytes_to_send[15] = (message.get_origin_id() & 0x000000ff)370 bytes_to_send[16] = (message.get_timestamps() & 0xff00000000000000) >> 56371 bytes_to_send[17] = (message.get_timestamps() & 0x00ff000000000000) >> 48372 bytes_to_send[18] = (message.get_timestamps() & 0x0000ff0000000000) >> 40373 bytes_to_send[19] = (message.get_timestamps() & 0x000000ff00000000) >> 32374 bytes_to_send[20] = (message.get_timestamps() & 0x00000000ff000000) >> 24375 bytes_to_send[21] = (message.get_timestamps() & 0x0000000000ff0000) >> 16376 bytes_to_send[22] = (message.get_timestamps() & 0x000000000000ff00) >> 8377 bytes_to_send[23] = (message.get_timestamps() & 0x00000000000000ff)378 bytes_to_send[24] = (message.get_dlc() & 0xff000000) >> 24379 bytes_to_send[25] = (message.get_dlc() & 0x00ff0000) >> 16380 bytes_to_send[26] = (message.get_dlc() & 0x0000ff00) >> 8381 bytes_to_send[27] = (message.get_dlc() & 0x000000ff)382 for x in range(28, self.global_parameter.get_global_datagram_size()):383 bytes_to_send[x] = 0384 return bytes_to_send385 def encode_heartbeat_message(self, message):386 bytes_to_send = bytearray(self.global_parameter.get_global_datagram_size())387 data_type_msb = message.get_message_id() // (2 ** 32)388 data_type_lsb = message.get_message_id() % (2 ** 32)389 bytes_to_send[0] = (data_type_msb & 0xff000000) >> 24390 bytes_to_send[1] = (data_type_msb & 0x00ff0000) >> 16391 bytes_to_send[2] = (data_type_msb & 0x0000ff00) >> 8392 bytes_to_send[3] = (data_type_msb & 0x000000ff)393 bytes_to_send[4] = (data_type_lsb & 0xff000000) >> 24394 bytes_to_send[5] = (data_type_lsb & 0x00ff0000) >> 16395 bytes_to_send[6] = (data_type_lsb & 0x0000ff00) >> 8396 bytes_to_send[7] = (data_type_lsb & 0x000000ff)397 bytes_to_send[8] = (message.get_target_id() & 0xff000000) >> 24398 bytes_to_send[9] = (message.get_target_id() & 0x00ff0000) >> 16399 bytes_to_send[10] = (message.get_target_id() & 0x0000ff00) >> 8400 bytes_to_send[11] = (message.get_target_id() & 0x000000ff)401 bytes_to_send[12] = (message.get_origin_id() & 0xff000000) >> 24402 bytes_to_send[13] = (message.get_origin_id() & 0x00ff0000) >> 16403 bytes_to_send[14] = (message.get_origin_id() & 0x0000ff00) >> 8404 bytes_to_send[15] = (message.get_origin_id() & 0x000000ff)405 bytes_to_send[16] = (message.get_timestamps() & 0xff00000000000000) >> 56406 bytes_to_send[17] = (message.get_timestamps() & 0x00ff000000000000) >> 48407 bytes_to_send[18] = (message.get_timestamps() & 0x0000ff0000000000) >> 40408 bytes_to_send[19] = (message.get_timestamps() & 0x000000ff00000000) >> 32409 bytes_to_send[20] = (message.get_timestamps() & 0x00000000ff000000) >> 24410 bytes_to_send[21] = (message.get_timestamps() & 0x0000000000ff0000) >> 16411 bytes_to_send[22] = (message.get_timestamps() & 0x000000000000ff00) >> 8412 bytes_to_send[23] = (message.get_timestamps() & 0x00000000000000ff)413 bytes_to_send[24] = (message.get_dlc() & 0xff000000) >> 24414 bytes_to_send[25] = (message.get_dlc() & 0x00ff0000) >> 16415 bytes_to_send[26] = (message.get_dlc() & 0x0000ff00) >> 8416 bytes_to_send[27] = (message.get_dlc() & 0x000000ff)417 for x in range(28, self.global_parameter.get_global_datagram_size()):418 bytes_to_send[x] = 0419 return bytes_to_send420 def encode_channelopened_message(self, message):421 bytes_to_send = bytearray(self.global_parameter.get_global_datagram_size())422 data_type_msb = message.get_message_id() // (2 ** 32)423 data_type_lsb = message.get_message_id() % (2 ** 32)424 bytes_to_send[0] = (data_type_msb & 0xff000000) >> 24425 bytes_to_send[1] = (data_type_msb & 0x00ff0000) >> 16426 bytes_to_send[2] = (data_type_msb & 0x0000ff00) >> 8427 bytes_to_send[3] = (data_type_msb & 0x000000ff)428 bytes_to_send[4] = (data_type_lsb & 0xff000000) >> 24429 bytes_to_send[5] = (data_type_lsb & 0x00ff0000) >> 16430 bytes_to_send[6] = (data_type_lsb & 0x0000ff00) >> 8431 bytes_to_send[7] = (data_type_lsb & 0x000000ff)432 bytes_to_send[8] = (message.get_target_id() & 0xff000000) >> 24433 bytes_to_send[9] = (message.get_target_id() & 0x00ff0000) >> 16434 bytes_to_send[10] = (message.get_target_id() & 0x0000ff00) >> 8435 bytes_to_send[11] = (message.get_target_id() & 0x000000ff)436 bytes_to_send[12] = (message.get_origin_id() & 0xff000000) >> 24437 bytes_to_send[13] = (message.get_origin_id() & 0x00ff0000) >> 16438 bytes_to_send[14] = (message.get_origin_id() & 0x0000ff00) >> 8439 bytes_to_send[15] = (message.get_origin_id() & 0x000000ff)440 bytes_to_send[16] = (message.get_timestamps() & 0xff00000000000000) >> 56441 bytes_to_send[17] = (message.get_timestamps() & 0x00ff000000000000) >> 48442 bytes_to_send[18] = (message.get_timestamps() & 0x0000ff0000000000) >> 40443 bytes_to_send[19] = (message.get_timestamps() & 0x000000ff00000000) >> 32444 bytes_to_send[20] = (message.get_timestamps() & 0x00000000ff000000) >> 24445 bytes_to_send[21] = (message.get_timestamps() & 0x0000000000ff0000) >> 16446 bytes_to_send[22] = (message.get_timestamps() & 0x000000000000ff00) >> 8447 bytes_to_send[23] = (message.get_timestamps() & 0x00000000000000ff)448 bytes_to_send[24] = (message.get_dlc() & 0xff000000) >> 24449 bytes_to_send[25] = (message.get_dlc() & 0x00ff0000) >> 16450 bytes_to_send[26] = (message.get_dlc() & 0x0000ff00) >> 8451 bytes_to_send[27] = (message.get_dlc() & 0x000000ff)452 for x in range(28, self.global_parameter.get_global_datagram_size()):453 bytes_to_send[x] = 0454 return bytes_to_send455 def encode_handshake_message(self, message):456 bytes_to_send = bytearray(self.global_parameter.get_global_datagram_size())457 data_type_msb = message.get_message_id() // (2 ** 32)458 data_type_lsb = message.get_message_id() % (2 ** 32)459 bytes_to_send[0] = (data_type_msb & 0xff000000) >> 24460 bytes_to_send[1] = (data_type_msb & 0x00ff0000) >> 16461 bytes_to_send[2] = (data_type_msb & 0x0000ff00) >> 8462 bytes_to_send[3] = (data_type_msb & 0x000000ff)463 bytes_to_send[4] = (data_type_lsb & 0xff000000) >> 24464 bytes_to_send[5] = (data_type_lsb & 0x00ff0000) >> 16465 bytes_to_send[6] = (data_type_lsb & 0x0000ff00) >> 8466 bytes_to_send[7] = (data_type_lsb & 0x000000ff)467 bytes_to_send[8] = (message.get_target_id() & 0xff000000) >> 24468 bytes_to_send[9] = (message.get_target_id() & 0x00ff0000) >> 16469 bytes_to_send[10] = (message.get_target_id() & 0x0000ff00) >> 8470 bytes_to_send[11] = (message.get_target_id() & 0x000000ff)471 bytes_to_send[12] = (message.get_origin_id() & 0xff000000) >> 24472 bytes_to_send[13] = (message.get_origin_id() & 0x00ff0000) >> 16473 bytes_to_send[14] = (message.get_origin_id() & 0x0000ff00) >> 8474 bytes_to_send[15] = (message.get_origin_id() & 0x000000ff)475 bytes_to_send[16] = (message.get_timestamps() & 0xff00000000000000) >> 56476 bytes_to_send[17] = (message.get_timestamps() & 0x00ff000000000000) >> 48477 bytes_to_send[18] = (message.get_timestamps() & 0x0000ff0000000000) >> 40478 bytes_to_send[19] = (message.get_timestamps() & 0x000000ff00000000) >> 32479 bytes_to_send[20] = (message.get_timestamps() & 0x00000000ff000000) >> 24480 bytes_to_send[21] = (message.get_timestamps() & 0x0000000000ff0000) >> 16481 bytes_to_send[22] = (message.get_timestamps() & 0x000000000000ff00) >> 8482 bytes_to_send[23] = (message.get_timestamps() & 0x00000000000000ff)483 bytes_to_send[24] = (message.get_dlc() & 0xff000000) >> 24484 bytes_to_send[25] = (message.get_dlc() & 0x00ff0000) >> 16...
Hit.py
Source:Hit.py
...129 self.alignment = alignment130 def keys(self):131 '''Returns a list of tuples that will be used as keys for this hit in a hitlist.'''132 if self.get_seq_id is not None and self.get_target_id is not None:133 return [(self.get_seq_id(), self.get_target_id(), self.seq_location[0], self.target_location[0]),134 (self.get_seq_id(), self.get_target_id(), self.seq_location[1], self.target_location[1]),135 (self.get_seq_id(), self.get_target_id(), self.seq_location[0], self.target_location[0])]136 else:137 return None138 def _check_rc(self):139 '''140 Returns True if the current hit is a hit on the reversed complement of a141 sequence originally read from a file.142 '''143 return(self.get_seq_id()[-2:] == "RC" and self.get_target_id()[-2:] == "RC")144 def get_seq_id(self):145 '''Returns the ID of the sequence that contains the current alignment.'''146 return self.sequence_info.id147 def get_target_id(self):148 '''Returns the ID of the target that contains the current alignment.'''149 return self.target_info.id150 def get_euclidian_distance(self):151 '''Returns the calculated Euclidian distance between sequence and target'''152 if self.target_info.distance is None:153 return 0.0154 else:155 return self.target_info.distance156 def get_graph_relation(self, prefix, targetID, sequence_node, target_node):157 158 relParameters = "seq_start:{},seq_end:{},".format(self.seq_location[0], self.seq_location[1])159 relParameters += "target_start:{},target_end:{},".format(self.target_location[0], self.target_location[1])160 relParameters += "score: {}, length: {}, ".format(self.score, len(self.alignment))161 relParameters += "relative_score: {}, base_score: {}, ".format(self.relative_score, self.base_score)162 relParameters += "query_identity: {}, query_coverage: {}, ".format(self.query_identity, self.query_coverage)163 164 if targetID == self.get_target_id():165 relParameters += "direction:'forward'"166 else:167 relParameters += "direction:'reverse'"168 relation = "AlignsWith"169 170 if self.target_location[0] - self.seq_location[0] >= 0 and self.target_location[1] + (self.sequence_info.original_length - self.seq_location[1]) <= self.target_info.original_length:171 relation = "AlignsIn"172 relParameters += ",extends: 0"173 elif (self.target_location[0] - self.seq_location[0] >= 0 and self.target_location[1] + 1 == self.target_info.original_length) or (self.target_location[0] == 0 and self.target_location[1] + 1 + (self.sequence_info.original_length - self.seq_location[1]) <= self.target_info.original_length):174 relation = "Extends"175 if self.target_location[1] + 1 == self.target_info.original_length:176 relation += "End"177 relParameters += ",extends: {}".format(self.sequence_info.original_length-self.seq_location[1])178 else:179 relation += "Start"180 relParameters += ",extends: {}".format(self.seq_location[0])181 elif (self.target_location[0] - self.seq_location[0] >= 0 and self.target_location[1] + (self.sequence_info.original_length - self.seq_location[1]) > self.target_info.original_length) or (self.target_location[0] - self.seq_location[0] < 0 and self.target_location[1] + (self.sequence_info.original_length - self.seq_location[1]) <= self.target_info.original_length) :182 relation = "Overlaps"183 if self.target_location[1] + (self.sequence_info.original_length - self.seq_location[1]) > self.target_info.original_length:184 relParameters += ",extends: {}".format(self.sequence_info.original_length-self.seq_location[1])185 relation += "End"186 else:187 relation += "Start"188 relParameters += ",extends: {}".format(self.seq_location[0])189 else:190 relParameters += ",extends: 0"191 return "match (a:{}),(b:{}) where a.name = '{}_{}' and b.name= '{}_{}' and (not a.name = b.name) and not (a)-[:{}]->(b) create (a)-[r:{} {{ {} }}]->(b)".format(192 sequence_node, target_node, prefix, self.get_seq_id(), prefix, targetID, relation, relation,relParameters)193 def get_sam_line(self):194 '''Creates and returns an alignment line as described in http://samtools.sourceforge.net/SAM1.pdf195 The following mappings are used for record lines:196 QNAME: self.get_seq_id()197 FLAG: only bit 0x2 and 0x10 are set since the other values are either false or unknown198 RNAME: self.get_target_id()199 POS: hit.target_location[0] + 1 (+1 since SAM is 1 based!)200 MAPQ: set to 255 to indicate quality score is not available201 CIGAR: see _get_sam_cigar202 RNEXT: set to * (not available)203 PNEXT: set to 0 (not available)204 TLEN: set to 0 (not available)205 SEQ: self.sequence_info.sequence206 QUAL: set to * (not available)207 AS: self.score208 AD:f: computed euclidian distance between sequence and target209 RS:f: computed relative score210 '''211 rc_seq = False212 rc_target = False213 214 identifier = self.get_seq_id()215 if identifier[-2:] == 'RC':216 identifier = identifier[:-3]217 rc_seq = True218 target_id = self.get_target_id()219 if target_id[-2:] == 'RC':220 target_id = target_id[:-3]221 rc_target = True222 223 #rc = (rc_seq and not rc_target) or (not rc_seq and rc_target)224 self.rc = rc_target or rc_seq 225 226 hit_pos = str(self.target_location[0] + 1)227 sam_sequence = self.sequence_info.seq228 if self.rc:229 self.alignment = self.alignment[::-1]230 self.sequence_match = self.sequence_match[::-1]231 sam_sequence = Seq(str(self.sequence_info.seq), self.sequence_info.seq.alphabet).reverse_complement()232 hit_pos = str(self.target_info.original_length - self.target_location[1])233 if len(self.sequence_match) == 0 or len(self.target_match) == 0 or len(self.alignment) == 0:234 raise CudaException('sequence_match, target_match and alignment should be set and have lengths > 0.')235 return '\t'.join([identifier, self._get_sam_flag(), target_id,236 hit_pos, Hit._get_sam_mapq(), self._get_sam_cigar(),237 '*', str(0), str(0), str(sam_sequence), '*', self._get_sam_alignment_score(),238 self._get_sam_relative_score(),239 self._get_sam_relative_base_score(),240 self._get_sam_query_coverage(),241 self._get_sam_query_identity()])242 243 def get_trimmed_line(self):244 identifier = self.get_seq_id()245 if identifier[-2:] == 'RC':246 identifier = identifier[:-3]247 target_id = self.get_target_id()248 if target_id[-2:] == 'RC':249 target_id = target_id[:-3]250 if len(self.sequence_match) == 0 or len(self.target_match) == 0 or len(self.alignment) == 0:251 raise CudaException('sequence_match, target_match and alignment should be set and have lengths > 0.')252 return ''.join(['>', target_id, ' ', self.sequence_info.id, "\n", 253 str(self.sequence_info.seq[:self.target_location[0]] + self.sequence_info.seq[self.target_location[1]+1:])])254 def get_fasta(self):255 identifier = self.get_seq_id()256 if identifier[-2:] == 'RC':257 identifier = identifier[:-3]258 target_id = self.get_target_id()259 if target_id[-2:] == 'RC':260 target_id = target_id[:-3]261 if len(self.sequence_match) == 0 or len(self.target_match) == 0 or len(self.alignment) == 0:262 raise CudaException('sequence_match, target_match and alignment should be set and have lengths > 0.')263 return ''.join(['>', target_id, ' ', self.sequence_info.id, "\n", 264 str(self.sequence_info.seq[:self.target_location[0]] + self.sequence_info.seq[self.target_location[1]+1:])])265 def get_full_fasta(self):266 identifier = self.get_seq_id()267 return '>{}\n{}'.format(identifier, str(self.sequence_info.seq))268 def get_sam_sq(self):269 '''creates and returns the target (reference) information of the hit formatted270 as a SAM SQ-line. See http://samtools.sourceforge.net/SAM1.pdf271 '''272 return '\t'.join(['@SQ', 'SN:{0}'.format(self.get_target_id() if self.get_target_id()[-2:] != "RC" else self.get_target_id()[:-3]),273 'LN:{0}'.format(self.target_info.original_length)])274 def _get_sam_alignment_score(self):275 '''Returns the (optional) field containing the alignment score of the hit as an int.276 '''277 return ':'.join(['AS', 'i', str(int(self.score))])278 def _get_sam_flag(self):279 '''Assemble the FLAG field of a hit as described in http://samtools.sourceforge.net/SAM1.pdf.280 If the hit involves the reversed complement of a sequence, bit 16 is set.281 The other bits are set to 0, either because their value is unknown or False.282 '''283 flag = 0284 if self.get_seq_id()[-2:] == 'RC' or self.get_target_id()[-2:] == 'RC':285 flag += 16286 return str(flag)287 @staticmethod288 def _get_sam_mapq():289 '''Determine the MAPQ field as described in http://samtools.sourceforge.net/SAM1.pdf.290 At the moment a fixed value of 255 is returned, indicating that mapping quality is not available.291 '''292 return str(255)293 def _get_sam_cigar(self):294 '''Determines the CIGAR of a hit as described in http://samtools.sourceforge.net/SAM1.pdf.295 '''296 cigar_parts = []297 # add clipping information to cigar_parts298 if not self.rc:...
Formatters.py
Source:Formatters.py
...15 self.logger.debug('Initialized {0}'.format(self.name))16 def _format_hit(self, hit):17 '''This method may be overruled to enable other formats for printed results.'''18 self.logger.debug('Formatting hit {0}'.format(hit.get_seq_id()))19 formatted_hit = ', '.join([hit.get_seq_id(), hit.get_target_id(), str(hit.seq_location[0]), str(hit.seq_location[1]),20 str(hit.target_location[0]), str(hit.target_location[1]), str(hit.score), str(hit.matches),21 str(hit.mismatches), str(len(hit.alignment) - hit.matches - hit.mismatches),22 str(len(hit.alignment)), str(hit.score / len(hit.alignment)),23 str(hit.sequence_info.original_length), str(hit.target_info.original_length),24 str(hit.score / hit.sequence_info.original_length),25 str(hit.score / hit.target_info.original_length), str(hit.distance)])26 formatted_hit = '\n'.join([formatted_hit, hit.sequence_match, hit.alignment, hit.target_match])27 return formatted_hit28 def _set_name(self):29 '''Name of the formatter. Used for logging'''30 self.name = 'defaultformatter'31 def _get_hits(self):32 '''Returns ordered list of hits'''33 hits = self.hitlist.real_hits.values()34 return sorted(hits, key=lambda hit: (hit.get_seq_id(), hit.get_target_id(), hit.score))35 def print_results(self):36 '''sets, formats and prints the results to a file.'''37 self.logger.debug('printing results...')38 output = open(self.outputfile, 'w')39 for hit in self._get_hits():40 formatted_hit = self._format_hit(hit)41 output.write(formatted_hit + "\n")42 self.logger.debug('finished printing results')43class SamFormatter(DefaultFormatter):44 '''This Formatter is used to create SAM output45 See http://samtools.sourceforge.net/SAM1.pdf46 '''47 def __init__(self, logger, hitlist, outputfile):48 '''Since the header contains information about the target sequences and must be49 present before alignment lines, formatted lines are stored before printing.50 '''51 DefaultFormatter.__init__(self, logger, hitlist, outputfile)52 self.sq_lines = {}53 self.record_lines = []54 def _set_name(self):55 '''Name of the formatter. Used for logging'''56 self.name = 'SAM formatter'57 def _format_hit(self, hit):58 '''Adds a header line to self.sq_lines and an alignment line to self.record_lines.59 The following mappings are used for header lines:60 SN: hit.get_target_id()61 LN: hit.full_target.original_length62 '''63 self.logger.debug('Formatting hit {0}'.format(hit.get_seq_id()))64 #add a header line for the target id if not already present65 if hit.get_target_id() not in self.sq_lines:66 if hit.get_target_id()[-2:] != 'RC':67 self.sq_lines[hit.get_target_id()] = hit.get_sam_sq()68 else:69 self.sq_lines[hit.get_target_id()[:-3]] = hit.get_sam_sq()70 71 #add a line for the hit72 self.record_lines.append(hit.get_sam_line())73 def print_results(self):74 '''sets, formats and prints the results to a file.'''75 self.logger.info('formatting results...')76 #format header and hit lines77 for hit in self._get_hits():78 self._format_hit(hit)79 self.logger.debug('printing results...')80 output = open(self.outputfile, 'w')81 #write the header lines to the file82 header_string = '@HD\tVN:1.4\tSO:unknown'83 output.write(header_string + '\n')84 for header_line in self.sq_lines:85 output.write(self.sq_lines[header_line] + '\n')86 #program information header line87 output.write('@PG\tID:0\tPN:paswas\tVN:3.0\n')88 #write the hit lines to the output file89 for line in self.record_lines:90 output.write(line + '\n')91 output.close()92 self.logger.debug('finished printing results')93class TrimmerFormatter(DefaultFormatter):94 '''This Formatter is used to create SAM output95 See http://samtools.sourceforge.net/SAM1.pdf96 '''97 def __init__(self, logger, hitlist, outputfile):98 '''Since the header contains information about the target sequences and must be99 present before alignment lines, formatted lines are stored before printing.100 '''101 DefaultFormatter.__init__(self, logger, hitlist, outputfile)102 self.sq_lines = {}103 self.record_lines = []104 def _set_name(self):105 '''Name of the formatter. Used for logging'''106 self.name = 'SAM formatter'107 def _format_hit(self, hit):108 '''Adds a header line to self.sq_lines and an alignment line to self.record_lines.109 The following mappings are used for header lines:110 SN: hit.get_target_id()111 LN: hit.full_target.original_length112 '''113 self.logger.debug('Formatting hit {0}'.format(hit.get_seq_id()))114 self.record_lines.append(hit.get_trimmed_line())115 def print_results(self):116 '''sets, formats and prints the results to a file.'''117 self.logger.info('formatting results...')118 #format header and hit lines119 for hit in self._get_hits():120 self._format_hit(hit)121 self.logger.debug('printing results...')122 output = open(self.outputfile, 'w')123 #write the hit lines to the output file124 for line in self.record_lines:125 output.write(line + '\n')126 output.close()127 self.logger.debug('finished printing results')128class FASTA(DefaultFormatter):129 '''This Formatter is used to create FASTA output130 '''131 def __init__(self, logger, hitlist, outputfile):132 '''Since the header contains information about the target sequences and must be133 present before alignment lines, formatted lines are stored before printing.134 '''135 DefaultFormatter.__init__(self, logger, hitlist, outputfile)136 self.sq_lines = {}137 self.record_lines = []138 def _set_name(self):139 '''Name of the formatter. Used for logging'''140 self.name = 'FASTA formatter'141 def _format_hit(self, hit):142 '''Adds a header line to self.sq_lines and an alignment line to self.record_lines.143 The following mappings are used for header lines:144 SN: hit.get_target_id()145 LN: hit.full_target.original_length146 '''147 self.logger.debug('Formatting hit {0}'.format(hit.get_seq_id()))148 self.record_lines.append(hit.get_full_fasta())149 def print_results(self):150 '''sets, formats and prints the results to a file.'''151 self.logger.info('formatting results...')152 #format header and hit lines153 for hit in self._get_hits():154 self._format_hit(hit)155 self.logger.debug('printing results...')156 output = open(self.outputfile, 'w')157 #write the hit lines to the output file158 for line in self.record_lines:...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!