def chainChromTarget(target, hal, queryGenome, queryChromSize, queryTwoBit, queryChrom, targetGenome, targetTwoBit, chainFile): "target to chain one chromosome" queryBed = makeChromBedTmp(target, hal, queryChrom, queryChromSize) # --inMemory caused out of memory in with some alignments with 31G allocated procOps.callProc([["halLiftover", "--outPSL", hal, queryGenome, queryBed, targetGenome, "/dev/stdout"], ["pslPosTarget", "/dev/stdin", "/dev/stdout"], ["axtChain", "-psl", "-verbose=0", "-linearGap=medium", "/dev/stdin", targetTwoBit, queryTwoBit, chainFile]])
def pileup(out_bam, vcf_path): bases = {"A", "T", "G", "C", "a", "t", "g", "c"} vcf_handle = vcf.Reader(open(vcf_path)) wgs_results = defaultdict(list) for vcf_rec in vcf_handle: if vcf_rec.is_indel: continue pos_str = "{0}:{1}-{1}".format(vcf_rec.CHROM, vcf_rec.POS) cmd = ['samtools', 'mpileup', '-r', pos_str, out_bam] mpileup_rec = callProc(cmd).split() pile_up_result = Counter(x.upper() for x in mpileup_rec[4] if x in bases) sample_dict = {s.sample: s.gt_bases for s in vcf_rec.samples} for s in vcf_rec.samples: if len([x for x in sample_dict.itervalues() if x == s.gt_bases ]) != 1: continue if s.gt_bases is None: continue c = 1.0 * pile_up_result[s.gt_bases] / len(mpileup_rec[4]) c *= 1.0 * len([ x for x in sample_dict.itervalues() if x is not None ]) / len(sample_dict) wgs_results[s.sample].append([vcf_rec.POS, c]) return wgs_results
def pileup(out_bam, vcf_path): bases = {"A", "T", "G", "C", "a", "t", "g", "c"} vcf_handle = vcf.Reader(open(vcf_path)) wgs_results = defaultdict(list) for vcf_rec in vcf_handle: if vcf_rec.is_indel: continue pos_str = "{0}:{1}-{1}".format(vcf_rec.CHROM, vcf_rec.POS) cmd = ['samtools', 'mpileup', '-r', pos_str, out_bam] mpileup_rec = callProc(cmd).split() pile_up_result = Counter(x.upper() for x in mpileup_rec[4] if x in bases) sample_dict = {s.sample: s.gt_bases for s in vcf_rec.samples} for s in vcf_rec.samples: if len([x for x in sample_dict.itervalues() if x == s.gt_bases]) != 1: continue if s.gt_bases is None: continue c = 1.0 * pile_up_result[s.gt_bases] / len(mpileup_rec[4]) c *= 1.0 * len([x for x in sample_dict.itervalues() if x is not None]) / len(sample_dict) wgs_results[s.sample].append([vcf_rec.POS, c]) return wgs_results
def testCallSimple(self): out = procOps.callProc(["sort", self.getInputFile("simple1.txt")]) self.assertEqual(out, "five\nfour\none\nsix\nthree\ntwo")
def testCallErr(self): with self.assertRaises(pipeline.ProcException) as cm: procOps.callProc(["false"]) self.assertEqual(str(cm.exception), 'process exited 1: false')
def testCallKeepNL(self): out = procOps.callProc(["sort", self.getInputFile("simple1.txt")], keepLastNewLine=True) self.assertEqual(out, "five\nfour\none\nsix\nthree\ntwo\n")
def testCallSimple(self): out = procOps.callProc(["sort", self.getInputFile("simple1.txt")]) self.failUnlessEqual(out, "five\nfour\none\nsix\nthree\ntwo")
def testQuotesCsh(self): # must use /bin/echo, as some csh echos expand backslash sequences for (words, expect) in self.testData: out = procOps.callProc( ["csh", "-c", "/bin/echo " + " ".join(procOps.shQuote(words))]) self.failUnlessEqual(out, expect)
def testQuotesBash(self): for (words, expect) in self.testData: out = procOps.callProc( ["sh", "-c", "/bin/echo " + " ".join(procOps.shQuote(words))]) self.failUnlessEqual(out, expect)
def makeChromSizeTmp(target, prefix, twoBit): "create a tmp chrom sizes file from a twobit" chromSizeFile = getLocalTempPath(target, prefix, "size") procOps.callProc(["twoBitInfo", twoBit, chromSizeFile]) return chromSizeFile
def testCallKeepNL(self): out = procOps.callProc( ["sort", self.getInputFile("simple1.txt")], keepLastNewLine=True) self.failUnlessEqual(out, "five\nfour\none\nsix\nthree\ntwo\n")
def testCallErr(self): ex = None try: procOps.callProc(["false"]) except Exception, ex: pass
def testQuotesBash(self): for (words, expect) in self.testData: out = procOps.callProc(["sh", "-c", "/bin/echo " + " ".join(procOps.shQuote(words))]) self.assertEqual(out, expect)
def testQuotesCsh(self): # must use /bin/echo, as some csh echos expand backslash sequences for (words, expect) in self.testData: out = procOps.callProc(["csh", "-c", "/bin/echo " + " ".join(procOps.shQuote(words))]) self.assertEqual(out, expect)