Пример #1
0
 def test_convert_gff2bed_gene(self):
     bioformats.bed.convert_gff2bed_gene(self.__input_file,
                                         self.__output_file)
     # try to read the obtained BED file
     with open(self.__output_file) as bed_file:
         reader = Reader(bed_file)
         for _ in reader.records():
             pass
Пример #2
0
 def test_convert_gff2bed(self):
     bioformats.bed.convert_gff2bed(self.__input_file,
                                    self.__output_file,
                                    'exon')
     # try to read the obtained BED file
     with open(self.__output_file) as bed_file:
         reader = Reader(bed_file)
         for _ in reader.records():
             pass
     bioformats.bed.convert_gff2bed(self.__input_file,
                                    self.__output_file,
                                    'exon',
                                    attributes=['Parent'],
                                    name_tag='ID')
     # try to read the obtained BED file
     with open(self.__output_file) as bed_file:
         reader = Reader(bed_file)
         for _ in reader.records():
             pass
     bioformats.bed.convert_gff2bed(self.__input_file,
                                    self.__output_file,
                                    'exon',
                                    attributes=['Parent'],
                                    name_tag='NoTag')
     # try to read the obtained BED file
     with open(self.__output_file) as bed_file:
         reader = Reader(bed_file)
         for _ in reader.records():
             pass
Пример #3
0
 def test_columns(self):
     """
     Check if BED and auxiliary columns are correctly counted.
     """
     with open(self.__column_test_file) as bed_file:
         reader = Reader(bed_file)
         for i, record in enumerate(reader.records()):
             self.assertEqual(reader.bed_columns,
                              self.__correct_columns[i][0])
             self.assertEqual(reader.aux_columns,
                              self.__correct_columns[i][1])
Пример #4
0
 def test_bed(self):
     for i, j in iteritems(self.output_results):
         feature_filter = FlankNFilter(self.test_fa, flank_len=i[0])
         test_output = os.path.join('data', 'fasta', j) + '.bed'
         feature_filter.filter_bed(self.test_bed, self.output, i[1])
         with open(test_output) as correct_file:
             with open(self.output) as produced_file:
                 for k, l in zip(
                         Reader(correct_file).records(),
                         Reader(produced_file).records()):
                     self.assertEqual(k, l)
Пример #5
0
 def test_convert2bed(self):
     """
     Test the BED conversion routine.
     """
     fragment_map = Map()
     fragment_map.read(self.__test_line)
     fragment_map.convert2bed(self.__output_file)
     # try to read the produced BED file
     with open(self.__output_file) as bed_file:
         reader = Reader(bed_file)
         for _ in reader.records():
             pass
Пример #6
0
 def test_records(self):
     """
     Check if the parser reads a file in the BED format in the
     correct way.
     """
     # test against the correct input file
     parser = Reader(self.__correct_file)
     for record in parser.records():
         self.assertIsInstance(record, BedRecord)
     # test against the incorrect input file
     parser = Reader(self.__incorrect_file)
     with self.assertRaises(BedError):
         for record in parser.records():
             self.assertIsInstance(record, BedRecord)
Пример #7
0
    def test_fastagaps(self):
        """
        Test if gaps are correctly identified in a FASTA file.
        """
        sys.argv = ['', self.__fasta, self.__output_file]
        bioformats.cli.fastagaps()

        # compare the obtained BED file with the correct one
        correct_bed = Reader(self.__correct_bed)
        output_bed = Reader(self.__output_file)
        for x, y in zip(correct_bed.records(), output_bed.records()):
            self.assertEqual(x, y)

        os.unlink(self.__output_file)
        os.unlink(self.__fasta + '.fai')
Пример #8
0
    def test_write(self):
        """
        Check if BED records are written in the correct way.
        """
        bed_input = Reader(self.__input_file)
        with Writer(self.__output_file) as bed_output:
            for record in bed_input.records():
                bed_output.write(record)

        # check if the lines are identical
        with open(self.__input_file) as original_file, \
                open(self.__output_file) as written_file:
            for x, y in zip(original_file, written_file):
                self.assertEqual(x, y)

        os.unlink(self.__output_file)
Пример #9
0
    def test_write(self):
        """
        Check if BED records are written in the correct way.
        """
        for i in self.__input_file:
            with open(i) as bed_file:
                bed_input = Reader(bed_file)
                with Writer(self.__output_file) as bed_output:
                    for record in bed_input.records():
                        bed_output.write(record)

            # check if the lines are identical
            with open(i) as original_file, \
                    open(self.__output_file) as written_file:
                for x, y in zip(original_file, written_file):
                    self.assertEqual(x.rstrip(), y.rstrip())
Пример #10
0
 def test_get_autosql_table(self):
     for i in self.__input_file:
         with open(i) as bed_file:
             reader = Reader(bed_file)
             autosql_table = bioformats.bed.get_autosql_table(
                 reader
             )
             self.assertIsInstance(autosql_table,
                                   bioformats.autosql.Table)
             self.assertEqual(len(autosql_table.entries),
                              reader.bed_columns +
                              reader.aux_columns)
Пример #11
0
 def test_records(self):
     """
     Check if the parser reads a file in the BED format in the
     correct way.
     """
     # test against the correct input files
     for i in self.__correct_files:
         with open(i) as bed_file:
             parser = Reader(bed_file)
             for record in parser.records():
                 self.assertIsInstance(record, Record)
     # test against an unsorted input file
     for i in self.__correct_files:
         with open(i) as unsorted_bed_file:
             parser = Reader(unsorted_bed_file)
             with self.assertRaises(BedError):
                 for record in parser.records(check_order=True):
                     self.assertIsInstance(record, Record)
     # test against the incorrect input file
     with open(self.__incorrect_file) as bed_file:
         parser = Reader(bed_file)
         with self.assertRaises(BedError):
             for record in parser.records():
                 self.assertIsInstance(record, Record)
Пример #12
0
 def test_records(self):
     """
     Check if the parser reads a file in the BED format in the
     correct way.
     """
     # test against the correct input file
     parser = Reader(self.__correct_file)
     for record in parser.records():
         self.assertIsInstance(record, BedRecord)
     # test against the incorrect input file
     parser = Reader(self.__incorrect_file)
     with self.assertRaises(BedError):
         for record in parser.records():
             self.assertIsInstance(record, BedRecord)
Пример #13
0
    def test_fastagaps(self):
        """
        Test if gaps are correctly identified in a FASTA file.
        """
        sys.argv = ['', 'fastagaps', self.__fasta, self.__output_file]
        bioformats.cli.bioformats()

        # compare the obtained BED file with the correct one
        with open(self.__correct_bed) as correct_bed:
            with open(self.__output_file) as output_bed:
                correct_reader = Reader(correct_bed)
                output_reader = Reader(output_bed)
                for x, y in zip(correct_reader.records(),
                                output_reader.records()):
                    self.assertEqual(x, y)
Пример #14
0
    def test_fastagaps(self):
        """
        Test if gaps are correctly identified in a FASTA file.
        """
        sys.argv = ['', self.__fasta, self.__output_file]
        bioformats.cli.fastagaps()

        # compare the obtained BED file with the correct one
        correct_bed = Reader(self.__correct_bed)
        output_bed = Reader(self.__output_file)
        for x, y in zip(correct_bed.records(), output_bed.records()):
            self.assertEqual(x, y)

        os.unlink(self.__output_file)
        os.unlink(self.__fasta + '.fai')