Example #1
0
    def create_standard_fragments(self, profile_db):
        reference_profile = profile_db.gats[0]

        ref_frags = []
        # get the basic details
        for frag_number in reference_profile.orientationless_fragments():
            f = Fragment([],
                         number=frag_number,
                         operon_forward_start=False,
                         dna_A=False,
                         dif=False)
            if str(frag_number) == str(profile_db.dnaA_fragment_number):
                f.dna_A = True
            if str(frag_number) == str(profile_db.dif_fragment_number):
                f.dif = True
            ref_frags.append(f)

        # reorientate to dnaA
        dna_start_frags = self.reorientate_ori(ref_frags)
        dnaa_index = self.find_dnaa(dna_start_frags)
        dif_index = self.find_dif(dna_start_frags)
        if dnaa_index == -1 or dif_index == -1:
            return []

        # forward walk (reverse is already set )
        for i in range(dnaa_index, dif_index):
            if i >= dif_index:
                # we have reached the end
                continue
            else:
                dna_start_frags[i].operon_forward_start = True

        return dna_start_frags
Example #2
0
    def calc_fragment_coords(self, boundries):
        genome_length = len(self.chromosome.seq)
        fragments = []

        start_coord = 0
        end_coord = genome_length

        # check to see if one of the fragments goes over the end
        end_frag = [b for b in boundries if b[0] > b[1]]
        if len(end_frag) > 0:
            self.is_circular = False
            del boundries[-1]
            start_coord = end_frag[0][1]
            end_coord = end_frag[0][0]

        if self.is_circular:
            # first - we assume its circular
            f = Fragment([[boundries[-1][1], genome_length],
                          [0, boundries[0][0]]])
            fragments.append(f)
        else:
            f = Fragment([[boundries[-1][1], end_coord]])
            fragments.append(f)
            f = Fragment([[start_coord, boundries[0][0]]])
            fragments.append(f)

        for i in range(0, len(boundries) - 1):
            fragments.append(Fragment([[boundries[i][1],
                                        boundries[i + 1][0]]]))
        return fragments
Example #3
0
    def test_plot_profile_some_reversed(self):
        fragments = []
        fragments.append(
            Fragment([],
                     sequence="AAAA",
                     number=1,
                     reversed_frag=True,
                     dna_A=True))
        fragments.append(
            Fragment([],
                     sequence="AAA",
                     number=3,
                     reversed_frag=False,
                     dna_A=False))
        fragments.append(
            Fragment([],
                     sequence="AAAAAAAAAA",
                     number=2,
                     reversed_frag=True,
                     dna_A=False))
        fragments.append(
            Fragment([],
                     sequence="A",
                     number=4,
                     reversed_frag=False,
                     dna_A=False))

        p = PlotProfile(fragments, 'plot2.pdf', False)
        p.create_plot()

        self.assertTrue(os.path.exists('plot2.pdf'))
        os.remove('plot2.pdf')
Example #4
0
    def create_fragments(self, input_profile, standard_fragments):
        frags = []
        # get the basic details

        reversed_frags = input_profile.orientation_array()
        for i, frag_number in enumerate(
                input_profile.orientationless_fragments()):
            f = Fragment([],
                         number=frag_number,
                         operon_forward_start=False,
                         dna_A=False,
                         dif=False,
                         reversed_frag=not reversed_frags[i])
            if str(frag_number) == str(input_profile.dnaA_fragment_number):
                f.dna_A = True
            if str(frag_number) == str(input_profile.dif_fragment_number):
                f.dif = True
            frags.append(f)

        # loop over the standard and set the direction (if inverted, then invert)
        for f in frags:
            for s in standard_fragments:
                if f.number == s.number:
                    f.operon_forward_start = s.operon_forward_start

            #if f.dna_A:
            #    f.operon_forward_start = True
            #if f.dif:
            #    f.operon_forward_start = False

            if f.reversed_frag:
                f.operon_forward_start = not f.operon_forward_start

        return frags
    def calc_fragment_coords(self, boundries):
        genome_length = len(self.chromosome.seq)
        fragments = []
        if not boundries:
            return []

        start_coord = 0
        end_coord = genome_length

        # check to see if one of the fragments goes over the end
        end_frag = [b for b in boundries if b.start > b.end]
        if len(end_frag) > 0:
            self.is_circular = False
            del boundries[-1]
            start_coord = end_frag[0].end
            end_coord = end_frag[0].start

        if self.is_circular:
            # first - we assume its circular
            f = Fragment(
                [[boundries[-1].end, genome_length], [0, boundries[0].start]],
                operon_forward_start=boundries[-1].direction,
                operon_forward_end=boundries[0].direction)
            fragments.append(f)
        else:
            f = Fragment([[boundries[-1].end, end_coord]],
                         operon_forward_start=boundries[-1].direction)
            fragments.append(f)
            f = Fragment([[start_coord, boundries[0].start]],
                         operon_forward_end=boundries[0].direction)
            fragments.append(f)

        for i in range(0, len(boundries) - 1):
            fragments.append(
                Fragment([[boundries[i].end, boundries[i + 1].start]],
                         operon_forward_start=boundries[i].direction,
                         operon_forward_end=boundries[i + 1].direction))
        return fragments
Example #6
0
 def test_term_first_valid(self):
     # --> 1'(Ter) <-- 6' <-- 3 <-- 4 <-- 5(Ori) --> 2'
     fragments = []
     fragments.append(Fragment([], number = 1, operon_forward_start = False, dna_A = False, dif = True))
     fragments.append(Fragment([], number = 6, operon_forward_start = False, dna_A = False, dif = False))
     fragments.append(Fragment([], number = 3, operon_forward_start = False, dna_A = False, dif = False))    
     fragments.append(Fragment([], number = 4, operon_forward_start = False, dna_A = False, dif = False))         
     fragments.append(Fragment([], number = 5, operon_forward_start = True, dna_A = True, dif = False))   
     fragments.append(Fragment([], number = 2, operon_forward_start = True, dna_A = False, dif = False)) 
     
     vf = ValidateFragments(fragments)
     self.assertTrue(vf.validate())
Example #7
0
 def test_fragment_seq_name_one_coord(self):
     f = Fragment([[10, 123]])
     self.assertEqual(str(f), '0 10_123')
Example #8
0
 def test_fragment_seq_name_two_coords(self):
     f = Fragment([[10, 123], [555, 999]])
     self.assertEqual(str(f), '0 10_123__555_999')