def MakeReference(self): if not os.path.isfile(self.strRefFile): with open(self.strBarcodeFile) as Barcode, \ open(self.strTargetSeqFile) as Target, \ open(self.strReferenceSeqFile) as Ref, \ open(self.strRefFile, 'w') as Output: listBarcode = Helper.RemoveNullAndBadKeyword(Barcode) listTarget = Helper.RemoveNullAndBadKeyword(Target) listRef = Helper.RemoveNullAndBadKeyword(Ref) ## defensive assert len(listBarcode) == len(listTarget) == len(listRef), 'Barcode, Target and Reference must be a same row number.' listName = [] for strBar, strTar in zip(listBarcode, listTarget): strBar = strBar.replace('\n', '').replace('\r', '').strip().upper() strTar = strTar.replace('\n', '').replace('\r', '').strip().upper() Helper.CheckIntegrity(self.strBarcodeFile, strBar) ## defensive Helper.CheckIntegrity(self.strBarcodeFile, strTar) ## defensive listName.append(strBar + ':' + strTar + '\n') for i, strRow in enumerate(listRef): strRow = strRow.replace('\r', '').strip().upper() Output.write('>' + listName[i] + strRow + '\n')
def MakeReference(self): with open(self.strBarcodeFile) as Barcode, \ open(self.strReferenceSeqFile) as Ref, \ open(self.strRefFile, 'w') as Output: listBarcode = Helper.RemoveNullAndBadKeyword(Barcode) listRef = Helper.RemoveNullAndBadKeyword(Ref) ## defensive assert len(listBarcode) == len( listRef), 'Barcode and Reference must be a same row number.' dictBarcode = {} for strBarcode in listBarcode: strBarcode = strBarcode.replace('\n', '').replace('\r', '').upper() Helper.CheckIntegrity(self.strBarcodeFile, strBarcode) ## defensive listBarcode = strBarcode.split(':') strBarSample = listBarcode[0] strBarcode = listBarcode[1] dictBarcode[strBarSample] = strBarcode for strRef in listRef: strRef = strRef.replace('\n', '').replace('\r', '').upper() Helper.CheckIntegrity(self.strBarcodeFile, strRef) ## defensive listRef = strRef.split(':') strRefSample = listRef[0] strRef = listRef[1] try: sBarcode = dictBarcode[strRefSample] Output.write('%s\t%s\t%s\n' % (strRefSample, sBarcode, strRef)) except KeyError: logging.error('no matching') logging.error(strRefSample, strRef)