def extractLeadAnnotation(lead: Lead) -> Annotation.LeadAnnotation: return Annotation.LeadAnnotation( Annotation.CropLocation( lead.x, lead.y, lead.width, lead.height, ), lead.startTime)
def saveAnnotations(self): inputParameters = self.getCurrentInputParameters() if self.window.editor.image is None: return assert self.openFile is not None def extractLeadAnnotation(lead: Lead) -> Annotation.LeadAnnotation: return Annotation.LeadAnnotation( Annotation.CropLocation( lead.x, lead.y, lead.width, lead.height, ), lead.startTime) metadataDirectory = self.openFile.parent / '.paperecg' if not metadataDirectory.exists(): metadataDirectory.mkdir() filePath = metadataDirectory / (self.openFile.stem + '-' + self.openFile.suffix[1:] + '.json') print("leads\n", inputParameters.leads.items()) leads = { name: extractLeadAnnotation(lead) for name, lead in inputParameters.leads.items() } currentDateTime = ( datetime.datetime.now()).strftime("%m/%d/%Y, %H:%M:%S") Annotation.Annotation(timeStamp=currentDateTime, image=Annotation.ImageMetadata( self.openFile.name, directory=str( self.openFile.parent.absolute())), rotation=inputParameters.rotation, timeScale=inputParameters.timeScale, voltageScale=inputParameters.voltScale, leads=leads).save(filePath) print("Metadata successfully saved to:", str(filePath)) self.window.editor.EditPanelGlobalView.setLastSavedTimeStamp( currentDateTime)
def loadAnnotation(self): if self.ann: ret = QMessageBox.question( self, "Load annotation", "Save current annotations before loading?", QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel, ) if ret == QMessageBox.Yes: self.onButtonSave() elif ret == QMessageBox.Cancel: return dir = "./" if self.ann: dir = self.ann.annotationDir fileName = QFileDialog.getOpenFileName( self, "Load annotation list from file", dir, "All Files (*);;Text Files (*.txt)" ) if fileName: print fileName self.ann = Annotation(fileName) self.startUp = True self.updateClassNamesView() self.imageListTable.updateTableView(self.ann) self.imageListTable.select(0, 0)
def loadImageDir(self): if self.ann: ret = QMessageBox.question( self, "Load annotation", "Save current annotations before loading?", QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel, ) if ret == QMessageBox.Yes: self.onButtonSave() elif ret == QMessageBox.Cancel: return if self.imageDir is None: self.imageDir = "/home/bastan/research/sicura/data" fd = QFileDialog(None, "Select image folder", self.imageDir, "*.png") # fd = QFileDialog(None, "Select image folder", ".", "*.png") fd.setFileMode(QFileDialog.Directory) fd.setNameFilter("*.png;;*.jpg;;*.jpeg;;*.pgm;;*.*") if fd.exec_() == QDialog.Rejected: return fileExt = fd.selectedNameFilter() # load the image file names from the selected directory self.ann = Annotation() self.ann.loadDir(fd.directory().absolutePath(), fd.directory().dirName(), fd.selectedNameFilter()) self.startUp = True self.updateClassNames() self.imageListTable.updateTableView(self.ann) self.imageListTable.select(0, 0) # select and goto the first image
def merge_voc(an1, an2): an = Annotation() if an1.width != an2.width or an1.height != an2.height or an1.depth != an2.depth or an1.filename != an2.filename: return None an.filename = an1.filename an.width = an1.width an.height = an1.height an.depth = an1.depth an.objs = an1.objs + an2.objs return an
def getCellsByTableID(TableID,db): rows = db.getTableCellsWithTableArticleData(TableID) cells = [] for row in rows: cell = Cell.Cell() cell.idArticle = row[20] cell.idPMC = row[24] cell.idTable = row[13] cell.tableOrder = row[14] cell.pragmaticClass = row[22] cell.idCell = row[0] cell.cellID = row[1] cell.cellType = row[2] cell.rowN = row[4] cell.columnN = row[5] cell.Content = row[9] cell.Header = row[10] cell.Stub = row[11] cell.Super_row = row[12] cell.HeaderId = row[6] cell.StubId = row[7] cell.SuperRowId = row[8] roles = db.getCellRole(cell.idCell) for role in roles: if role[0]==1: cell.isHeader = True if role[0]==2: cell.isStub = True if role[0]==3: cell.isData = True if role[0]==4: cell.isSuperRow = True annotations = db.getCellAnnotation(cell.idCell) cell_annotations = [] if(annotations!= None): for ann in annotations: Annot = Annotation.Annotation() Annot.annotationID = ann[0] Annot.Content = ann[1] Annot.Start = ann[2] Annot.End = ann[3] Annot.AnnotationCID = ann[4] Annot.AnnotationDesc =ann[5] Annot.AgentName = ann[6] Annot.AgentType = ann[7] Annot.AnnotationURL = ann[8] cell_annotations.append(Annot) cell.Annotations = cell_annotations cells.append(cell) return cells
class MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() self.createMenus() # annotations, image list, etc. self.ann = None self.imageDir = None # current image shown piximage = None self.startUp = True ## drawing scene and view on the right self.sceneDraw = ImageDrawScene(self) self.sceneDraw.setBackground(piximage) self.viewDraw = GraphicsView(self.sceneDraw, QGraphicsView.NoDrag) self.viewDraw.installEventFilter(self) self.viewDraw.setStatusTip("Painting area") ## list of objects scene and view on the left self.sceneList = ObjectListScene(self) self.sceneList.setImage(piximage) self.viewList = GraphicsView(self.sceneList, QGraphicsView.RubberBandDrag) self.viewList.setRubberBandSelectionMode(Qt.ContainsItemShape) self.viewList.installEventFilter(self) self.viewList.setStatusTip("List of already selected objects") ## list of images self.imageListTable = ImageTable(10, 3, self) # text fields for class/subclass name classLabel = QLabel("Class:") subclassLabel = QLabel("Subclass:") self.classText = QLineEdit("bottle") self.subclassText = QLineEdit("glass") self.connect(self.classText, SIGNAL("editingFinished()"), self.updateClassNames) self.connect(self.subclassText, SIGNAL("editingFinished()"), self.updateClassNames) ## buttons - todo: setShortcut (self, QKeySequence key) buttonPrev = QPushButton("Previous", self) buttonPrev.setIcon(QIcon("./icons/prev.png")) buttonPrev.setStatusTip("Save and go to the previous image [ shortcut: Ctrl + Space ]") buttonPrev.setShortcut(QKeySequence(Qt.CTRL + Qt.Key_Space)) self.connect(buttonPrev, SIGNAL("clicked()"), self.onButtonPrev) buttonNext = QPushButton("Next", self) buttonNext.setIcon(QIcon("./icons/next.png")) buttonNext.setStatusTip("Save and go to the next image [ shortcut: Space ]") buttonNext.setShortcut(QKeySequence(Qt.Key_Space)) self.connect(buttonNext, SIGNAL("clicked()"), self.onButtonNext) buttonAddObject = QPushButton("Add", self) buttonAddObject.setIcon(QIcon("./icons/add.png")) buttonAddObject.setStatusTip("Add the selected object [ shortcut: Ctrl + A ]") buttonAddObject.setShortcut(QKeySequence("Ctrl+a")) self.connect(buttonAddObject, SIGNAL("clicked()"), self.onButtonAddObject) buttonDeleteObject = QPushButton("Delete", self) buttonDeleteObject.setIcon(QIcon("./icons/delete.png")) buttonDeleteObject.setStatusTip("Delete the selected object(s) [ shortcut: Del ]") buttonDeleteObject.setShortcut(QKeySequence(QKeySequence.Delete)) # Delete key self.connect(buttonDeleteObject, SIGNAL("clicked()"), self.onButtonDeleteObject) buttonResetPaint = QPushButton("Reset", self) buttonResetPaint.setIcon(QIcon("./icons/refresh.png")) buttonResetPaint.setStatusTip("Clear/reset the painting on the right image") self.connect(buttonResetPaint, SIGNAL("clicked()"), self.onButtonResetPaint) buttonSave = QPushButton("Save", self) buttonSave.setIcon(QIcon("./icons/save.png")) buttonSave.setStatusTip("Save annotations [ shortcut: Ctrl + S ]") buttonSave.setShortcut(QKeySequence(QKeySequence.Save)) # Ctrl + S self.connect(buttonSave, SIGNAL("clicked()"), self.onButtonSave) buttonExit = QPushButton("Exit", self) buttonExit.setIcon(QIcon("./icons/exit.png")) buttonExit.setStatusTip("Exit the application [ shortcut: Ctrl + Q ]") self.connect(buttonExit, SIGNAL("clicked()"), self.close) # drawing/painting/brush type combo box dtypeComboBox = QComboBox() # BRUSH_TYPES_STR = [ "Line", "Ellipse", "Rectangle", "Rounded rectangle"] --- global variable dtypeComboBox.addItems(BRUSH_TYPES_STR) dtypeComboBox.setStatusTip("Brush type for painting on the image") self.connect(dtypeComboBox, SIGNAL("activated(int)"), self.changeBrushType) typeLabel = QLabel("&Brush type:") typeLabel.setBuddy(dtypeComboBox) self.buttonBrushColor = QPushButton("Brush color", self) self.buttonBrushColor.setIcon(QIcon(self.getColorRectImage(BRUSH_COLOR))) self.brushColor = BRUSH_COLOR self.buttonBrushColor.setStatusTip("Select brush color") self.connect(self.buttonBrushColor, SIGNAL("clicked()"), self.changeBrushColor) ## slider for brush size brushSizeSlider = QSlider(Qt.Horizontal, self) brushSizeSlider.setMinimum(1) brushSizeSlider.setMaximum(100) brushSizeSlider.setTickPosition(QSlider.TicksAbove) brushSizeSlider.setTickInterval(10) brushSizeSlider.setSingleStep(1) brushSizeSlider.setValue(BRUSH_RADIUS) self.changeBrushRadius(BRUSH_RADIUS) brushSizeSlider.setStatusTip("Brush radius, for painting on the image") self.connect(brushSizeSlider, SIGNAL("valueChanged(int)"), self.changeBrushRadius) ## status bar self.statusBar = QStatusBar(self) self.setStatusBar(self.statusBar) ### Layouts ### # images & image list in the center layoutC = QHBoxLayout() layoutC.addWidget(self.viewList) layoutC.addSpacing(20) layoutC.addWidget(self.viewDraw) layoutC.addSpacing(20) layoutR0 = QHBoxLayout() layoutR0.addWidget(classLabel) layoutR0.addStretch(0) layoutR0.addWidget(self.classText) layoutR0.addSpacing(5) layoutR0.addWidget(subclassLabel) layoutR0.addStretch(0) layoutR0.addWidget(self.subclassText) layoutR1 = QHBoxLayout() layoutR1.addWidget(typeLabel) layoutR1.addStretch(0) layoutR1.addWidget(dtypeComboBox) layoutR1.addSpacing(10) layoutR1.addWidget(self.buttonBrushColor) layoutR = QVBoxLayout() layoutR.addItem(layoutR0) layoutR.addSpacing(10) layoutR.addWidget(self.imageListTable) layoutR.addSpacing(10) layoutR.addItem(layoutR1) layoutR.addSpacing(5) layoutR.addWidget(brushSizeSlider) layoutC.addItem(layoutR) # layout for controls at the bottom layoutB = QHBoxLayout() layoutB.addWidget(buttonPrev) layoutB.addSpacing(20) layoutB.addWidget(buttonNext) layoutB.addSpacing(60) layoutB.addWidget(buttonDeleteObject) layoutB.addSpacing(20) layoutB.addWidget(buttonAddObject) layoutB.addSpacing(20) layoutB.addWidget(buttonResetPaint) layoutB.addSpacing(60) layoutB.addWidget(buttonSave) layoutB.addSpacing(20) layoutB.addWidget(buttonExit) layout = QVBoxLayout() layout.addItem(layoutC) layout.addSpacing(10) layout.addItem(layoutB) self.widget = QWidget() self.widget.setLayout(layout) self.setCentralWidget(self.widget) self.setWindowTitle("XRanT : X-Ray Annotation Tool") self.setWindowIcon(QIcon("./icons/x-icon.png")) # self.setWindowIcon(QIcon('./icons/xray-icon.png')) self.statusMessage("XRanT ready. Browse an image directory to get started [File/Ctrl-O]") def createMenus(self): menuBar = self.menuBar() ## File menu self.fileMenu = menuBar.addMenu("&File") self.fileOpenImageDir = QAction("&Open image directory..", self, shortcut="Ctrl+O", triggered=self.loadImageDir) self.fileOpenImageDir.setStatusTip("Select the directory containing the images to annotate") self.fileMenu.addAction(self.fileOpenImageDir) self.changeAnnDir = QAction("Change output directory..", self, triggered=self.changeAnnotationDir) self.changeAnnDir.setStatusTip("Change the current output directory to any directory") self.fileMenu.addAction(self.changeAnnDir) self.fileMenu.addSeparator() self.saveAll = QAction("Save all", self, triggered=self.onButtonSave) self.saveAll.setStatusTip("Save annotation list and current objects to default files") self.fileMenu.addAction(self.saveAll) self.saveAnnAs = QAction("Save a copy of annotation list as..", self, triggered=self.saveAnnotationAs) self.saveAnnAs.setStatusTip("Save a copy of annotation list to a specified file") self.fileMenu.addAction(self.saveAnnAs) self.fileMenu.addSeparator() self.loadAnn = QAction("Load annotation list..", self, triggered=self.loadAnnotation) self.loadAnn.setStatusTip("Load existing annotation list from file") self.fileMenu.addAction(self.loadAnn) self.fileMenu.addSeparator() self.fileExitAct = QAction("E&xit", self, shortcut="Ctrl+Q", triggered=self.close) self.fileExitAct.setStatusTip("Exit the application!") self.fileMenu.addAction(self.fileExitAct) self.helpMenu = menuBar.addMenu("&Help") self.helpAbout = QAction("&About", self, triggered=self.helpAbout) self.helpMenu.addAction(self.helpAbout) ### ### ### Event handling ### ### ### # handle previous/next image button events def onButtonPrev(self): ind = self.ann.prev() if ind != self.ann.index: self.imageListTable.select(ind, 0) def onButtonNext(self): ind = self.ann.next() if ind != self.ann.index: self.imageListTable.select(ind, 0) def onButtonAddObject(self): self.addObject() def onButtonDeleteObject(self): self.sceneList.deleteSelectedObjects() def onButtonResetPaint(self): self.sceneDraw.resetForeground() # TODO: ask overwrite def onButtonSave(self): if self.ann is not None: self.ann.saveCurrentObjectMasks() self.ann.saveAnnotationList() else: print "Nothing to save!" def closeEvent(self, event): if self.ann: ret = QMessageBox.question( self, "Exit application", "Save all (annotation list + unsaved masks) before exit?", QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel, ) if ret == QMessageBox.Yes: self.onButtonSave() elif ret == QMessageBox.Cancel: event.ignore() print "Cancel" return event.accept() ### FUNCTIONS ### # TODO: ask overwrite def saveAnnotationAs(self): if not self.ann: return fileName = QFileDialog.getSaveFileName( self, "Save a copy of annotation list as", self.ann.annotationDir + self.ann.getAnnotationListFile(), "All Files (*);;Text Files (*.txt)", ) if fileName: self.ann.saveAnnotationListAs(fileName) def loadAnnotation(self): if self.ann: ret = QMessageBox.question( self, "Load annotation", "Save current annotations before loading?", QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel, ) if ret == QMessageBox.Yes: self.onButtonSave() elif ret == QMessageBox.Cancel: return dir = "./" if self.ann: dir = self.ann.annotationDir fileName = QFileDialog.getOpenFileName( self, "Load annotation list from file", dir, "All Files (*);;Text Files (*.txt)" ) if fileName: print fileName self.ann = Annotation(fileName) self.startUp = True self.updateClassNamesView() self.imageListTable.updateTableView(self.ann) self.imageListTable.select(0, 0) def changeAnnotationDir(self): if not self.ann: print "No annotation yet!" return options = QFileDialog.DontResolveSymlinks | QFileDialog.ShowDirsOnly directory = QFileDialog.getExistingDirectory( self, "Select output annotation directory", self.ann.annotationDir, options ) if directory: self.ann.setAnnotationDir(directory) def loadImageDir(self): if self.ann: ret = QMessageBox.question( self, "Load annotation", "Save current annotations before loading?", QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel, ) if ret == QMessageBox.Yes: self.onButtonSave() elif ret == QMessageBox.Cancel: return if self.imageDir is None: self.imageDir = "/home/bastan/research/sicura/data" fd = QFileDialog(None, "Select image folder", self.imageDir, "*.png") # fd = QFileDialog(None, "Select image folder", ".", "*.png") fd.setFileMode(QFileDialog.Directory) fd.setNameFilter("*.png;;*.jpg;;*.jpeg;;*.pgm;;*.*") if fd.exec_() == QDialog.Rejected: return fileExt = fd.selectedNameFilter() # load the image file names from the selected directory self.ann = Annotation() self.ann.loadDir(fd.directory().absolutePath(), fd.directory().dirName(), fd.selectedNameFilter()) self.startUp = True self.updateClassNames() self.imageListTable.updateTableView(self.ann) self.imageListTable.select(0, 0) # select and goto the first image def toImage(self, index): if self.ann is not None: if not self.startUp: self.ann.saveCurrentObjectMasks() self.ann.deleteObjectMasks() index = self.ann.goto(index) self.ann.loadObjectImages(index, self.brushColor, False) self.imageListTable.updateTableRow(self.ann, self.ann.index) self.sceneList.clear() self.showCurrentImage() self.startUp = False print "Image", index + 1 # load the current image from disk and display it def showCurrentImage(self): if self.ann is not None and self.ann.numImages() > 0: imageFile = self.ann.curImagePath() if os.path.exists(imageFile): piximage = QPixmap(imageFile) self.showImage(piximage) def showImage(self, piximage): self.sceneList.setImage(piximage) self.sceneList.addObjects(self.ann.image(self.ann.index)) self.viewList.fitImageView() self.sceneList.update() self.sceneDraw.setImage(piximage) self.viewDraw.fitImageView() self.sceneDraw.update() # add the selected object to the scene and to the list of annotations def addObject(self): mask = self.sceneDraw.getObjectMask() x1, y1, w, h = getMBR_numpy(mask) if x1 < 0: return objImg = self.sceneDraw.foregroundImage.copy(x1, y1, w, h) self.sceneList.addObjectImage(objImg, x1, y1) self.sceneDraw.resetForeground() self.ann.addObject(mask, objImg, x1, y1, self.sceneList.objID) self.imageListTable.updateTableRow(self.ann, self.ann.index) def updateClassNames(self): className = self.classText.text() subclassName = self.subclassText.text() if len(className) < 1: className = "none" if len(subclassName) < 1: subclassName = "none" if self.ann is not None: self.ann.setClassName(className, subclassName) print "Updated class names and directories" def updateClassNamesView(self): className = self.ann.className subclassName = self.ann.subclassName if len(className) < 1 or className == "none": self.classText.setText("") else: self.classText.setText(className) if len(subclassName) < 1 or subclassName == "none": self.subclassText.setText("") else: self.subclassText.setText(subclassName) def changeBrushRadius(self, value): self.sceneDraw.setRadius(value) def changeBrushType(self, value): self.sceneDraw.setBrushType(BRUSH_TYPES_INT[value]) def getColorRectImage(self, color, w=80, h=60): qimage = QImage(w, h, QImage.Format_ARGB32_Premultiplied) qimage.fill(color.rgba()) return QPixmap.fromImage(qimage) def changeBrushColor(self): cd = QColorDialog(self.sceneDraw.dcolor) cd.setOption(QColorDialog.ShowAlphaChannel, True) cd.exec_() color = cd.selectedColor() self.sceneDraw.setBrushColor(color) self.buttonBrushColor.setIcon(QIcon(self.getColorRectImage(color))) self.brushColor = color def statusMessage(self, message): self.statusBar.showMessage(message) def helpAbout(self): QMessageBox.about( self, "About XRanT", "<b>XRanT: X-Ray Annotation Tool</b><br>" "Author: Muhammet Bastan<br>IUPR @TU-KL<br>[email protected]<br>July 2011", )
标注进行纠正,保存到指定目录 ''' in_anno_dir = 'E:/DataSet/VOCdevkit/VOC2007/Annotations_bak' in_img_dir = 'E:/DataSet/VOCdevkit/VOC2007/JPEGImages' out_anno_dir = 'E:/DataSet/VOCdevkit/VOC2007/Annotations' #out_img_dir = 'E:/DataSet/hand_face/image' annotaion_list = os.listdir(in_anno_dir) index = 0 for annotation_file in annotaion_list: print(index, ' :', annotation_file, 'is process...') index = index + 1 annotation_path = os.path.join(in_anno_dir, annotation_file) anno = Annotation() flag = anno.read_from_xml(annotation_path) if flag == False: continue if len(anno.objs) == 0: continue img_name = anno.filename img_path = os.path.join(in_img_dir, img_name) img = io.imread(img_path) anno.height = img.shape[0] anno.width = img.shape[1] anno.depth = img.shape[2] anno.check() #out_img_path = os.path.join(out_img_dir, img_name) #io.imsave(out_img_path, img) out_anno_path = os.path.join(out_anno_dir, annotation_file)
import Core import Core.Stats import Plot import Annotation import matplotlib.pyplot as pp annotations = Annotation.Annotator() print ("probe No:", annotations.get_number()) annotations.remove_snp_probes() print ("probe No after SNP removal:", annotations.get_number()) file = "Data/GSE42308.txt" samples = Core.ParseFile(file).get_samples() # samples2 = Core.ParseBatch("Data/").get_all_samples() probes = annotations.get_probes(annotations.get_all_probe_ids()) print(len(probes)) probe2 = Annotation.get_probes_from_feature(probes, Annotation.Feature(Annotation.CpG_location.ISLAND)) print(len(probe2)) probe3 = Annotation.get_probes_from_feature(probe2, Annotation.Feature("BRCA1")) print(len(probe3)) brcaprobes = annotations.get_probes(annotations.get_probes_id_from_gene("BRCA1")) #groups= [groups[0], groups[3]] Plot.BoxPlot(probes, samples) # probe_list = annotations.get_probes_from_gene("TP53") # probe_list2 =annotations.get_probes_id_from_loc(Annotation.Location.BODY)
def get_normal_freq(audio_file, tuning): return frequency( Annotation.from_wav(audio_file.name + ".wav").fret, tuning.tuning[Annotation.from_wav(audio_file.name + ".wav").string - 1])
def load_database(config): audio_path = config.audio_path annotation_path = config.annotation_path tuning_path = config.tuning_path audio_files = [] annotations = [] tuning_files = [] # AUDIO ------------------------------------ if config.idmt: for filename in os.listdir(audio_path): if filename.endswith(".wav"): sample_rate, audio_source = wavfile.read( os.path.join(audio_path, filename)) a_s, s_r = ap.idmt_preprocessing(audio_source, sample_rate) audio_file = Audio.make_audio(a_s, a_s, s_r, filename, audio_path) audio_files.append(audio_file) else: continue else: for string in range(1, config.no_strings + 1): string_path = audio_path + str(string) for filename in os.listdir(string_path): if filename.endswith(".wav"): sample_rate, audio_source = wavfile.read( os.path.join(string_path, filename)) a_s_left, a_s_right, s_r = ap.pre_processing( audio_source, sample_rate) audio_file = Audio.make_audio(a_s_left, a_s_right, s_r, filename, string_path) audio_files.append(audio_file) else: continue # ANNOTATION ------------------------------------ if config.idmt: for filename in os.listdir(annotation_path): if filename.endswith(".xml"): root = xml.etree.ElementTree.parse( os.path.join(annotation_path, filename)).getroot() annotation = Annotation.from_xml(root) annotations.append(annotation) else: continue else: for string in range(1, config.no_strings + 1): string_path = annotation_path + str(string) for filename in os.listdir(string_path): if filename.endswith(".wav"): annotation = Annotation.from_wav(filename) annotations.append(annotation) else: continue # TUNING ------------------------------------ if config.idmt: for annotation in annotations: if annotation.fret == 0: for a_f in audio_files: if a_f.name == annotation.filename: tuning_files.append(a_f) else: for filename in os.listdir(tuning_path): if filename.endswith(".wav"): sample_rate, audio_source = wavfile.read( os.path.join(tuning_path, filename)) a_s_left, a_s_right, s_r = ap.pre_processing( audio_source, sample_rate) audio_file = Audio.make_audio(a_s_left, a_s_right, s_r, filename, tuning_path) tuning_files.append(audio_file) else: continue tuning = Tuning.estimate_tuning(tuning_files, config) # Filter based on fret-range audio_temp = [] annotation_temp = [] # audio filter for a_f in audio_files: for annotation in annotations: if a_f.name == annotation.filename: if config.max_fret >= annotation.fret >= config.min_fret: audio_temp.append(a_f) annotation_temp.append(annotation) audio_files = audio_temp annotations = annotation_temp # RETURN ------------------------------------ return Database(audio_files, annotations, tuning)
m.GeneParameter1 = gen.getGeneDetailsfromSoup(soup.text, 1) m.GeneParameter2 = gen.getGeneDetailsfromSoup(soup.text, 4) elif type == 2: m.GeneParameter1 = gen.getGeneDetailsfromSoup(soup.text, 1) m.GeneParameter2 = "" else: m.GeneParameter1 = "" m.GeneParameter2 = "" #print(gene) ######################################################################################################################## #This one extract annotation soup = bs.BeautifulSoup(str(rows.pop()), 'lxml') s1 = soup.text.replace(u"Â", "").replace(u"â", "") m.AnnotationTypeID = ann.getAnnotationType(soup.text.replace(u"Â", "")) print m.AnnotationTypeID, s1 m.Annotation = soup.text # Lets see if needed or not if m.AnnotationTypeID == 1: m.AnnotationCodon1 = "" m.AnnotationCodon2 = "" m.AnnotationBracket1 = ann.getAnnotationDetailsfromSoup(s1, 1) m.AnnotationBracket2 = ann.getAnnotationDetailsfromSoup(s1, 2) elif m.AnnotationTypeID == 2: m.AnnotationCodon1 = "" m.AnnotationCodon2 = "" m.AnnotationBracket1 = ann.getAnnotationDetailsfromSoup(s1, 1) m.AnnotationBracket2 = ann.getAnnotationDetailsfromSoup(s1, 2) elif m.AnnotationTypeID == 3: m.AnnotationCodon1 = ann.getAnnotationDetailsfromSoup(s1, 1) m.AnnotationCodon2 = ann.getAnnotationDetailsfromSoup(s1, 3)
""" Chech for the existance of the input filename. :param filename: filename to check. :return: """ return os.path.exists(os.path.abspath(filename)) # USAGE : ./convertbed.py -file Data/GSE42308.txt -out gello.bed -gene DENR parser = argparse.ArgumentParser() parser.add_argument("-file", help="File name that contains average beta values.") parser.add_argument("-out", help="directory that BED files will be stored.") parser.add_argument("-gene", help="Name of gene that BED file will be created for") args = vars(parser.parse_args()) file = os.path.abspath(args["file"]) out = os.path.abspath(args["out"]) if check_file(file): annotations = Annotation.Annotator() parse = Core.ParseFile(file) probe_list = annotations.get_probes_from_gene(args["gene"]) Core.samples_to_bed(out, probe_list, parse.get_samples()) print("Done.") else: print("File does not exist.")
def open_file(self, file_type, filename=None): title = 'Open Video / Images' if file_type == 'video' else 'Open Annotation' file_types = "Video Files (*.avi *.mp4);; Images Files (*.jpg *.bmp *.tif *.tiff *.png)" \ if file_type == 'video' else 'Annotation File (*.atc)' # if working on unsaved annotation if self.annotation and not self.annotation.is_file_saved(): message_box = QtWidgets.QMessageBox() message_box.setText("Annotation has not been saved") message_box.setInformativeText("Create new anyway?") message_box.setStandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No) message_box.setDefaultButton(QtWidgets.QMessageBox.No) ret = message_box.exec_() # user wants not to create new one - do nothing if ret != QtWidgets.QMessageBox.Yes: return # user wants to discard his unsaved temp annotation self.annotation.close() # ask user if no filename given if not filename: # open file (the 'str' - some versions of pyqt return a QString instead of a normal string) filename = str( QtWidgets.QFileDialog.getOpenFileName( QtWidgets.QFileDialog(), title, QtCore.QDir.currentPath(), file_types)[0]) # if user presses 'cancel' in dialog, null string is returned if not filename: return try: # open annotation self.annotation = Annotation.Annotation(filename) # Connect scene to annotation self.scene.set_annotation(self.annotation) # update slider maximum self.frameSlider.setMaximum(self.annotation.num_frames) # enable GUI self.enable_gui(True) # load classes to GUI comboBox self.populate_class_combobox(self.annotation.classes()) # save filename to last video used file (check first that it is not the temporary workspace) if self.annotation.is_file_saved(): pickle.dump(self.annotation.filename(), open(CURRENT_ANNOTATION_FILENAME, "wb")) # set window title self.setWindowTitle('Video Annotation Tool' + ( '*' if file_type == 'video' else self.annotation.filename())) # update self.update() except Annotation.VideoLoadVideoNotFound as e: message_box = QtWidgets.QMessageBox() message_box.setText(str(e)) message_box.setInformativeText( "Would you like to navigate to the new location of the video file?" ) message_box.setStandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No) message_box.setDefaultButton(QtWidgets.QMessageBox.Yes) ret = message_box.exec_() if ret == QtWidgets.QMessageBox.Yes: filename = self.provide_video_location() annotation_file = Annotation.Annotation.update_video_filename_in_annotation( e.filename, filename) if self.annotation: self.annotation.close() del self.annotation self.annotation = None self.open_file('annotation', annotation_file) # self.annotation = Annotation.Annotation(annotation_file) # self.update() # file reading failed except (Annotation.AnnotationFileError, Annotation.VideoLoadError) as e: message_box = QtWidgets.QMessageBox() message_box.setText(str(e)) message_box.setStandardButtons(QtWidgets.QMessageBox.Ok) message_box.setDefaultButton(QtWidgets.QMessageBox.Ok) message_box.exec_()
geneHandle = open(gene_file,'w') geneHandle.write("Genome:\t{}\n".format(bacterium)) geneDict = {} # This dictionary will ultimately contain the gene names granting resistance to eacha ntibiotic for # output to <gene_file> wildType = pm.import_wt(organism,DRUGSdb) # Identify and store any wt amino acid sequences that will be needed #letterCode = {"Susceptible":"S","Intermediate":"I","Unknown":"U","Resistant":"R"} # These two lines initialize the prediction output. The antibioticLine is actually the headers for an output table # with one row, which is the prediction line. antibioticLine = "Genome" # header for first column of the output table (a.k.a. organism name) predictionLine = os.path.basename(annotationFile) # Organism name for the output table # The following lines each store, for the different antibiotic classes, words in the annotation that distinguish # each specific type of resistance gene betaList = Annotation.import_list(DRUGSdb + "beta_lactamase_keywords.txt") tetList = Annotation.import_list(DRUGSdb + "tetracycline_names.txt") aminoglyList = Annotation.import_list(DRUGSdb + "aminoglycoside_names.txt") ciproList = Annotation.import_list(DRUGSdb + "ciprofloxacin_names.txt") trsxList = Annotation.import_list(DRUGSdb + "trimethoprim_sulfamethoxazole_names.txt") chlorList = Annotation.import_list(DRUGSdb + "chloramphenicol_names.txt") listList = [betaList,tetList,aminoglyList,ciproList,trsxList,chlorList] # Easy storage for the keywords # This list corresponds to the antibiotic categories of the keyword list above antibioticList = ["Beta-lactamase","Tetracycline","Aminoglycoside","Fluoroquinolone","Bactrim","Chloramphenicol"] annotationDict,resfam_positive = Annotation.import_annotations_Mitch(annotationFile) # A function that stores the # annotations from a HMM output file created specifically with my (Mitch's) version of the HMM annotator. If you # need to be reading these comments then this function probably needs to be updated for your application. The # resfam_positive dictionary contains a boolean value for whether any annotations for a gene were from resfams.
anno_list2 = os.listdir(input_anno_dir2) def merge_voc(an1, an2): an = Annotation() if an1.width != an2.width or an1.height != an2.height or an1.depth != an2.depth or an1.filename != an2.filename: return None an.filename = an1.filename an.width = an1.width an.height = an1.height an.depth = an1.depth an.objs = an1.objs + an2.objs return an anno_set = [] for anno_file1 in anno_list1: an1 = Annotation() an1.read_from_xml(os.path.join(input_anno_dir1, anno_file1)) bfind = 0 for anno_file2 in anno_list2: if anno_file1 == anno_file2: anno_list2.remove(anno_file2) bfind = 1 break if bfind: an2 = Annotation() an2.read_from_xml(os.path.join(input_anno_dir2, anno_file2)) an = merge_voc(an1, an2) anno_set.append(an) else: anno_set.append(an1)
if args.genes: geneFile = os.path.splitext(os.path.basename(args.blastFile))[0] + ".genes" geneHandle = open(geneFile,'w') DRUGSdb = "ReferenceFiles/" betaLactamProFile = DRUGSdb + args.blacProfile beta_lactams,bLacProfile = pm.import_profile(betaLactamProFile) wildType = pm.import_wt(args.org,DRUGSdb) letterCode = {"Susceptible":"S","Intermediate":"I","Unknown":"U","Resistant":"R"} antibioticLine = "Genome" predictionLine = os.path.basename(args.blastFile) betaList = Annotation.import_list(DRUGSdb + "RF_beta-lactamase_keywords.txt") tetList = Annotation.import_list(DRUGSdb + "RF_tetracycline_keywords.txt") aminoglyList = Annotation.import_list(DRUGSdb + "RF_aminoglycoside_keywords.txt") ciproList = Annotation.import_list(DRUGSdb + "RF_quinolone_keywords.txt") trsxList = Annotation.import_list(DRUGSdb + "RF_TRSX_keywords.txt") chlorList = Annotation.import_list(DRUGSdb + "RF_phenicol_keywords.txt") listList = [betaList,tetList,aminoglyList,ciproList,trsxList,chlorList] antibioticList = ["Beta-lactamase","Tetracycline","Aminoglycoside","Fluoroquinolone","Bactrim","Chloramphenicol"] annotationDict,resfam_positive = Annotation.import_annotations_blast(args.blastFile) geneList = [] for annotation in annotationDict.keys(): name = annotationDict[annotation]