Example #1
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()
Example #2
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()
Example #3
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)