def call_gengraph(fiber_fn, roi_xml_fn, roi_raw_fn, graphs, graphInvariants, graphsize, run = False): ''' Run graph building and other related scripts @param fiber_fn: fiber tract file @param roi_xml_fn: region of interest xml file @param roi_raw_fn: region of interest raw file @param graphs: Dir where biggraphs & smallgraphs are saved @param graphInvariants: Dir where graph invariants are saved @param graphsize: the size of the graph 'big' or 'small' @param run: Whether or not to run processor intensive jobs. Default is - false so nothing is actually run ''' baseName = getFiberID(fiber_fn) #VERY TEMPORARY Gfn = os.path.join(graphs, baseName) # partial name if (run): if graphsize.lower().startswith("s"): print("Running Small gengraph ...") Gfn+="smgr.graphml" # Note: Some included atlases are present gengraph.genGraph(fiber_fn, Gfn, roi_xml_fn, roi_raw_fn, bigGraph=False, **settings.ATLASES) elif graphsize.lower().startswith("b"): print("\nRunning Big gengraph ...") Gfn+="bggr.graphml" gengraph.genGraph(fiber_fn, Gfn, roi_xml_fn, roi_raw_fn, bigGraph=True, **settings.ATLASES) else: print '[ERROR]: Graphsize Unkwown' # should never happen return Gfn
def rungenGraph(): global inputRoi_raw global inputRoi_xml global inputFiber_dat out = "/Users/dmhembere44/Desktop/genGraphOut.mat" gengraph.genGraph(inputFiber_dat, out)
def process_input_data(derivatives, graph_loc, graphsize, invariants, proj_dir, to_email): ''' Extract File name & determine what file corresponds to what for gengraph @param session: the session dictionary object ''' """ if isinstance(session, str) or isinstance(session, unicode): f = open(session, "rb") session = pickle.load(f) f.close() """ filesInUploadDir = os.listdir(derivatives) fiber_fn, data_atlas_fn = checkFileExtGengraph( filesInUploadDir) # Check & sort files ''' Fully qualify file names ''' fiber_fn = os.path.join(derivatives, fiber_fn) if not data_atlas_fn: data_atlas_fn = settings.ATLASES.keys()[0] else: data_atlas_fn = os.path.join(derivatives, data_atlas_fn) print "data_atlas_fn %s ..." % data_atlas_fn Gfn = os.path.join(graph_loc, getFiberID(fiber_fn)) # partial name if (graphsize).lower().startswith("s"): Gfn += "smgr.graphml" graphsize = False # False is small graph elif graphsize.lower().startswith("b"): Gfn += "bggr.graphml" graphsize = True # True is big graph else: print '[ERROR]: Graphsize Unkwown' # should never happen try: genGraph(fiber_fn, data_atlas_fn, Gfn, graphsize, **settings.ATLASES) # FIXME: numfibers = 20000 for tests except: msg = "Hello,\n\nYour most recent job failed either because your fiber streamline file or ROI mask was incorrectly formatted." msg += " Please check both and try again.\n\n" sendJobFailureEmail(to_email, msg) return 911 # Run ivariants here if len(invariants) > 0: print "Computing invariants {0}".format(invariants) invariant_fns = run_invariants(invariants, Gfn, graph_loc) dwnld_loc = get_download_path(proj_dir) sendJobCompleteEmail(to_email, dwnld_loc)
def process_input_data(derivatives, graph_loc, graphsize, invariants, proj_dir, to_email): ''' Extract File name & determine what file corresponds to what for gengraph @param session: the session dictionary object ''' """ if isinstance(session, str) or isinstance(session, unicode): f = open(session, "rb") session = pickle.load(f) f.close() """ filesInUploadDir = os.listdir(derivatives) fiber_fn, data_atlas_fn = checkFileExtGengraph(filesInUploadDir) # Check & sort files ''' Fully qualify file names ''' fiber_fn = os.path.join(derivatives, fiber_fn) if not data_atlas_fn: data_atlas_fn = settings.ATLASES.keys()[0] else: data_atlas_fn = os.path.join(derivatives, data_atlas_fn) print "data_atlas_fn %s ..." % data_atlas_fn Gfn = os.path.join(graph_loc, getFiberID(fiber_fn)) # partial name if (graphsize).lower().startswith("s"): Gfn += "smgr.graphml" graphsize = False # False is small graph elif graphsize.lower().startswith("b"): Gfn+="bggr.graphml" graphsize = True # True is big graph else: print '[ERROR]: Graphsize Unkwown' # should never happen try: genGraph(fiber_fn, data_atlas_fn, Gfn, graphsize, **settings.ATLASES) # FIXME: numfibers = 20000 for tests except: msg = "Hello,\n\nYour most recent job failed either because your fiber streamline file or ROI mask was incorrectly formatted." msg += " Please check both and try again.\n\n" sendJobFailureEmail(to_email, msg) return 911 # Run ivariants here if len(invariants) > 0: print "Computing invariants {0}".format(invariants) invariant_fns = run_invariants(invariants, Gfn, graph_loc) dwnld_loc = get_download_path(proj_dir) sendJobCompleteEmail(to_email, dwnld_loc)
def processData(fiber_fn, roi_xml_fn, roi_raw_fn, graphs, graphInvariants, graphsize, run=False): ''' Run graph building and other related scripts @param fiber_fn: fiber tract file @param roi_xml_fn: region of interest xml file @param roi_raw_fn: region of interest raw file @param graphs: Dir where biggraphs & smallgraphs are saved @param graphInvariants: Dir where graph invariants are saved @param graphsize: the size of the graph 'big' or 'small' @param run: Whether or not to run processor intensive jobs. Default is - false so nothing is actually run ''' if (run): import mrcap.svd as svd import mrcap.lcc as lcc print "Imported svd and lcc modules..." baseName = getFiberID(fiber_fn) #VERY TEMPORARY smGrfn = os.path.join(graphs, (baseName + 'smgr.mat')) bgGrfn = os.path.join(graphs, (baseName + 'bggr.mat')) if (run): if (graphsize == 'small'): ''' Run gengraph SMALL & save output ''' print("Running Small gengraph....") gengraph.genGraph(fiber_fn, smGrfn, roi_xml_fn, roi_raw_fn, bigGraph=False) elif (graphsize == 'big'): ''' Run gengrah BIG & save output ''' print("\nRunning Big gengraph....") gengraph.genGraph(fiber_fn, bgGrfn, roi_xml_fn, roi_raw_fn, bigGraph=True) else: print '[ERROR]: Graphsize Unkwown' # should never happen ''' Run LCC ''' lccfn = os.path.join(graphInvariants, "LCC", (baseName + 'concomp.npy')) if (run): '''Should be big but we'll do small for now''' if (graphsize == 'big'): print "Running biggraph Largest connected component..." lcc.process_single_brain(bgGrfn, lccfn) if (graphsize == 'small'): print "Running smallgraph Largest connected component..." lcc.process_single_brain(smGrfn, lccfn) ''' Run Embed - SVD ''' SVDfn = os.path.join(graphInvariants, "SVD", (baseName + 'embed.npy')) print("Running SVD....") if (run): if (graphsize == 'big'): print "Running SVD on biggraph" svd.embed_graph(lccfn, bgGrfn, SVDfn) if (graphsize == 'small'): print "Running SVD on smallgraph" svd.embed_graph(lccfn, smGrfn, SVDfn) print "Completed generating - graph, lcc & svd" return [smGrfn, bgGrfn, lccfn, SVDfn]
def processData(fiber_fn, roi_xml_fn, roi_raw_fn,graphs, graphInvariants, graphsize, run = False): ''' Run graph building and other related scripts @param fiber_fn: fiber tract file @param roi_xml_fn: region of interest xml file @param roi_raw_fn: region of interest raw file @param graphs: Dir where biggraphs & smallgraphs are saved @param graphInvariants: Dir where graph invariants are saved @param graphsize: the size of the graph 'big' or 'small' @param run: Whether or not to run processor intensive jobs. Default is - false so nothing is actually run ''' if (run): import mrcap.svd as svd import mrcap.lcc as lcc print "Imported svd and lcc modules..." baseName = getFiberID(fiber_fn) #VERY TEMPORARY smGrfn = os.path.join(graphs, (baseName +'smgr.mat')) bgGrfn = os.path.join(graphs, (baseName +'bggr.mat')) if (run): if (graphsize == 'small'): ''' Run gengraph SMALL & save output ''' print("Running Small gengraph....") gengraph.genGraph(fiber_fn, smGrfn, roi_xml_fn, roi_raw_fn, bigGraph=False) elif(graphsize == 'big'): ''' Run gengrah BIG & save output ''' print("\nRunning Big gengraph....") gengraph.genGraph(fiber_fn, bgGrfn, roi_xml_fn, roi_raw_fn, bigGraph=True) else: print '[ERROR]: Graphsize Unkwown' # should never happen ''' Run LCC ''' lccfn = os.path.join(graphInvariants,"LCC", (baseName + 'concomp.npy')) if (run): '''Should be big but we'll do small for now''' if (graphsize == 'big'): print "Running biggraph Largest connected component..." lcc.process_single_brain(bgGrfn, lccfn) if (graphsize == 'small'): print "Running smallgraph Largest connected component..." lcc.process_single_brain(smGrfn, lccfn) ''' Run Embed - SVD ''' SVDfn = os.path.join(graphInvariants,"SVD" ,(baseName + 'embed.npy')) print("Running SVD....") if (run): if (graphsize == 'big'): print "Running SVD on biggraph" svd.embed_graph(lccfn, bgGrfn, SVDfn) if (graphsize == 'small'): print "Running SVD on smallgraph" svd.embed_graph(lccfn, smGrfn, SVDfn) print "Completed generating - graph, lcc & svd" return [ smGrfn, bgGrfn, lccfn, SVDfn ]