def _makeMainTrackDb(self):
        mainTrackDb = []

        for atn, labelNAndInfo in self.byAssayBiosampleType.iteritems():
            pri = self.priority.increment(1)
            totalExperiments = sum(
                [len(info["exps"]) for info in labelNAndInfo.values()])
            shortLabel = self.labelNToNormal[atn]
            longLabel = self.labelNToNormal[
                atn] + " (%s experiments)" % totalExperiments

            mainTrackDb.append("""
track super_{atn}
superTrack on
priority {priority}
shortLabel {shortL}
longLabel {longL}
description {longL}
""".format(atn=atn,
            priority=pri,
            shortL=shortLabel,
            longL=Helpers.makeLongLabel(longLabel)))

        outF = StringIO.StringIO()
        outF.write('\n'.join(mainTrackDb))
        for atn, labelNAndInfo in self.byAssayBiosampleType.iteritems():
            for labelN, info in labelNAndInfo.iteritems():
                with open(info["fnp"]) as f:
                    outF.write(f.read())
                    outF.write('\n')
        return outF.getvalue()
Пример #2
0
    def _makeMainTrackDb(self):
        mainTrackDb = []

        for atn, btAndInfo in self.byAssayBiosampleType.iteritems():
            pri = self.priority.increment(1)

            totalExperiments = 0
            for bt, info in btAndInfo.iteritems():
                if "0_all" != bt:
                    totalExperiments += len(info["exps"])

            shortLabel = self.btToNormal[atn]
            longLabel = info["longLabelBase"] + " (%s experiments)" % totalExperiments

            mainTrackDb.append("""
track super_{atn}
superTrack on
priority {priority}
shortLabel {shortL}
longLabel {longL}
""".format(atn = atn,
           priority = pri,
           shortL=shortLabel,
           longL=Helpers.makeLongLabel(longLabel)))

        outF = StringIO.StringIO()
        outF.write('\n'.join(mainTrackDb))
        for atn, btAndInfo in self.byAssayBiosampleType.iteritems():
            for bt, info in btAndInfo.iteritems():
                with open(info["fnp"]) as f:
                    outF.write(f.read())
                    outF.write('\n')
        return outF.getvalue()
Пример #3
0
    def _makeMainTrackDb(self):
        mainTrackDb = []

        for bt, btnFnps in self.byBiosampleTypeBiosample.iteritems():
            pri = self.priority.increment(1)
            totalExperiments = sum(
                [len(info["expIDs"]) for info in btnFnps.values()])
            shortLabel = self.btToNormal[bt]
            longLabel = self.btToNormal[
                bt] + " (%s experiments)" % totalExperiments

            if shortLabel == "induced pluripotent stem cell line":
                shortLabel = "IPSC"

            shortLabel = titlecase(shortLabel)
            shortLabel = shortLabel.replace('Ipsc', 'IPSC')
            shortLabel = shortLabel.replace('In Vitro Differentiated Cell',
                                            'in vitro Diff Cell')
            shortLabel = shortLabel + ' Experiments'

            mainTrackDb.append("""
track super_{bt}
superTrack on
priority {priority}
shortLabel {shortL}
longLabel {longL}
description {longL}
""".format(bt=bt,
            priority=pri,
            shortL=shortLabel,
            longL=Helpers.makeLongLabel(longLabel)))

        outF = StringIO.StringIO()
        outF.write('\n'.join(mainTrackDb))
        for bt, btnFnps in self.byBiosampleTypeBiosample.iteritems():
            for btn, info in btnFnps.iteritems():
                with open(info["fnp"]) as f:
                    outF.write(f.read())
                    outF.write('\n')
        return outF.getvalue()
