"Otherwise, lines will be added for any individual mentioned in the file.") for k,d in Pedigree.REQUIRED_KEYS.iteritems(): parser.add_argument('--%s'%k, type=str, dest=k, default=d, help='Override the column header for %s. Default is "%s".' % (k,d)) for k,d in Pedigree.RESERVED_KEYS.iteritems(): parser.add_argument('--%s'%k, type=str, dest=k, default=d, help='Override the column header for %s. Default is "%s".' % (k,d)) args = parser.parse_args() for k in Pedigree.REQUIRED_KEYS.keys(): Pedigree.REQUIRED_KEYS[k] = getattr(args,k) for k in Pedigree.RESERVED_KEYS.keys(): Pedigree.RESERVED_KEYS[k] = getattr(args,k) print "Loading file..." ped = Pedigree(args.infile, countAndCalculate=True, zeroMissing=args.zeroMissing.strip().upper().startswith('T'), tickFunction=tick, numTicks = 100) print "Writing file..." lowPath = args.outfile.lower() if lowPath.endswith('.gexf'): edgeTypes = Pedigree.defaultEdgeTypes() nodeAttributeTypes = Pedigree.defaultNodeAttributeTypes() nodeAttributeTypes['is_root'] = gexf_node_attribute_mapper('is_root', attrType=gexf_node_attribute_mapper.BOOLEAN, defaultValue=False, validValues=[False,True]) # Write the graph file ped.write_gexf(args.outfile, edgeTypes, nodeAttributeTypes) elif lowPath.endswith('.json'): ped.write_json(args.outfile) elif lowPath.endswith('.dot'): ped.write_dot(args.outfile) elif lowPath.endswith('.png'): program = lowPath[:-4].split('.')[-1]
def go(self): global visWindow for k in Pedigree.REQUIRED_KEYS.keys(): t = self.overrides[k].currentText() if t == '': self.displayError("%s header is required." % k) return elif not t in self.header: self.displayError("%s doesn't exist in the input file." % t) return Pedigree.REQUIRED_KEYS[k] = t for k in Pedigree.RESERVED_KEYS.keys(): t = self.overrides[k].currentText() if self.window.programBox.currentText() == 'vis': if t == '': self.displayError("%s header is required." % k) return elif not t in self.header: self.displayError("%s doesn't exist in the input file." % t) return else: if t == '': t = k Pedigree.RESERVED_KEYS[k] = t try: if self.window.programBox.currentText() == 'vis': fileName = self.window.inputField.text() if fileName.lower().endswith('.gexf') or fileName.lower().endswith('.json'): raise Exception('.gexf and .json formats are not supported for the vis program. Use calculateD to create a .dat file.') ped = Pedigree(fileName, countAndCalculate=False, zeroMissing=self.window.zeroMissingBox.isChecked()) from resources.main_app import App self.window.hide() visWindow = App(ped) self.window.close() else: progress = QProgressDialog(u"Running...", u"Cancel", 0, NUM_TICKS, parent=None) progress.setWindowModality(Qt.WindowModal) progress.show() def tick(newMessage=None, increment=1): if progress.wasCanceled(): raise cancelException('Cancel clicked.') newValue = min(progress.maximum(),progress.value()+increment) progress.setValue(newValue) if newMessage != None: progress.setLabelText(newMessage) return True ped = Pedigree(self.window.inputField.text(), countAndCalculate=True, zeroMissing=self.window.zeroMissingBox.isChecked(), tickFunction=tick, numTicks=NUM_TICKS) progress.setLabelText('Writing File...') extension = os.path.splitext(self.window.outputField.text())[1].lower() if extension == '.gexf': edgeTypes = Pedigree.defaultEdgeTypes() nodeAttributeTypes = Pedigree.defaultNodeAttributeTypes() nodeAttributeTypes['is_root'] = gexf_node_attribute_mapper('is_root', attrType=gexf_node_attribute_mapper.BOOLEAN, defaultValue=False, validValues=[False,True]) ped.write_gexf(self.window.outputField.text(), edgeTypes, nodeAttributeTypes) elif extension == '.json': ped.write_json(self.window.outputField.text()) else: ped.write_egopama(self.window.outputField.text()) progress.close() self.window.inputField.setText(self.window.outputField.text()) self.window.outputField.setText("") self.window.programBox.setCurrentIndex(1) except Exception, e: if not isinstance(e, cancelException): self.displayError("An unexpected error occurred.",traceback.format_exc())