Beispiel #1
0
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 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
Beispiel #5
0
 def testCallSimple(self):
     out = procOps.callProc(["sort", self.getInputFile("simple1.txt")])
     self.assertEqual(out, "five\nfour\none\nsix\nthree\ntwo")
Beispiel #6
0
 def testCallErr(self):
     with self.assertRaises(pipeline.ProcException) as cm:
         procOps.callProc(["false"])
     self.assertEqual(str(cm.exception), 'process exited 1: false')
Beispiel #7
0
 def testCallKeepNL(self):
     out = procOps.callProc(["sort", self.getInputFile("simple1.txt")], keepLastNewLine=True)
     self.assertEqual(out, "five\nfour\none\nsix\nthree\ntwo\n")
Beispiel #8
0
 def testCallSimple(self):
     out = procOps.callProc(["sort", self.getInputFile("simple1.txt")])
     self.failUnlessEqual(out, "five\nfour\none\nsix\nthree\ntwo")
Beispiel #9
0
 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)
Beispiel #10
0
 def testQuotesBash(self):
     for (words, expect) in self.testData:
         out = procOps.callProc(
             ["sh", "-c", "/bin/echo " + " ".join(procOps.shQuote(words))])
         self.failUnlessEqual(out, expect)
Beispiel #11
0
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
Beispiel #12
0
 def testCallKeepNL(self):
     out = procOps.callProc(
         ["sort", self.getInputFile("simple1.txt")], keepLastNewLine=True)
     self.failUnlessEqual(out, "five\nfour\none\nsix\nthree\ntwo\n")
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
Beispiel #14
0
 def testCallErr(self):
     ex = None
     try:
         procOps.callProc(["false"])
     except Exception, ex:
         pass
Beispiel #15
0
 def testQuotesBash(self):
     for (words, expect) in self.testData:
         out = procOps.callProc(["sh", "-c", "/bin/echo " + " ".join(procOps.shQuote(words))])
         self.assertEqual(out, expect)
Beispiel #16
0
 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)
Beispiel #17
0
 def testCallErr(self):
     ex = None
     try:
         procOps.callProc(["false"])
     except Exception, ex:
         pass