def merge(b1, b2): geneIds = set(typeOps.mkiter(b1.geneIds)) | set(typeOps.mkiter(b2.geneIds)) b = GeneBoundsBed.create(b1.chrom, min(b1.start, b2.start), max(b1.end, b2.end), b1.name, strand=b1.strand, geneSym=b1.geneSym, hgncId=b1.hgncId, geneIds=list(geneIds), geneType=b1.geneType) return b
def linkRequires(self, requires): """link in productions required by this node. Can be single nodes, or lists or sets of nodes, reverse links are created""" for r in typeOps.mkiter(requires): if not isinstance(r, Production): raise ExRunException("Rule " + str(self) + " requires can only be linked to a Production, attempt to link to: " + str(r)) r.linkRequiredBy(self)
def linkProduces(self, produces): """link in productions produced by this node. Can be single nodes, or lists or sets of nodes, reverse links are created""" for p in typeOps.mkiter(produces): if not isinstance(p, Production): raise ExRunException("Rule " + str(self) + " produces can only be linked to a Production, attempt to link to: " + str(p)) p.linkProducedBy(self)
def __specsToStateTbl(self, notOkSpecs): "convert spec lists no tables" notOkStates = {} for spec in notOkSpecs: for n in typeOps.mkiter(spec[0]): notOkStates[n] = spec[1] return notOkStates
def linkRequires(self, requires): """link in productions or targets required by this node. Can be single nodes, or lists or sets of nodes""" for r in typeOps.mkiter(requires): if not (isinstance(r, Production) or isinstance(r, Target)): raise ExRunException("Target " + str(self) + " requires can only be linked to a Production or a Target, attempt to link to: " + str(r)) self.requires.add(r)
def __addCmdStdio(self, fspecs, specSet, exclude=None): "add None, a single or a list of file specs as requires or produces links" for fspec in typeOps.mkiter(fspecs): if (isinstance(fspec, FileIn) or isinstance(fspec, FileOut)): fspec = fspec.file # get File object for reference if (isinstance(fspec, File) and ((exclude == None) or (fspec not in exclude))): specSet.add(fspec)
def linkRequiredBy(self, requiredBy): """link to rules that require production, can be single rule, lists or sets of rules, reverse links are created""" for r in typeOps.mkiter(requiredBy): if not isinstance(r, Rule): raise ExRunException("Production " + str(self) + " requiredBy can only be linked to a Rule, attempt to link to: " + str(r)) self.requiredBy.add(r) r.requires.add(self);
def getFiles(self, paths): """like getFile(), only path can be a single path, or a list of paths, or a File object, or list of File objects. Returns a list of File objects""" files = [] for p in typeOps.mkiter(paths): files.append(self.getFile(p)) return files
def linkRequires(self, requires): """link in productions or targets required by this node. Can be single nodes, or lists or sets of nodes""" for r in typeOps.mkiter(requires): if not (isinstance(r, Production) or isinstance(r, Target)): raise ExRunException( "Target " + str(self) + " requires can only be linked to a Production or a Target, attempt to link to: " + str(r)) self.requires.add(r)
def linkRequires(self, requires): """link in productions required by this node. Can be single nodes, or lists or sets of nodes, reverse links are created""" for r in typeOps.mkiter(requires): if not isinstance(r, Production): raise ExRunException( "Rule " + str(self) + " requires can only be linked to a Production, attempt to link to: " + str(r)) r.linkRequiredBy(self)
def linkProduces(self, produces): """link in productions produced by this node. Can be single nodes, or lists or sets of nodes, reverse links are created""" for p in typeOps.mkiter(produces): if not isinstance(p, Production): raise ExRunException( "Rule " + str(self) + " produces can only be linked to a Production, attempt to link to: " + str(p)) p.linkProducedBy(self)
def __getRunTargets(self, targets=None): "get list of targets to run, return the default if none specified" ts = [] for t in typeOps.mkiter(targets): if isinstance(t, Target): ts.append(t) else: ts.append(self.getTarget(t)) if len(ts) == 0: ts.append(self.getTarget(self.defaultTargetName)) return ts
def linkRequiredBy(self, requiredBy): """link to rules that require production, can be single rule, lists or sets of rules, reverse links are created""" for r in typeOps.mkiter(requiredBy): if not isinstance(r, Rule): raise ExRunException( "Production " + str(self) + " requiredBy can only be linked to a Rule, attempt to link to: " + str(r)) self.requiredBy.add(r) r.requires.add(self)
def geneBoundsBigBedRead(bigBedFh, chrom, start, end): if start >= end: return iter(()) for entry in typeOps.mkiter(bigBedFh.entries(chrom, start, end)): data = entry[2].split('\t') yield GeneBoundsBed.create(chrom, entry[0], entry[1], data[0], score=data[1], strand=data[2], thickStart=data[3], thickEnd=data[4], itemRgb=data[5], geneSym=data[6], hgncId=data[7], geneIds=data[8], geneType=data[9])