예제 #1
0
 def setUpClass(self):
    with warnings.catch_warnings():
       warnings.filterwarnings("ignore", "unclosed file <_io\.TextIOWrapper",  ResourceWarning,           "gffutils", 133 )
       warnings.filterwarnings("ignore", "generator '_FileIterator\.",         PendingDeprecationWarning, "gffutils", 186 )
       warnings.filterwarnings("ignore", "unclosed file <_io\.TextIOWrapper",  ResourceWarning,           "gffutils", 668 )
       self.test_gff_db = gffutils.create_db( test_gff_file,
                                              dbfn                    = test_gff_db_file,
                                              force                   = True,     # overwrite previous testing db file
                                              merge_strategy          = 'error',
                                              keep_order              = False,    # True doesn't appear to maintain attribute order :-/  (and turning this off may be faster)
                                              sort_attribute_values   = False
                                              )
       if(self.test_gff_db is not None and isinstance(self.test_gff_db, expected_db_class)):
          self.db_available = True
    self.gffmunger = GFFMunger(None)
예제 #2
0
 def test_050_gff_error_handling(self):
     """checks handling of non-fatal errors encountered in GFF"""
     yet_another_munger = GFFMunger(None)
     yet_another_munger.input_file_arg = broken_gff_file
     self.assertTrue(yet_another_munger.validate_GFF3(
         broken_gff_file))  # should pass validation despire bad relations
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore",
                                 "unclosed file <_io\.TextIOWrapper",
                                 ResourceWarning, "gffutils", 668)
         yet_another_munger.import_gff3(broken_gff_file)
         try:
             oldloglevel = yet_another_munger.logger.level
             yet_another_munger.logger.setLevel(logging.CRITICAL)
             yet_another_munger.move_polypeptide_annotations()
             yet_another_munger.logger.setLevel(oldloglevel)
         except AssertionError:
             self.fail(
                 "AssertionError should not be raised by GFFMunger.move_polypeptide_annotations() when processing annotations in "
                 + broken_gff_file)
     warnings.resetwarnings()
     yet_another_munger.clean_up()
예제 #3
0
class Validator_Tests(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.gffmunger = GFFMunger(None)

    def test_000_gt_installed(self):
        """check genometools is installed and exceuteable"""
        cp = subprocess.run([self.gffmunger.gt_path, gt_test_arg],
                            timeout=3,
                            stderr=subprocess.STDOUT,
                            stdout=subprocess.PIPE)
        success = 0 == cp.returncode
        if not success:
            print(cp.stdout)
        self.assertTrue(success)

    def test_010_gt_valid_gff_passes(self):
        """check GFFMunger.validate_GFF3 passes a valid GFF3 file"""
        self.assertTrue(self.gffmunger.validate_GFF3(test_gff_file))

    def test_020_gt_invalid_gff_fails(self):
        """check GFFMunger.validate_GFF3 fails an invalid GFF3 file"""
        self.assertFalse(
            self.gffmunger.validate_GFF3(
                bad_gff_file,
                silent=True))  # silence validation errors, which are expected

    def test_030_gt_valid_fasta_passes(self):
        """check GFFMunger.validate_FASTA passes a valid FASTA file"""
        self.assertTrue(self.gffmunger.validate_FASTA(test_fasta_file))

    def test_040_gt_invalid_fasta_fails(self):
        """check GFFMunger.validate_FASTA fails an invalid FASTA file"""
        self.assertFalse(
            self.gffmunger.validate_FASTA(
                bad_fasta_file,
                silent=True))  # silence validation errors, which are expected
예제 #4
0
class GFF_Tests(unittest.TestCase):

    test_gff_db = None
    db_available = False

    @classmethod
    def setUpClass(self):
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore",
                                    "unclosed file <_io\.TextIOWrapper",
                                    ResourceWarning, "gffutils", 133)
            warnings.filterwarnings("ignore", "generator '_FileIterator\.",
                                    PendingDeprecationWarning, "gffutils", 186)
            warnings.filterwarnings("ignore",
                                    "unclosed file <_io\.TextIOWrapper",
                                    ResourceWarning, "gffutils", 668)
            self.test_gff_db = gffutils.create_db(
                test_gff_file,
                dbfn=str(test_gff_db_file).replace('<uid>',
                                                   uuid.uuid4().hex),
                force=True,  # overwrite previous testing db file
                merge_strategy='error',
                keep_order=
                False,  # True doesn't appear to maintain attribute order :-/  (and turning this off may be faster)
                sort_attribute_values=False)
            if (self.test_gff_db is not None
                    and isinstance(self.test_gff_db, expected_db_class)):
                self.db_available = True
        self.gffmunger = GFFMunger(None)

    def test_000_db_created(self):
        """test that gffutils.create_db was able to create a database from the sample GFF file"""
        #self.assertIsNotNone(self.test_gff_db)
        #self.assertIsInstance(self.test_gff_db, expected_db_class)
        self.assertTrue(self.db_available)

    #@unittest.skipUnless(db_available, "no db available")
    def test_010_gffutils_find_gene(self):
        """test that gffutils can find a sample gene identifier from the GFF"""
        if (not self.db_available):
            self.skipTest('no db available')
        this_gene = self.test_gff_db[sample_gff_gene_id]
        self.assertIsNotNone(this_gene)
        self.assertIsInstance(this_gene, expected_feature_class)

    def test_020_gffutils_find_features(self):
        """test that gffutils can find features in GFF"""
        if (not self.db_available):
            self.skipTest('no db available')
        for this_featuretype in sample_gff_featuretypes:
            for this_feature in self.test_gff_db.children(
                    sample_gff_gene_id, featuretype=this_featuretype):
                self.assertIsNotNone(this_feature)
                self.assertIsInstance(this_feature, expected_feature_class)
                # print(this_feature)

    def test_030_gffutils_find_attributes(self):
        """test that gffutils can find attributes in GFF"""
        if (not self.db_available):
            self.skipTest('no db available')
        for this_featuretype in sample_gff_featuretypes:
            for this_feature in self.test_gff_db.children(
                    sample_gff_gene_id, featuretype=this_featuretype):
                #print(this_feature)
                self.assertIsNotNone(this_feature)
                self.assertIsInstance(this_feature, expected_feature_class)
                these_attributes = this_feature.attributes
                self.assertIsNotNone(these_attributes)
                self.assertIsInstance(these_attributes,
                                      expected_attributes_class)
                for this_item in sorted(these_attributes.items()):
                    self.assertIsNotNone(this_item)
                    #print('{this_item[0]}: {this_item[1]}'.format(this_item=this_item))

    def test_040_gff_components_no_fasta(self):
        """test separation of GFF3 file without FASTA, into metadata and features """
        self.gffmunger.extract_GFF3_components(test_gff_file)
        self.assertIsNotNone(self.gffmunger.input_metadata)
        if self.gffmunger.read_features_to_buffer:
            self.assertIsNotNone(self.gffmunger.input_features)
        else:
            self.assertIsNone(self.gffmunger.input_features)
        self.assertIsNone(self.gffmunger.input_fasta)

    def test_045_gff_components_with_fasta(self):
        """test separation of GFF3 file with FASTA, into metadata, features and FASTA data"""
        self.gffmunger.extract_GFF3_components(test_gff_and_fasta_file)
        self.assertIsNotNone(self.gffmunger.input_fasta)
