示例#1
0
    def test_readsToWiggle_pysam(self):
        reads = pysam.Samfile(os.path.join(clipper.test_dir(), "allup_test.bam"))      
        reads = reads.fetch(region="chr15:91536649-91537641")
        wiggle, jxns, pos_counts, lengths, allreads = readsToWiggle_pysam(reads, 91537632, 91537675, '-', 'center', False)
        #wiggle, pos_counts, lengths = readsToWiggle_pysam(reads, 91537632, 91537675, '-', 'center', False)
         
        wiggle_true = [  2. ,  2.,   2. ,  2. ,  2. ,  2.  , 2. ,  2. , 11. , 11.,  11. , 11.  ,11. , 11. , 11.,
   11. , 11.,  11.,  11. , 11.  ,11. , 11. , 11. , 11.,  11. , 11. , 11.  ,11. , 11.  ,11.,
   11. , 11.,  11.,   9. ,  9. ,  9. ,  9. ,  9.,   9. ,  9.,   9. ,  0. ,  0.,   0.]
        
        print wiggle
        for true, test in zip(wiggle_true, wiggle):
            self.assertEqual(test, true)
        #
        pos_counts_true = [ 0. , 0.,  0. , 0.  ,0. , 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0. , 0. , 
                            0. , 0. , 2.,  0., 0. , 0.,  0.,  0.,  0. , 0.,  9.,  0. , 0.,  0. , 0. ,  
                            0. , 0. , 0. , 0. , 0.,  0.,  0., 0. , 0.,  0. , 0. , 0.,  0.,  0. ,  0.]
        
        
        for true, test in zip(pos_counts_true, pos_counts):
            self.assertEqual(test, true)
        
        assert lengths == [33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33]
        
        reads = pysam.Samfile(os.path.join(clipper.test_dir(), "allup_test.bam"))      
        reads = reads.fetch(region="chr15:91536649-91537641")
        wiggle, jxns, pos_counts, lengths, allreads = readsToWiggle_pysam(reads, 91537632, 91537675, '-', 'center', True)
        #wiggle, pos_counts, lengths = readsToWiggle_pysam(reads, 91537632, 91537675, '-', 'center', True)

        wiggle_true = [0.06060606060606061, 0.06060606060606061, 0.06060606060606061, 0.06060606060606061, 0.06060606060606061, 0.06060606060606061, 0.06060606060606061, 0.06060606060606061, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.2727272727272727, 0.2727272727272727, 0.2727272727272727, 0.2727272727272727, 0.2727272727272727, 0.2727272727272727, 0.2727272727272727, 0.2727272727272727, 0.0, 0.0, 0.0]
        for true, test in zip(wiggle_true, wiggle):
            self.assertEqual(test, true)
示例#2
0
    def test_allup(self):
        """ runs entire program on small test dataset """

        args = [
            "--clusters",
            clipper.test_file("clip_analysis_test_peak_results.bed"),
            "-s",
            "mm9",
            "--bam",
            clipper.test_file("allup_test.bam"),
            "--AS_Structure",
            os.path.join(clipper.test_dir(), "mm9data4"),
            '--genome_location',
            clipper.test_file('mm9.fa'),
            #'--regions_location', clipper.test_file("knownGene_sample.gtf"),
            "--regions_location",
            os.path.join(clipper.test_dir(), "regions"),
            '--phastcons_location',
            clipper.test_file("allup_test.bam"),
            '--motifs',
            'AAAAAA',
            '--nrand',
            '1',
            #'--runPhast',
            '--runMotif',
            '--bw_pos',
            clipper.test_file("allup_test.pos.bw"),
            '--bw_neg',
            clipper.test_file("allup_test.neg.bw"),
        ]
        (options, args) = self.parser.parse_args(args)
        #self.assertTrue(False, "allup test is slow and has been removed for now")
        main(options)
示例#3
0
    def test_assign_to_regions(self):
        """
        
        Basic test of assign to regions 
        
        """

        tool = pybedtools.BedTool(
            clipper.test_file(
                "FOX2Brain-05.15.09.polyATrim.adapterTrim.rmRep.sorted.rmDup.peaks.bed"
            ))

        assign_to_regions(tool=tool,
                          clusters="test",
                          speciesFA=clipper.test_file("mm9.fa"),
                          regions_dir=os.path.join(clipper.test_dir(),
                                                   "regions"),
                          regions={
                              "exons": "Exon",
                              "utr3": "3' UTR",
                              "utr5": "5' UTR",
                              "proxintron500": "Proximal Intron",
                              "distintron500": "Distal Intron"
                          },
                          assigned_dir=clipper.test_dir(),
                          fasta_dir=clipper.test_dir(),
                          species="mm9",
                          nrand=3,
                          getseq=False)
