def hasPermission( user, path, name ) : if user == 'su' : return True else : if name.startswith(PROJECT_PREFIX) : try : return perms[user][utils.unprefix(name)] except KeyError : return False else : return True
def hasPermission(user, path, name): if user == 'su': return True else: if name.startswith(PROJECT_PREFIX): try: return perms[user][utils.unprefix(name)] except KeyError: return False else: return True
def makeItem( user_name, path ) : print "path: %s" % path (head,gparent_name,parent_name,name) = path.rsplit('/',3) gparent = "%s/%s" % (head, gparent_name) parent= "%s/%s" % (gparent, parent_name) #is_dir = os.path.isdir(path) prefix = getPrefix( path, name ) is_dir = prefix == DONOR_PREFIX or prefix == PROJECT_PREFIX item = {} if show( user_name, path, name) : name = utils.unprefix(name) parent_prefix = getPrefix( parent, parent_name ) gparent_prefix = getPrefix( gparent, gparent_name ) gparent_name = utils.extractName(gparent_prefix, path) parent_name = utils.extractName(parent_prefix, path) item = {'name' : name, \ 'parentDir' : parent, \ 'directory' : is_dir, \ 'path' : path, 'prefix' : prefix} if prefix == PROJECT_PREFIX : if name in dassembly : item['assembly'] = dassembly[name] else : item['assembly'] = "n/a" if prefix == QUERY_PREFIX : print "QUERY_PREFIX" assert parent_prefix == DONOR_PREFIX item['project'] = gparent_name item['donor'] = parent_name #project/query_name item['key'] = "%s/%s" % (gparent_name,name) tt = TRACK_TEMPLATE % \ (gparent_name, parent_name, name, UNBOUND_CHROM) item['label'] = name item['type'] = 'FeatureTrack' if item['project'] in dassembly : item['assembly'] = dassembly[item['project']] else : item['assembly'] = "n/a" #Associate these three keys with each query menuitem #It will tell the browser how many of each filetype we #have in the chrom folders. #(Remember: Using the counts for chr1) #dkey_ext = {"bam_ixs" : ".bam", \ #"interval_ixs" : ".interval", \ #"txt_ixs" : ".txt" } #for key in dkey_ext : #item[key] = [] item["bams"] = [] item["txts"] = [] item["sub_results"] = [] item["sub_exts"] = [] #pick the first available chrom folder and inspect its contents #use them to build up the list of bams, txts, sub_results, .... chrom_folder = "" for listing in os.listdir( path ) : folder = path + '/' + listing if os.path.isdir( folder ) : chrom_folder = folder break print "folder", chrom_folder if not chrom_folder : pass else : #folder = "%s/data/%s" % (ROOT_DIR, tt.replace( UNBOUND_CHROM, 'chr1' ) ) print "canonical chrom folder is %s" % chrom_folder #TODO #more specific than just looking for a .txt file? for thing in sorted( os.listdir( chrom_folder ) ) : if os.path.isdir( chrom_folder+"/"+thing ) and thing != ".svn" : print "listdir:", thing item["sub_results"].append( thing ) for subthing in sorted(os.listdir( chrom_folder+"/"+thing )) : head,ext = subthing.rsplit(".",1) if ext == "short" or ext == "interval" : if ext == "short" : item["sub_exts"].append( "bam.short" ) else : item["sub_exts"].append( ext ) else : head,ext = thing.rsplit(".",1) if ext == "bam" : item["bams"].append( thing ) if ext == "txt" : item["txts"].append( thing ) if len(item['sub_results']) > 0 : item['url'] = "%s/%%s/trackData.json" % tt else : item['url'] = "%s/trackData.json" % tt if is_dir : item["children"] = getChildren( user_name, path ) return item
def makeItem(user_name, path): print "path: %s" % path (head, gparent_name, parent_name, name) = path.rsplit('/', 3) gparent = "%s/%s" % (head, gparent_name) parent = "%s/%s" % (gparent, parent_name) #is_dir = os.path.isdir(path) prefix = getPrefix(path, name) is_dir = prefix == DONOR_PREFIX or prefix == PROJECT_PREFIX item = {} if show(user_name, path, name): name = utils.unprefix(name) parent_prefix = getPrefix(parent, parent_name) gparent_prefix = getPrefix(gparent, gparent_name) gparent_name = utils.extractName(gparent_prefix, path) parent_name = utils.extractName(parent_prefix, path) item = {'name' : name, \ 'parentDir' : parent, \ 'directory' : is_dir, \ 'path' : path, 'prefix' : prefix} if prefix == PROJECT_PREFIX: if name in dassembly: item['assembly'] = dassembly[name] else: item['assembly'] = "n/a" if prefix == QUERY_PREFIX: print "QUERY_PREFIX" assert parent_prefix == DONOR_PREFIX item['project'] = gparent_name item['donor'] = parent_name #project/query_name item['key'] = "%s/%s" % (gparent_name, name) tt = TRACK_TEMPLATE % \ (gparent_name, parent_name, name, UNBOUND_CHROM) item['label'] = name item['type'] = 'FeatureTrack' if item['project'] in dassembly: item['assembly'] = dassembly[item['project']] else: item['assembly'] = "n/a" #Associate these three keys with each query menuitem #It will tell the browser how many of each filetype we #have in the chrom folders. #(Remember: Using the counts for chr1) #dkey_ext = {"bam_ixs" : ".bam", \ #"interval_ixs" : ".interval", \ #"txt_ixs" : ".txt" } #for key in dkey_ext : #item[key] = [] item["bams"] = [] item["txts"] = [] item["sub_results"] = [] item["sub_exts"] = [] #pick the first available chrom folder and inspect its contents #use them to build up the list of bams, txts, sub_results, .... chrom_folder = "" for listing in os.listdir(path): folder = path + '/' + listing if os.path.isdir(folder): chrom_folder = folder break print "folder", chrom_folder if not chrom_folder: pass else: #folder = "%s/data/%s" % (ROOT_DIR, tt.replace( UNBOUND_CHROM, 'chr1' ) ) print "canonical chrom folder is %s" % chrom_folder #TODO #more specific than just looking for a .txt file? for thing in sorted(os.listdir(chrom_folder)): if os.path.isdir(chrom_folder + "/" + thing) and thing != ".svn": print "listdir:", thing item["sub_results"].append(thing) for subthing in sorted( os.listdir(chrom_folder + "/" + thing)): head, ext = subthing.rsplit(".", 1) if ext == "short" or ext == "interval": if ext == "short": item["sub_exts"].append("bam.short") else: item["sub_exts"].append(ext) else: head, ext = thing.rsplit(".", 1) if ext == "bam": item["bams"].append(thing) if ext == "txt": item["txts"].append(thing) if len(item['sub_results']) > 0: item['url'] = "%s/%%s/trackData.json" % tt else: item['url'] = "%s/trackData.json" % tt if is_dir: item["children"] = getChildren(user_name, path) return item