예제 #5
0
 def test_020_gff3_i0(self):
     """check functions for retreiving input filename, and reading and validating a GFF3 file and separate FASTA file"""
     newmunger = GFFMunger(None)
     newmunger.input_file_arg = test_gff_no_fasta
     newmunger.fasta_file_arg = test_fasta_file
     newmunger.output_file = self.output_file
     self.assertEqual(test_gff_no_fasta, newmunger.get_gff3_source())
     self.assertTrue(newmunger.validate_GFF3(test_gff_no_fasta))
     self.assertTrue(newmunger.validate_FASTA(test_fasta_file))
     self.assertEqual(newmunger.gffutils_db_filename,
                      newmunger.import_gff3())
     self.assertEqual(newmunger.gffutils_db_filename,
                      newmunger.import_gff3(test_gff_no_fasta))
     # when FASTA is in separate file, GFFMunger.extract_GFF3_components() should read only metadata
     self.assertEqual(expected_num_metadata_lines,
                      newmunger.extract_GFF3_components())
     self.assertEqual(expected_num_metadata_lines,
                      newmunger.extract_GFF3_components(test_gff_no_fasta))
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore", "unclosed file <_io\.FileIO",
                                 ResourceWarning, "six", 581)
         warnings.filterwarnings("ignore", "", ResourceWarning, "gffutils",
                                 0)
         self.assertIsInstance(newmunger.import_fasta(), pyfaidx.Fasta)
         self.assertIsInstance(newmunger.import_fasta(test_fasta_file),
                               pyfaidx.Fasta)
         try:
             newmunger.move_polypeptide_annotations()
         except:
             self.fail("Failed to process valid GFF3 file " +
                       test_gff_no_fasta)
     warnings.resetwarnings()
     self.assertTrue(newmunger.export_gff3())
     os.remove(newmunger.output_file)
     newmunger.clean_up()
예제 #6
0
 def test_000_gff3_with_fasta_io(self):
     """check functions for reading and validating a GFF3 file including FASTA, and writing it as output"""
     gffmunger = GFFMunger(None)
     gffmunger.input_file_arg = test_gff_file
     gffmunger.output_file = self.output_file
     self.assertEqual(test_gff_file, gffmunger.get_gff3_source())
     self.assertTrue(gffmunger.validate_GFF3(test_gff_file))
     self.assertEqual(gffmunger.gffutils_db_filename,
                      gffmunger.import_gff3())
     self.assertEqual(gffmunger.gffutils_db_filename,
                      gffmunger.import_gff3(test_gff_file))
     self.assertEqual(expected_num_input_lines,
                      gffmunger.extract_GFF3_components())
     self.assertEqual(expected_num_input_lines,
                      gffmunger.extract_GFF3_components(test_gff_file))
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore",
                                 "unclosed file <_io\.TextIOWrapper",
                                 ResourceWarning, "gffutils", 668)
         try:
             gffmunger.move_polypeptide_annotations()
         except:
             self.fail("Failed to process valid GFF3 file " + test_gff_file)
     warnings.resetwarnings()
     self.assertTrue(gffmunger.export_gff3())
     os.remove(gffmunger.output_file)
     gffmunger.clean_up()
예제 #7
0
 def setUpClass(self):
     self.gffmunger = GFFMunger(None)