示例#4
0
    def test_readsToWiggle_pysam(self):
        reads = pysam.Samfile(
            os.path.join(clipper.test_dir(), "allup_test.bam"))
        reads = reads.fetch(region="chr15:91536649-91537641")
        wiggle, jxns, pos_counts, lengths, allreads = readsToWiggle_pysam(
            reads, 91537632, 91537675, '-', 'center', False)
        #wiggle, pos_counts, lengths = readsToWiggle_pysam(reads, 91537632, 91537675, '-', 'center', False)

        wiggle_true = [
            2., 2., 2., 2., 2., 2., 2., 2., 11., 11., 11., 11., 11., 11., 11.,
            11., 11., 11., 11., 11., 11., 11., 11., 11., 11., 11., 11., 11.,
            11., 11., 11., 11., 11., 9., 9., 9., 9., 9., 9., 9., 9., 0., 0., 0.
        ]

        print wiggle
        for true, test in zip(wiggle_true, wiggle):
            self.assertEqual(test, true)
        #
        pos_counts_true = [
            0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 2.,
            0., 0., 0., 0., 0., 0., 0., 9., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
            0., 0., 0., 0., 0., 0., 0., 0., 0., 0.
        ]

        for true, test in zip(pos_counts_true, pos_counts):
            self.assertEqual(test, true)

        assert lengths == [33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33]

        reads = pysam.Samfile(
            os.path.join(clipper.test_dir(), "allup_test.bam"))
        reads = reads.fetch(region="chr15:91536649-91537641")
        wiggle, jxns, pos_counts, lengths, allreads = readsToWiggle_pysam(
            reads, 91537632, 91537675, '-', 'center', True)
        #wiggle, pos_counts, lengths = readsToWiggle_pysam(reads, 91537632, 91537675, '-', 'center', True)

        wiggle_true = [
            0.06060606060606061, 0.06060606060606061, 0.06060606060606061,
            0.06060606060606061, 0.06060606060606061, 0.06060606060606061,
            0.06060606060606061, 0.06060606060606061, 0.33333333333333326,
            0.33333333333333326, 0.33333333333333326, 0.33333333333333326,
            0.33333333333333326, 0.33333333333333326, 0.33333333333333326,
            0.33333333333333326, 0.33333333333333326, 0.33333333333333326,
            0.33333333333333326, 0.33333333333333326, 0.33333333333333326,
            0.33333333333333326, 0.33333333333333326, 0.33333333333333326,
            0.33333333333333326, 0.33333333333333326, 0.33333333333333326,
            0.33333333333333326, 0.33333333333333326, 0.33333333333333326,
            0.33333333333333326, 0.33333333333333326, 0.33333333333333326,
            0.2727272727272727, 0.2727272727272727, 0.2727272727272727,
            0.2727272727272727, 0.2727272727272727, 0.2727272727272727,
            0.2727272727272727, 0.2727272727272727, 0.0, 0.0, 0.0
        ]
        for true, test in zip(wiggle_true, wiggle):
            self.assertEqual(test, true)
示例#5
0
    def test_readsToWiggle_pysam_wiggles(self):
        """
            
        Tests the ability of reads to wiggle to generate correct wiggle files
        
        """

        reads = pysam.Samfile(
            os.path.join(clipper.test_dir(), "allup_test.bam"))
        reads = reads.fetch(region="chr15:91536649-91537641")
        wiggle, jxns, pos_counts, lengths, allreads = readsToWiggle_pysam(
            reads, 91537632, 91537675, '-', 'center', True)

        wiggle_true = [
            0.06060606060606061, 0.06060606060606061, 0.06060606060606061,
            0.06060606060606061, 0.06060606060606061, 0.06060606060606061,
            0.06060606060606061, 0.06060606060606061, 0.33333333333333326,
            0.33333333333333326, 0.33333333333333326, 0.33333333333333326,
            0.33333333333333326, 0.33333333333333326, 0.33333333333333326,
            0.33333333333333326, 0.33333333333333326, 0.33333333333333326,
            0.33333333333333326, 0.33333333333333326, 0.33333333333333326,
            0.33333333333333326, 0.33333333333333326, 0.33333333333333326,
            0.33333333333333326, 0.33333333333333326, 0.33333333333333326,
            0.33333333333333326, 0.33333333333333326, 0.33333333333333326,
            0.33333333333333326, 0.33333333333333326, 0.33333333333333326,
            0.2727272727272727, 0.2727272727272727, 0.2727272727272727,
            0.2727272727272727, 0.2727272727272727, 0.2727272727272727,
            0.2727272727272727, 0.2727272727272727, 0.0, 0.0, 0.0
        ]
        print wiggle_true
        print wiggle
        for true, test in zip(wiggle_true, wiggle):
            self.assertAlmostEqual(test, true, 4)