Пример #4
0
def outputCompositeTrackByBiosampleType(assembly, bt, btn, expIDs, fnp, idx,
                                        total, subGroups, biosample_type,
                                        biosample_term_name, lookupByExp):
    if not os.path.exists(fnp):
        raise Exception("missing " + fnp)

    subGroupsDict = {}
    for k in Helpers.SubGroupKeys:
        subGroupsDict[k] = {a[0]: a[1] for a in subGroups[k]}
    longLabel = biosample_term_name + " (%s experiments)" % len(expIDs)

    if "cell_line" == bt:
        subGroup1key = "target_label"
        subGroup2key = "biosample_summary"
    else:
        subGroup1key = "target_label"
        subGroup2key = "age_sex"
    subGroup3key = "view"
    subGroup1 = Helpers.unrollEquals(subGroupsDict[subGroup1key])
    subGroup2 = Helpers.unrollEquals(subGroupsDict[subGroup2key])
    subGroup3 = Helpers.unrollEquals(subGroupsDict[subGroup3key])

    actives = []
    for expID in expIDs:
        if expID in lookupByExp:
            actives.append(lookupByExp[expID].isActive())
    isActive = any(t for t in actives)
    if isActive:
        print("active biosample (composite):", btn)

    with open(fnp) as f:
        subtracks = f.read()

    with open(fnp, 'w') as f:
        f.write("""
track {bt}_{btn}
parent super_{bt}
compositeTrack on
centerLabelsDense on
""".format(bt=bt, btn=btn))
        if isActive:
            f.write("visibility full\n")
        f.write("""shortLabel {shortL}
description {longL}
longLabel {longL}
type bigWig 9 +
maxHeightPixels 64:12:8
autoScale on
subGroup1 {subGroup1key} {subGroup1key} {subGroup1}
subGroup2 {subGroup2key} {subGroup2key} {subGroup2}
subGroup3 {subGroup3key} {subGroup3key} {subGroup3}
sortOrder {subGroup1key}=+ {subGroup2key}=+ {subGroup3key}=+
dimensions dimX={subGroup2key} dimY={subGroup1key}
dragAndDrop subTracks
hoverMetadata on
darkerLabels on
""".format(shortL=Helpers.makeShortLabel(biosample_term_name),
           longL=Helpers.makeLongLabel(longLabel),
           subGroup1key=subGroup1key,
           subGroup1=subGroup1,
           subGroup2key=subGroup2key,
           subGroup2=subGroup2,
           subGroup3key=subGroup3key,
           subGroup3=subGroup3))
        f.write('\n' + subtracks)

    printWroteNumLines(fnp, idx, 'of', total)
Пример #5
0
def outputCompositeTrackByBiosampleType(assembly, assay_term_name, atn, biosample_type, bt,
                                        exps, fnp, idx, total, subGroups, lookupByExp, longLabelBase = None):
    if not os.path.exists(fnp):
        raise Exception("missing " + fnp)

    subGroupsDict = {}
    for k in Helpers.SubGroupKeys:
        subGroupsDict[k] = {a[0]:a[1] for a in subGroups[k]}
    longLabel = biosample_type + " (%s experiments)" % len(exps)

    print(subGroupsDict["assay"])

    if atn in ["dnase", "atac_seq"]:
        subGroup1key = "biosample"
        subGroup2key = "age"
    elif "histone_modifications" == atn:
        subGroup1key = "biosample"
        subGroup2key = "label"
    elif "transcription_factors" == atn:
        subGroup1key = "biosample"
        subGroup2key = "label"
    elif atn in ["transcription", "rampage", "microRNAseq"]:
        subGroup1key = "biosample"
        subGroup2key = "assay"
    else:
        subGroup1key = "donor"
        subGroup2key = "age"

    if "0_all" == bt:
        subGroup1key = "biosample"
        subGroup2key = "age_sex"

    subGroup3key = "view"
    subGroup1 = Helpers.unrollEquals(subGroupsDict[subGroup1key])
    subGroup2 = Helpers.unrollEquals(subGroupsDict[subGroup2key])
    subGroup3 = Helpers.unrollEquals(subGroupsDict[subGroup3key])

    with open(fnp) as f:
        subtracks = f.read()

    actives = []
    # for expID in expIDs:
    #     if expID in lookupByExp:
    #         actives.append(lookupByExp[expID].isActive())
    isActive = any(t for t in actives)
    # if isActive:
    #     print("active biosample (composite):", btn)

    with open(fnp, 'w') as f:
        f.write("""
track {atn}_{bt}
parent super_{atn}
compositeTrack on
centerLabelsDense on
""".format(atn=atn,
           bt=bt))
        if isActive:
            f.write("visibility full\n")
        f.write("""shortLabel {shortL}
longLabel {longL}
type bigWig 9 +
maxHeightPixels 64:12:8
autoScale on
subGroup1 {subGroup1key} {subGroup1key} {subGroup1}
subGroup2 {subGroup2key} {subGroup2key} {subGroup2}
subGroup3 {subGroup3key} {subGroup3key} {subGroup3}
sortOrder {subGroup1key}=+ {subGroup2key}=+ {subGroup3key}=+
dimensions dimX={subGroup2key} dimY={subGroup1key}
dragAndDrop subTracks
hoverMetadata on
darkerLabels on
""".format(shortL=Helpers.makeShortLabel(biosample_type),
           longL=Helpers.makeLongLabel(longLabel),
           subGroup1key=subGroup1key,
           subGroup1=subGroup1,
           subGroup2key=subGroup2key,
           subGroup2=subGroup2,
           subGroup3key=subGroup3key,
           subGroup3=subGroup3
))
        f.write('\n' + subtracks)

    printWroteNumLines(fnp, idx, 'of', total)