예제 #1
0
def addUserToHub(hubName, owner, newUser):
    keys = db.HubInfo.keysWhichMatch(db.HubInfo, owner)

    hubInfo = db.HubInfo(owner, hubName).get()
    if 'users' in hubInfo.keys():
        hubInfo['users'].append(newUser)
    else:
        hubInfo['users'].append(newUser)

    hubInfo['users'] = list(set(hubInfo['users']))
    db.HubInfo(owner, hubName).put(hubInfo)

    # create permissions database object for a user
    db.Permissions(owner, hubName, newUser).put(["", "", "", "", ""])
예제 #2
0
def removeTrack(request):
    query = request.matchdict
    hubName = query['hub']
    owner = query['user']
    trackName = request.params['trackName']

    hubInfo = db.HubInfo(owner, hubName).get()

    del hubInfo['tracks'][trackName]

    db.HubInfo(owner, hubName).put(hubInfo)

    url = request.route_url('myHubs')
    return HTTPFound(location=url)
예제 #3
0
    def __init__(self, user, hub, track, problem, trackUrl=None, tasks=None):
        self.user = user
        self.hub = hub
        self.track = track
        self.problem = problem

        if tasks is None:
            self.tasks = {}
        else:
            self.tasks = tasks

        # When adding labels during hub upload the URL hasn't been stored yet
        if trackUrl is None:
            txn = db.getTxn()
            hubInfo = db.HubInfo(user, hub).get(txn=txn)
            try:
                self.trackUrl = hubInfo['tracks'][track]['url']
            except TypeError:
                print(hubInfo)
                print(db.HubInfo.db_key_tuples())
                print(user, track)
                txn.commit()
                raise Exception
            txn.commit()
        else:
            self.trackUrl = trackUrl
        self.status = 'New'
예제 #4
0
def isPublic(request):
    query = request.matchdict
    hubName = query['hub']
    user = query['user']

    chkpublic = "chkpublic" in request.params.keys()
    hub = db.HubInfo(user, hubName).get()
    hub['isPublic'] = chkpublic
    db.HubInfo(user, hubName).put(hub)

    if chkpublic:
        Hubs.addUserToHub(hubName, user, 'Public')
    elif 'Public' in hub['users']:
        Hubs.removeUserFromHub(hubName, user, 'Public')

    url = request.route_url('myHubs')
    return HTTPFound(location=url)
예제 #5
0
def deleteHub(request):
    userid = request.unauthenticated_userid
    hubName = request.params['hubName']

    hub_info = None
    db.HubInfo(userid, hubName).put(hub_info)

    url = request.route_url('myHubs')
    return HTTPFound(location=url)
예제 #6
0
def addTrack(request):
    query = request.matchdict
    hubName = query['hub']
    owner = query['user']
    category = request.params['category']
    trackName = request.params['trackName']
    url = request.params['url']

    hubInfo = db.HubInfo(owner, hubName).get()
    hubInfo['tracks'][trackName] = {
        'categories': category,
        'key': trackName,
        'url': url
    }
    db.HubInfo(owner, hubName).put(hubInfo)

    url = request.route_url('myHubs')
    return HTTPFound(location=url)
예제 #7
0
    def do_GET(self, data):
        args = data['args']
        if args['file'] == 'trackList.json':

            hubInfo = db.HubInfo(self.query['user'], self.query['hub']).get()

            return createTrackListWithHubInfo(hubInfo)
        else:
            print('no handler for %s' % self.query['handler'])
예제 #8
0
def getHubInfos(keys, userid):
    hubInfos = {}

    for key in keys:
        currentHub = db.HubInfo(key[0], key[1]).get()
        currentHub['owner'] = key[0]

        if userid in currentHub['users'] or userid == key[0]:
            hubInfos['{hubName}'.format(hubName=key[1])] = currentHub

    return hubInfos
예제 #9
0
def storeHubInfo(user, hub, tracks, hubInfo, genome):
    superList = []
    trackList = []
    hubInfoTracks = {}

    # Load the track list into something which can be converted
    for track in tracks:
        if 'superTrack' in track:
            superList.append(track)
            continue

        if 'parent' in track:
            for super in superList:
                if super['track'] == track['parent']:
                    trackList.append(track)
                    continue
            for parent in trackList:
                if parent['track'] == track['parent']:
                    if 'children' not in parent:
                        parent['children'] = []
                        parent['children'].append(track)
                    else:
                        parent['children'].append(track)

    for track in trackList:
        # Determine which track is the coverage data
        coverage = None
        for child in track['children']:
            file = child['bigDataUrl'].rsplit('/', 1)
            if 'coverage' in file[1]:
                coverage = child

        # Add Data Url to config
        if coverage is not None:
            categories = 'Data'
            for category in track['longLabel'].split(' | ')[:-1]:
                categories = categories + ' / %s' % category

            hubInfoTracks[track['track']] = {'categories': categories,
                                             'key': track['shortLabel'],
                                             'url': coverage['bigDataUrl']}

            checkForPrexistingLabels(coverage['bigDataUrl'], user, hub, track, genome)

    txn = db.getTxn()
    hubInfo['tracks'] = hubInfoTracks
    db.HubInfo(user, hub).put(hubInfo, txn=txn)
    txn.commit()

    return '/%s/' % os.path.join(str(user), hub)
