Esempio n. 1
0
    def __init__(self, options):
        self.socru_output_filename = options.socru_output_filename
        self.profile_filename = options.profile_filename
        self.output_file = options.output_file

        shutil.copy(self.profile_filename, self.output_file)
        self.profiles = Profiles(self.profile_filename)
        self.results = Results(self.socru_output_filename)
Esempio n. 2
0
 def test_type_generator_valid(self):
     profiles = Profiles(os.path.join(data_dir, 'initial_profiles.txt'),
                         False)
     p = GATProfile(False,
                    fragments=['1', '7\'', '6\'', '4\'', '5\'', '3', '2\''])
     tg = TypeGenerator(profiles, p, False, prefix='GS')
     self.assertEqual(2, tg.calculate_orientationless_order())
     self.assertEqual('GS2.122', tg.calculate_type())
Esempio n. 3
0
 def test_type_generator_valid_seen(self):
     profiles = Profiles(os.path.join(data_dir, 'initial_profiles.txt'),
                         False)
     p = GATProfile(False, fragments=['1', '2', '3', '5', '4', '6', '7'])
     tg = TypeGenerator(profiles, p, False, True, prefix='GS')
     self.assertEqual(2, tg.calculate_orientationless_order())
     self.assertEqual('GREEN', tg.quality)
     self.assertEqual('GS2.0', tg.calculate_type())
Esempio n. 4
0
    def calc_type(self):
        profile_db = Profiles(os.path.join(self.db_dir, 'profile.txt'))

        split_fragments = self.fragments.split('-')
        input_profile = GATProfile(fragments=split_fragments)

        tg = TypeGenerator(profile_db, input_profile)
        return tg.calculate_type()
Esempio n. 5
0
    def test_profiles(self):
        p = Profiles(os.path.join(data_dir, 'profile.txt'), False)
        self.assertEqual(7, len(p.gats))
        self.assertEqual("1	2	3	4	5	6	7", str(p.gats[0]))

        p.gats[0].fragments = p.gats[0].invert_fragments()
        self.assertEqual("1'	7'	6'	5'	4'	3'	2'", str(p.gats[0]))

        self.assertEqual(5, p.dnaA_fragment_number)
Esempio n. 6
0
 def run(self):
     # load the profiles
     p = Profiles(os.path.join(self.db_dir, 'profile.txt'))
     d = Database(self.db_dir)
     
     for i in self.input_files:
         output_type = self.run_analysis(i, p, d)
         self.output_results(i, output_type)
         
     if self.top_blast_hits is not None:
         with open(self.top_blast_hits, "a+") as output_fh:
             for h in self.top_results:
                 output_fh.write(str(h)+"\n")
Esempio n. 7
0
    def type_generator(self):
        profile_db = Profiles(os.path.join(self.db_dir, 'profile.txt'),
                              self.verbose)

        split_fragments = self.fragments.split('-')
        input_profile = GATProfile(
            self.verbose,
            fragments=split_fragments,
            dnaA_fragment_number=profile_db.dnaA_fragment_number,
            dif_fragment_number=profile_db.dif_fragment_number)
        input_profile.orientate_for_dnaA()

        is_profile_valid = self.validate_profile(profile_db, input_profile)
        tg = TypeGenerator(profile_db, input_profile, self.verbose,
                           is_profile_valid)
        return tg
class SocruUpdateProfile:
    def __init__(self, options):
        self.socru_output_filename = options.socru_output_filename
        self.profile_filename = options.profile_filename
        self.output_file = options.output_file
        self.verbose = options.verbose

        shutil.copy(self.profile_filename, self.output_file)
        self.profiles = Profiles(self.profile_filename, self.verbose)
        self.results = Results(self.socru_output_filename, self.verbose)

    def run(self):
        valid_profiles_not_db_checked = self.results.filter(
            self.profiles.num_fragments)
        valid_profiles = []

        for input_profile in valid_profiles_not_db_checked:
            match_found = False
            for db_profile in self.profiles.gats:
                if db_profile.does_the_profile_match(input_profile):
                    match_found = True
                    continue

            if not match_found:
                valid_profiles.append(input_profile)

        with open(self.output_file, "a+") as output_fh:
            for p in valid_profiles:
                tg = TypeGenerator(self.profiles,
                                   p,
                                   self.verbose,
                                   True,
                                   prefix='')
                # get orientationless versions of p and db
                # check if there is an order number assigned, if not generate the next one.
                order_to_use = tg.calculate_orientationless_order()
                if order_to_use == 0:
                    order_to_use = self.profiles.next_order_number()

                p.gat_number = str(order_to_use) + '.' + str(
                    p.orientation_binary())
                self.profiles.gats.append(p)

                novel_type = p.gat_number + "\t" + str(p)
                output_fh.write(novel_type + "\n")
Esempio n. 9
0
 def run(self):
     # load the profiles
     if self.verbose:
         print("Loading profiles:\t" + os.path.join(self.db_dir, 'profile.txt'))
     p = Profiles(os.path.join(self.db_dir, 'profile.txt'), self.verbose)
     
     if self.verbose:
         print("Loading database:\t" + self.db_dir)
     d = Database(self.db_dir, self.verbose)
     
     for i in self.input_files:
         if self.verbose:
             print("Beginning analysis of input file:\t" + i)
         output_type = self.run_analysis(i, p, d)
         self.output_results(i, output_type)
         
     if self.top_blast_hits is not None:
         with open(self.top_blast_hits, "a+") as output_fh:
             for h in self.top_results:
                 output_fh.write(str(h)+"\n")