Exemplo n.º 1
0
    def test_inverted(self):
        p = GATProfile(fragments=['1', '5', '7', '3\''])
        self.assertFalse(p.is_profile_in_correct_orientation())
        self.assertEqual(["1'", '3', "7'", "5'"], p.invert_fragments())

        p.orientate_for_dnaA()
        self.assertTrue(p.is_profile_in_correct_orientation())
Exemplo n.º 2
0
    def run_analysis(self, input_file, p, d):
        boundries = self.find_rrna_boundries(input_file)
        fragments = self.populate_fragments_from_chromosome(
            input_file, boundries)

        tmpdir = mkdtemp()
        self.dirs_to_cleanup.append(tmpdir)
        ff = FragmentFiles(fragments, tmpdir, self.verbose)
        ff.create_fragment_fastas()

        # take each fasta file and blast it against the database
        blast = Blast(d.db_prefix, self.threads, self.verbose)

        gat_profile = GATProfile(self.verbose, fragments=[])
        for current_fragment in ff.ordered_fragments:
            fasta_file = current_fragment.output_filename

            blast_results = blast.run_blast(fasta_file)
            fb = FilterBlast(blast_results, self.min_bit_score,
                             self.min_alignment_length, self.verbose)
            top_result = fb.return_top_result()
            if top_result is None:
                gat_profile.fragments.append('?')
                current_fragment.number = '?'

                with open(fasta_file, "r") as fasta_file_fh:
                    with open(self.new_fragments, "a+") as newfrag_fh:
                        newfrag_fh.write(fasta_file_fh.read())
                continue
            else:
                self.top_results.append(top_result)

                current_fragment.number = str(top_result.subject)
                if str(p.dnaA_fragment_number) == str(current_fragment.number):
                    current_fragment.dna_A = True

                if top_result.is_forward():
                    gat_profile.fragments.append(str(top_result.subject))
                else:
                    current_fragment.reversed_frag = True
                    gat_profile.fragments.append(
                        str(top_result.subject) + '\'')

        gat_profile.orientate_for_dnaA()
        reordered_frag_objs = gat_profile.reorder_fragment_objects_based_on_fragment_name_array(
            ff.ordered_fragments)
        pp = PlotProfile(reordered_frag_objs, self.output_plot_file,
                         self.verbose)
        pp.create_plot()

        # lookup the gat_profile to get the number
        tg = TypeGenerator(p, gat_profile, self.verbose)
        type_output_string = tg.calculate_type() + "\t" + str(gat_profile)
        self.write_novel_profile_to_file(tg, type_output_string)

        return type_output_string
Exemplo n.º 3
0
    def run_analysis(self, input_file, p, d):
        # run the fasta through barrnap
        fd, barrnap_outputfile = mkstemp()
        b = Barrnap(input_file, self.threads)
        subprocess.check_output(
           b.construct_barrnap_command(barrnap_outputfile), 
           shell=True)

        boundries = b.read_barrnap_output(barrnap_outputfile)
        
        f = Fasta(input_file, is_circular = self.is_circular)
        fragments = f.calc_fragment_coords( boundries)
        f.populate_fragments_from_chromosome(fragments, self.max_bases_from_ends)
        
        tmpdir = mkdtemp()
        self.dirs_to_cleanup.append(tmpdir)

        ff = FragmentFiles(fragments, tmpdir)
        ff.create_fragment_fastas()
        
         # take each fasta file and blast it against the database
        blast = Blast(d.db_prefix, self.threads)
        
        gat_profile = GATProfile(fragments = [])
        for fasta_file in ff.output_filenames:
            blast_results = blast.run_blast(fasta_file)
            fb = FilterBlast(blast_results, self.min_bit_score, self.min_alignment_length)
            top_result = fb.return_top_result()
            if top_result is None:
                gat_profile.fragments.append('?')
                fasta_file
                
                with open(fasta_file, "r") as fasta_file_fh:
                    with open(self.new_fragments, "a+") as newfrag_fh:
                        newfrag_fh.write(fasta_file_fh.read())
                continue
            else:
                self.top_results.append(top_result) 
            
            if top_result.is_forward():
                gat_profile.fragments.append( str(top_result.subject))
            else:
                gat_profile.fragments.append( str(top_result.subject)+ '\'')
        
        gat_profile.orientate_for_dnaA()
        # lookup the gat_profile to get the number
        tg = TypeGenerator(p, gat_profile)
        type_output_string  =  tg.calculate_type() + "\t" + str(gat_profile)
        if not tg.has_previously_seen:
            with open(self.novel_profiles, "a+") as output_fh:
                output_fh.write(self.db_dir + "\t" + type_output_string + "\n")
        
        return type_output_string
Exemplo n.º 4
0
 def read_profiles(self):
     with open(self.input_file, newline='') as csvfile:
         profile_reader = csv.reader(csvfile, delimiter='\t')
         # skip the header
         next(profile_reader)
         profiles = []
         for row in profile_reader:
             if len(row) > 2:
                 fragments = [
                     row[f] for f in range(1, len(row)) if row[f] != ''
                 ]
                 g = GATProfile(gat_number=row[0], fragments=fragments)
                 g.orientate_for_dnaA()
                 profiles.append(g)
         return profiles
Exemplo n.º 5
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