예제 #1
0
 def load_consensus_file_repeat_ids(self):
     a = apply.Apply()
     a.consensus = {}
     consensus_file = os.path.join(data_dir, "consensus.fasta")
     a.load_consensus_file(consensus_file)
     self.assertRaises(AssertionError, a.load_consensus_file,
                       consensus_file)
예제 #2
0
 def test_load_coordinates_file_no_feature_list(self):
     coordinate_file = os.path.join(data_dir, "simple.coordinates")
     features_list = None
     a = apply.Apply()
     a.coordinates = {}
     a.load_coordinates_file(coordinate_file, features_list)
     expect_coordinates = {
         "ORF1": {
             "seq1": {
                 "start": 0,
                 "end": 90
             },
             "seq3": {
                 "start": 10,
                 "end": 100
             }
         },
         "ORF2": {
             "seq2": {
                 "start": 0,
                 "end": 126
             },
             "seq3": {
                 "start": 10,
                 "end": 136
             }
         }
     }
     self.assertEqual(a.coordinates, expect_coordinates)
예제 #3
0
파일: apply.py 프로젝트: rmcolq/genofunk
def run(options):
    if options.verbose:
        log_level = logging.DEBUG
        msg = "Using debug logging"
    else:
        log_level = logging.INFO
        msg = "Using info logging"

    #log_file = f"apply.log"
    #if os.path.exists(log_file):
    #    os.unlink(log_file)
    logging.basicConfig(
        #filename=log_file,
        stream=sys.stdout,
        level=log_level,
        format="%(asctime)s\t%(levelname)s\t%(message)s",
        datefmt="%d/%m/%Y %I:%M:%S",
    )
    logging.info(msg)
    logging.info(
        "Input parameters:\nDirectory: %s\nEdit file: %s\nFeatures: %s\nOutput prefix: %s\nConcatenate: %s"
                                                                                           %(options.directory,
                                                                                             options.edit_file,
                                                                                             options.features,
                                                                                             options.output_prefix,
                                                                                             options.concatinate)
    )

    g = apply.Apply()
    g.run(options.directory, options.edit_file, options.output_prefix, options.features, options.concatinate)
예제 #4
0
 def test_apply_loaded_edits_edits_empty(self):
     a = apply.Apply()
     editfile = os.path.join(data_dir, "all.edits")
     a.load_input_files(data_dir, edit_filepath=editfile)
     a.edits = EditFile()
     a.apply_loaded_edits()
     for name in a.consensus_sequence:
         self.assertEqual(a.consensus_sequence[name].seq,
                          self.a.consensus_sequence[name].seq)
예제 #5
0
 def test_run_with_no_features_concat(self):
     a = apply.Apply()
     editfile = os.path.join(data_dir, 'all.edits')
     tmp_prefix = os.path.join(data_dir, 'tmp')
     a.run(data_dir, editfile, tmp_prefix, concat=True)
     tmp_na_file = os.path.join(data_dir, 'tmp.na.fasta')
     expect_na_file = os.path.join(
         data_dir, 'expect_updated_na_consensus_concat.fasta')
     self.assertTrue(filecmp.cmp(tmp_na_file, expect_na_file,
                                 shallow=False))
     os.unlink(tmp_na_file)
     tmp_aa_file = os.path.join(data_dir, 'tmp.aa.fasta')
     expect_aa_file = os.path.join(
         data_dir, 'expect_updated_aa_consensus_concat.fasta')
     self.assertTrue(filecmp.cmp(tmp_aa_file, expect_aa_file,
                                 shallow=False))
     os.unlink(tmp_aa_file)
예제 #6
0
 def test_load_coordinates_file_with_feature_list(self):
     coordinate_file = os.path.join(data_dir, "simple.coordinates")
     features_list = ["ORF1", "idontexistinasample"]
     a = apply.Apply()
     a.coordinates = {}
     a.load_coordinates_file(coordinate_file, features_list)
     expect_coordinates = {
         "ORF1": {
             "seq1": {
                 "start": 0,
                 "end": 90
             },
             "seq3": {
                 "start": 10,
                 "end": 100
             }
         },
         "idontexistinasample": {}
     }
     self.assertEqual(a.coordinates, expect_coordinates)