示例#6
0
 def test_peaks_from_info(self):
     """
     
     Tests peak_from_info function, really badly, I'm basically making this so I can
     see if there is a memory leak
     
     """
     reads = pysam.Samfile(os.path.join(clipper.test_dir(), "allup_test.bam")) 
     reads = reads.fetch(region="chr15:91536649-91537641")
     loc = ['chr15', 'bar', 91536649, 91537641, "+"]
示例#7
0
 def test_peaks_from_info(self):
     """
     
     Tests peak_from_info function, really badly, I'm basically making this so I can
     see if there is a memory leak
     
     """
     reads = pysam.Samfile(os.path.join(clipper.test_dir(), "allup_test.bam")) 
     reads = reads.fetch(region="chr15:91536649-91537641")
     loc = ['chr15', 'bar', 91536649, 91537641, "+"]
示例#8
0
 def test_count_genomic_types(self):
     
     """
     
     Tests count genomic types
     
     """
     
     result, bed_result = parse_AS_STRUCTURE_dict("test", clipper.test_dir())
     result = count_genomic_types(result)
     
     self.assertDictEqual(result, {"CE:" : 14})
示例#9
0
    def test_count_genomic_types(self):
        """
        
        Tests count genomic types
        
        """

        result, bed_result = parse_AS_STRUCTURE_dict("test",
                                                     clipper.test_dir())
        result = count_genomic_types(result)

        self.assertDictEqual(result, {"CE:": 14})
示例#10
0
 def test_readsToWiggle_paysam_none(self):
     
     """
     
     Tests null input for reads to wiggle pysam
     
     """
     
     reads = pysam.Samfile(os.path.join(clipper.test_dir(), "allup_test.bam"))      
     reads = reads.fetch(region="chr15:91536649-91537641")
     
     self.assertRaises(TypeError, readsToWiggle_pysam, (None, 91537632, 91537675, '-', 'center', False))
示例#11
0
    def test_allup(self):
        
        """ runs entire program on small test dataset """

        args = ["--clusters", clipper.test_file("clip_analysis_test_peak_results.bed"),
                "-s", "mm9",
                "--bam", clipper.test_file("allup_test.bam"),
                "--AS_Structure", os.path.join(clipper.test_dir(), "mm9data4"),
                '--genome_location', clipper.test_file('mm9.fa'), 
                #'--regions_location', clipper.test_file("knownGene_sample.gtf"),
                "--regions_location", os.path.join(clipper.test_dir(), "regions"),
                '--phastcons_location', clipper.test_file("allup_test.bam"),
                '--motifs', 'AAAAAA',
                '--nrand', '1',
                #'--runPhast',
                '--runMotif',
                '--bw_pos', clipper.test_file("allup_test.pos.bw"),
                '--bw_neg', clipper.test_file("allup_test.neg.bw"),
                ]    
        (options, args) = self.parser.parse_args(args)
        #self.assertTrue(False, "allup test is slow and has been removed for now")
        main(options)
示例#12
0
 def test_assign_to_regions(self):
     
     """
     
     Basic test of assign to regions 
     
     """
     
     tool = pybedtools.BedTool(clipper.test_file("FOX2Brain-05.15.09.polyATrim.adapterTrim.rmRep.sorted.rmDup.peaks.bed"))
     
     assign_to_regions(tool=tool, 
                       clusters="test", 
                       speciesFA= clipper.test_file("mm9.fa"), 
                       regions_dir=os.path.join(clipper.test_dir(), "regions"), 
                       regions={"exons" : "Exon", "utr3" : "3' UTR", 
                                 "utr5" : "5' UTR", "proxintron500" : "Proximal Intron", 
                                 "distintron500" : "Distal Intron"} ,
                       assigned_dir = clipper.test_dir(),
                       fasta_dir = clipper.test_dir(),
                       species="mm9", 
                       nrand = 3, 
                       getseq=False)
