コード例 #1
0
 def test_write_features_summary(self):
     # Set up some test data
     peak = Peak('chr2L',66811,66812)
     features = FeatureSet(
         features_list=(
             Feature('CG31973','chr2L',25402,59243,'-'),
             Feature('CG2674-RE','chr2L',106903,114433,'+'),
             Feature('CG2674-RC','chr2L',107926,114433,'+')))
     # Temp output file
     fp,summary = tempfile.mkstemp()
     # Write peaks to file
     ap = AnalysisReportWriter(output.MULTI_LINE,
                               fields=('peak.chr',
                                       'peak.start',
                                       'peak.end',
                                       'order',
                                       'feature.id',
                                       'dist_closest',
                                       'dist_TSS'),
                               summary=summary)
     ap.write_nearest_features(peak,features)
     ap.close()
     # Expected and actual output
     expected_output = \
         "#peak.chr\tpeak.start\tpeak.end\torder\tfeature.id\tdist_closest\tdist_TSS\n" \
         "chr2L\t66811\t66812\t1 of 3\tCG31973\t7568\t7568\n"
     actual_output = open(summary,'r').read()
     # Check that output matches
     self.assertEqual(expected_output,actual_output)
コード例 #2
0
 def setUp(self):
     # Set up some test data
     self.peak = Peak('chr2L',66811,66812)
     self.features = FeatureSet(
         features_list=(
             Feature('CG31973','chr2L',25402,59243,'-'),
             Feature('CG2674-RE','chr2L',106903,114433,'+'),
             Feature('CG2674-RC','chr2L',107926,114433,'+')))
     self.single_line_fields = ('peak.chr',
                                'peak.start',
                                'peak.end',
                                'number_of_results',
                                'list(feature.id,'
                                'dist_closest,dist_TSS)')
     self.single_line_fields_extra_data = ('peak.chr',
                                           'peak.start',
                                           'peak.end',
                                           'cutoff',
                                           'number_of_results',
                                           'list(feature.id,'
                                           'dist_closest,dist_TSS)')
     self.multi_line_fields = ('peak.chr',
                               'peak.start',
                               'peak.end',
                               'order',
                               'feature.id',
                               'dist_closest',
                               'dist_TSS')
コード例 #3
0
 def test_write_features_append(self):
     # Set up some test data
     peak = Peak('chr2L',66811,66812)
     features1 = FeatureSet(
         features_list=(
             Feature('CG31973','chr2L',25402,59243,'-'),
             Feature('CG2674-RE','chr2L',106903,114433,'+'),))
     features2 = FeatureSet(
         features_list=(
             Feature('CG2674-RC','chr2L',107926,114433,'+'),))
     # Temp output file
     fp,outfile = tempfile.mkstemp()
     # Write first set of nearest features
     ap = AnalysisReportWriter(output.MULTI_LINE,
                               fields=('peak.chr',
                                       'peak.start',
                                       'peak.end',
                                       'order',
                                       'feature.id',
                                       'dist_closest',
                                       'dist_TSS'),
                               outfile=outfile)
     ap.write_nearest_features(peak,features1)
     ap.close()
     # Write second set of nearest features
     ap = AnalysisReportWriter(output.MULTI_LINE,
                               fields=('peak.chr',
                                       'peak.start',
                                       'peak.end',
                                       'order',
                                       'feature.id',
                                       'dist_closest',
                                       'dist_TSS'),
                               outfile=outfile,
                               append=True)
     ap.write_nearest_features(peak,features2)
     ap.close()
     # Expected and actual output
     expected_output = \
         "#peak.chr\tpeak.start\tpeak.end\torder\tfeature.id\tdist_closest\tdist_TSS\n" \
         "chr2L\t66811\t66812\t1 of 2\tCG31973\t7568\t7568\n" \
         "chr2L\t66811\t66812\t2 of 2\tCG2674-RE\t40091\t40091\n" \
         "chr2L\t66811\t66812\t1 of 1\tCG2674-RC\t41114\t41114\n"
     actual_output = open(outfile,'r').read()
     # Check that output matches
     self.assertEqual(expected_output,actual_output)
コード例 #4
0
 def test_closest_transcript_to_peak(self):
     features = FeatureSet('Transcripts-ex1.txt')
     feature1 = features[1]
     feature2 = features[2]
     peaks = PeakSet('ChIP_peaks-ex1.txt')
     peak = peaks[0]
     nearest = GetNearestTranscriptToPeak(feature1, feature2, peak)
     # 2nd feature should be closer than first
     self.assertEqual(nearest, feature1,
                      "Wrong transcript selected as nearest")
     # test when only one is set
     nearest = GetNearestTranscriptToPeak(None, feature2, peak)
     self.assertEqual(nearest, feature2,
                      "Wrong transcript selected as nearest")