예제 #7
0
 def test_load_edits_in_range_with_feature_list(self):
     a = apply.Apply()
     edit_file = os.path.join(data_dir, "simple_edits")
     features_list = ["ORF1", "idontexistinasample"]
     a.coordinates = {
         "ORF1": {
             "seq1": {
                 "start": 0,
                 "end": 90
             },
             "seq3": {
                 "start": 10,
                 "end": 100
             }
         },
         "idontexistinasample": {}
     }
     a.load_edits_in_range(edit_file, features_list)
     expect_edit_file = os.path.join(data_dir, "simple_edits_expect")
     expect_edits = EditFile(expect_edit_file)
     self.assertEqual(a.edits, expect_edits)
예제 #8
0
 def test_load_coordinates_file_with_join(self):
     coordinate_file = os.path.join(data_dir, "simple2.coordinates")
     features_list = ["ORF3", "idontexistinasample"]
     a = apply.Apply()
     a.coordinates = {}
     a.load_coordinates_file(coordinate_file, features_list)
     expect_coordinates = {
         "ORF3": {
             "seq6": {
                 "join": [{
                     "start": 0,
                     "end": 124
                 }, {
                     "start": 125,
                     "end": 128
                 }]
             }
         },
         "idontexistinasample": {}
     }
     self.assertEqual(a.coordinates, expect_coordinates)
예제 #9
0
 def setUp(self):
     self.a = apply.Apply()
     editfile = os.path.join(data_dir, 'all.edits')
     self.a.load_input_files(data_dir, editfile)
예제 #10
0
 def test_load_input_files_empty(self):
     a = apply.Apply()
     edit_file = os.path.join(data_dir, "all.edits")
     empty_dir = os.path.join(data_dir, "empty")
     self.assertRaises(AssertionError, a.load_input_files, empty_dir,
                       edit_file)
예제 #11
0
 def load_consensus_file(self):
     a = apply.Apply()
     a.consensus = {}
     consensus_file = os.path.join(data_dir, "consensus.fasta")
     a.load_consensus_file(consensus_file)
     self.assertEqual(len(a.consensus_sequence), 12)
예제 #12
0
 def test_load_consensus_file_empty(self):
     a = apply.Apply()
     a.consensus = {}
     consensus_file = os.path.join(data_dir, "empty.fasta")
     self.assertRaises(AssertionError, a.load_consensus_file,
                       consensus_file)
예제 #13
0
 def test_load_coordinates_file_empty(self):
     a = apply.Apply()
     a.coordinates = {}
     coordinate_file = os.path.join(data_dir, "empty.coordinates")
     self.assertRaises(json.JSONDecodeError, a.load_coordinates_file,
                       coordinate_file)
예제 #14
0
 def test_load_coordinates_file_does_not_exist(self):
     a = apply.Apply()
     a.coordinates = {}
     coordinate_file = os.path.join(data_dir, "doesnt_exist.coordinates")
     self.assertRaises(AssertionError, a.load_coordinates_file,
                       coordinate_file)
예제 #15
0
 def test_load_edits_in_range_no_coordinates(self):
     a = apply.Apply()
     edit_file = os.path.join(data_dir, "simple_edits")
     self.assertRaises(AssertionError, a.load_edits_in_range, edit_file)
예제 #16
0
 def test_load_input_files_missing_pair(self):
     a = apply.Apply()
     edit_file = os.path.join(data_dir, "all.edits")
     missing_dir = os.path.join(data_dir, "missing_consensus")
     self.assertRaises(AssertionError, a.load_input_files, missing_dir,
                       edit_file)
예제 #17
0
 def test_load_consensus_file_no_consensus(self):
     a = apply.Apply()
     consensus_file = os.path.join(data_dir, "doesnt_exist.fasta")
     self.assertRaises(AssertionError, a.load_consensus_file,
                       consensus_file)