示例#13
0
    def test_readsToWiggle_paysam_none(self):
        """
        
        Tests null input for reads to wiggle pysam
        
        """

        reads = pysam.Samfile(
            os.path.join(clipper.test_dir(), "allup_test.bam"))
        reads = reads.fetch(region="chr15:91536649-91537641")

        self.assertRaises(TypeError, readsToWiggle_pysam,
                          (None, 91537632, 91537675, '-', 'center', False))
示例#14
0
    def test_calculate_kmer_diff(self):
        """
        
        Tests calculate kmer diff
        
        Not testing computations (if kmer diff works) here, just that the dir structure is as it should be.  
        
        """

        result = calculate_kmer_diff([3, 4], ['all'],
                                     "clip_analysis_test_peak_results.bed",
                                     os.path.join(clipper.test_dir(), "test"))
        self.assertListEqual(result.keys(), ["all"])
        self.assertListEqual(result['all'].keys(), [3, 4])
示例#15
0
    def test_count_genomic_region_sizes(self):
        """
        
        Regression test to make sure we can count all genomic regions
        Need to write better test, for now we'll just make sure it doesn't crash
        
        """

        regions = OrderedDict()
        regions["exons"] = "Exon"
        regions["utr3"] = "3' UTR"
        regions["utr5"] = "5' UTR"
        regions["proxintron500"] = "Proximal\nIntron"
        regions["distintron500"] = "Distal\nIntron"
        results = count_genomic_region_sizes(
            os.path.join(clipper.test_dir(), "regions"), regions, "mm9")
示例#16
0
 def test_count_genomic_region_sizes(self):
     
     """
     
     Regression test to make sure we can count all genomic regions
     Need to write better test, for now we'll just make sure it doesn't crash
     
     """
     
     regions = OrderedDict()
     regions["exons"] = "Exon"
     regions["utr3"] = "3' UTR"
     regions["utr5"] = "5' UTR"
     regions["proxintron500"] = "Proximal\nIntron"
     regions["distintron500"] = "Distal\nIntron"
     results = count_genomic_region_sizes(os.path.join(clipper.test_dir(), "regions"), regions, "mm9")
示例#17
0
    def test_readsToWiggle_pysam_wiggles(self):
        
        """
            
        Tests the ability of reads to wiggle to generate correct wiggle files
        
        """
            
        reads = pysam.Samfile(os.path.join(clipper.test_dir(), "allup_test.bam"))      
        reads = reads.fetch(region="chr15:91536649-91537641")
        wiggle, jxns, pos_counts, lengths, allreads = readsToWiggle_pysam(reads, 91537632, 91537675, '-', 'center', True)

        wiggle_true = [0.06060606060606061, 0.06060606060606061, 0.06060606060606061, 0.06060606060606061, 0.06060606060606061, 0.06060606060606061, 0.06060606060606061, 0.06060606060606061, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.33333333333333326, 0.2727272727272727, 0.2727272727272727, 0.2727272727272727, 0.2727272727272727, 0.2727272727272727, 0.2727272727272727, 0.2727272727272727, 0.2727272727272727, 0.0, 0.0, 0.0]
        print wiggle_true
        print wiggle
        for true, test in zip(wiggle_true, wiggle):
            self.assertAlmostEqual(test, true, 4)
示例#18
0
 def test_calculate_kmer_diff(self):
     
     """
     
     Tests calculate kmer diff
     
     Not testing computations (if kmer diff works) here, just that the dir structure is as it should be.  
     
     """
     
     result = calculate_kmer_diff([3,4], ['all'], "clip_analysis_test_peak_results.bed", os.path.join(clipper.test_dir(), "test"))
     self.assertListEqual(result.keys(), ["all"])
     self.assertListEqual(result['all'].keys(), [3,4])