예제 #10
0
def publicHubs(request):
    userid = request.authenticated_userid

    everyKey = db.HubInfo.keysWhichMatch(db.HubInfo)

    hubNames = list(map(lambda tuple: tuple[1], everyKey))

    hubInfos = {}
    for key in everyKey:
        currentHub = db.HubInfo(key[0], key[1]).get()

        if 'isPublic' in currentHub.keys() and currentHub['isPublic']:
            currentHub['labels'] = 0
            for labelKey in db.Labels.keysWhichMatch(key[0], key[1]):
                currentHub['labels'] += db.Labels(*labelKey).get().shape[0]

            currentHub['owner'] = key[0]
            hubInfos['{hubName}'.format(hubName=key[1])] = currentHub

    return {"user": userid, "HubNames": hubNames, "hubInfos": hubInfos}
예제 #11
0
def moreHubInfo(request):
    userid = request.authenticated_userid
    query = request.matchdict
    hubName = query['hub']

    myKeys = db.Labels.keysWhichMatch(userid, hubName)
    num_labels = 0
    labels = {}
    for key in myKeys:
        num_labels += db.Labels(*key).get().shape[0]
        labels[(key[2], key[3])] = db.Labels(*key).get().to_html()

    thisHubInfo = db.HubInfo(userid, hubName).get()

    tracks = []

    return {
        'user': userid,
        'hubName': hubName,
        'hubInfo': thisHubInfo,
        'numLabels': num_labels,
        'tracks': tracks,
        'labels': labels
    }
예제 #12
0
def generateLOPARTModel(data, problem):
    user = data['user']
    hub = data['hub']
    track = data['track']
    chrom = data['ref']
    blockStart = data['start']
    blockEnd = data['end']
    scale = data['scale']
    hubInfo = db.HubInfo(user, hub).get()
    trackUrl = hubInfo['tracks'][data['track']]['url']
    datapoints = data['width']

    start = max(data['visible']['start'], problem['chromStart'])
    end = min(data['visible']['end'], problem['chromEnd'])

    scaledBins = int(scale * (end - start))

    sumData = bw.bigWigSummary(trackUrl, chrom, start, end, scaledBins)
    if len(sumData) < 1:
        return []

    dbLabels = db.Labels(user, hub, track, chrom)
    labels = dbLabels.getInBounds(chrom, start, end)
    denom = end - start

    if len(labels.index) < 1:
        labelsToUse = pd.DataFrame({'start': [1], 'end': [2], 'change': [-1]})
    else:
        lopartLabels = labels[(labels['annotation'] != 'unknown')
                              & (labels['annotation'] != 'peak')]

        if len(lopartLabels.index) < 1:
            labelsToUse = pd.DataFrame({
                'start': [1],
                'end': [2],
                'change': [-1]
            })
        else:
            labelsToUse = labels.apply(convertLabelsToLopart,
                                       axis=1,
                                       args=(start, end, denom, scaledBins))

    lopartOut = LOPART.runSlimLOPART(sumData, labelsToUse,
                                     getLOPARTPenalty(data))

    if lopartOut.empty:
        return []

    lopartPeaks = lopartToPeaks(lopartOut)

    if lopartPeaks.empty:
        return []

    blockBinStart = round((blockStart - start) * scale)
    blockBinEnd = round((blockEnd - start) * scale)

    isInBounds = lopartPeaks.apply(checkBlockInBounds,
                                   axis=1,
                                   args=(blockBinStart, blockBinEnd))

    lopartInBlock = lopartPeaks[isInBounds].copy()

    if lopartInBlock.empty:
        return []

    lopartInBlock['ref'] = chrom
    lopartInBlock['type'] = 'lopart'

    return convertLopartOutToJbrowse(lopartInBlock, blockBinStart, blockBinEnd,
                                     datapoints)
예제 #13
0
def getHubInfo(user, hub):
    return db.HubInfo(user, hub).get()
예제 #14
0
def removeUserFromHub(hubName, owner, removedUser):
    hub_info = db.HubInfo(owner, hubName).get()
    hub_info['users'].remove(removedUser)
    db.HubInfo(owner, hubName).put(hub_info)
예제 #15
0
def getTrackInfo(data):
    txn = db.getTxn()
    hubInfo = db.HubInfo(data['user'], data['hub']).get(txn=txn)
    txn.commit()

    return hubInfo['tracks'][data['track']]
예제 #16
0
def getGenome(data, txn=None):
    hubInfo = db.HubInfo(data['user'], data['hub']).get(txn=txn)

    return hubInfo['genome']