示例#19
0
    def test_parse_AS_STRUCTURE_dict(self):
        """
        
        Tests build AS structure dict
        
        """

        true_tool = pybedtools.BedTool(
            "chr10\t127496045\t127555714\tENSMUSG00000040054\t0\t+\n",
            from_string=True)

        result, result_bed = parse_AS_STRUCTURE_dict("test",
                                                     clipper.test_dir())
        print str(result_bed)
        self.assertEqual(len(true_tool.intersect(result_bed)), 1)
        test_result = result["ENSMUSG00000040054"]

        true_exons = {
            0: '127496045-127496082',
            1: '127528690-127528832',
            2: '127533494-127533579',
            3: '127545949-127546087',
            4: '127547810-127548404',
            5: '127549637-127549823',
            6: '127550518-127550737',
            7: '127551389-127551839',
            8: '127552080-127552141',
            9: '127553116-127553225',
            10: '127553361-127553463',
            11: '127553602-127553813',
            12: '127555610-127555714'
        }

        self.assertDictEqual(test_result["exons"], true_exons)

        self.assertDictEqual(
            test_result["introns"], {
                0: '127496083-127528689',
                1: '127528833-127533493',
                2: '127533580-127545948',
                3: '127546088-127547809',
                4: '127548405-127549636',
                5: '127549824-127550517',
                6: '127550738-127551388',
                7: '127551840-127552079',
                8: '127552142-127553115',
                9: '127553226-127553360',
                10: '127553464-127553601',
                11: '127553814-127555609'
            }, "introns not equal")

        self.assertDictEqual(
            test_result["types"], {
                0: "CE:",
                1: "CE:",
                2: "CE:",
                3: "CE:",
                4: "CE:",
                5: "CE:",
                6: "CE:",
                7: "CE:",
                8: "CE:",
                9: "CE:",
                10: "CE:",
                11: "CE:",
                12: "CE:"
            }, "types not equal")

        self.assertEqual(test_result["tx_stop"], 127555714)
        self.assertEqual(test_result["tx_start"], 127496045)
        self.assertEqual(test_result["premRNA_length"], 59670)
        self.assertEqual(test_result["mRNA_length"], 2451)
示例#20
0
    def test_parse_AS_STRUCTURE_dict(self):
        
        """
        
        Tests build AS structure dict
        
        """
        
        true_tool = pybedtools.BedTool("chr10\t127496045\t127555714\tENSMUSG00000040054\t0\t+\n", from_string=True)
        
        result, result_bed = parse_AS_STRUCTURE_dict("test", clipper.test_dir())
        print str(result_bed)
        self.assertEqual(len(true_tool.intersect(result_bed)), 1)
        test_result = result["ENSMUSG00000040054"]
        
        true_exons = {0:'127496045-127496082', 
                    1:'127528690-127528832',
                    2:'127533494-127533579', 
                    3:'127545949-127546087', 
                    4:'127547810-127548404', 
                    5:'127549637-127549823', 
                    6:'127550518-127550737', 
                    7:'127551389-127551839', 
                    8:'127552080-127552141', 
                    9:'127553116-127553225', 
                    10:'127553361-127553463', 
                    11:'127553602-127553813',
                    12:'127555610-127555714'}
        
  
        self.assertDictEqual(test_result["exons"], true_exons)
        
        self.assertDictEqual(test_result["introns"], {0 :'127496083-127528689', 
                                                     1 :'127528833-127533493', 
                                                     2 :'127533580-127545948', 
                                                     3 :'127546088-127547809', 
                                                     4 : '127548405-127549636',
                                                     5 :'127549824-127550517', 
                                                     6 :'127550738-127551388', 
                                                     7 :'127551840-127552079', 
                                                     8 : '127552142-127553115', 
                                                     9 : '127553226-127553360', 
                                                     10 : '127553464-127553601', 
                                                     11 :'127553814-127555609'}, 
                             "introns not equal")

        self.assertDictEqual(test_result["types"], {0 : "CE:", 
                                                    1 : "CE:", 
                                                    2 : "CE:", 
                                                    3 : "CE:",
                                                    4 : "CE:", 
                                                    5 : "CE:", 
                                                    6 : "CE:", 
                                                    7 : "CE:", 
                                                    8 : "CE:", 
                                                    9 : "CE:", 
                                                    10 : "CE:", 
                                                    11 : "CE:", 
                                                    12 : "CE:" }, 
                             "types not equal")

        self.assertEqual(test_result["tx_stop"], 127555714)
        self.assertEqual(test_result["tx_start"], 127496045)
        self.assertEqual(test_result["premRNA_length"], 59670)
        self.assertEqual(test_result["mRNA_length"], 2451)