コード例 #1
0
ファイル: assemble.py プロジェクト: Xiuying/illumitag
 def __init__(self, path, parent):
     # Save parent #
     self.parent, self.outcome = parent, parent
     self.samples = parent.samples
     # Extra #
     self.pool = self.outcome.parent
     self.samples = self.pool.samples
     self.primers = self.pool.primers
     # Load #
     self.load()
     # Auto paths #
     self.p = AutoPaths(self.base_dir, self.all_paths)
     # All primer outcomes #
     self.good_primers     = GoodPrimers(self)
     self.wrong_primers    = WrongPrimers(self)
     self.only_fwd_primers = OnlyFwdPrimers(self)
     self.only_rev_primers = OnlyRevPrimers(self)
     self.no_primers       = NoPrimers(self)
     # Group them #
     self.children = (self.good_primers, self.wrong_primers, self.only_fwd_primers, self.only_rev_primers, self.no_primers)
コード例 #2
0
ファイル: assemble.py プロジェクト: Xiuying/illumitag
class AssembleGroup(object):
    """A bunch of sequences all having the same type of assembly outcome
    (and barcode outcome)"""

    primer_mismatches = 1

    def __iter__(self): return iter(self.children)
    def __repr__(self): return '<%s object of %s>' % (self.__class__.__name__, self.parent)
    def __len__(self): return self.count
    def __ne__(self, other): return not self.__eq__(other)

    def __init__(self, path, parent):
        # Save parent #
        self.parent, self.outcome = parent, parent
        self.samples = parent.samples
        # Extra #
        self.pool = self.outcome.parent
        self.samples = self.pool.samples
        self.primers = self.pool.primers
        # Load #
        self.load()
        # Auto paths #
        self.p = AutoPaths(self.base_dir, self.all_paths)
        # All primer outcomes #
        self.good_primers     = GoodPrimers(self)
        self.wrong_primers    = WrongPrimers(self)
        self.only_fwd_primers = OnlyFwdPrimers(self)
        self.only_rev_primers = OnlyRevPrimers(self)
        self.no_primers       = NoPrimers(self)
        # Group them #
        self.children = (self.good_primers, self.wrong_primers, self.only_fwd_primers, self.only_rev_primers, self.no_primers)

    @property
    def first(self): return self.children[0]

    @property
    def flipped_iterator(self):
        for r in self.parse_barcodes():
            if r.first.set == 'R' or r.last.set == 'F': yield reverse_compl_with_name(r.read)
            else: yield r.read

    def flip_reads(self):
        self.flipped_reads.write(self.flipped_iterator)

    def dont_flip_reads(self):
        self.flipped_reads.link_from(self.path)

    def make_primer_groups(self):
        for g in self.children: g.create()
        for r in self.flipped_reads.parse_primers(mismatches=self.primer_mismatches):
            if r.fwd_start_pos is not None and r.rev_start_pos is not None:
                if r.fwd_start_pos < 70 and r.rev_start_pos > -70: self.good_primers.add_seq(r.read)
                else:                                              self.wrong_primers.add_seq(r.read)
            elif r.fwd_start_pos:                                  self.only_fwd_primers.add_seq(r.read)
            elif r.rev_start_pos:                                  self.only_rev_primers.add_seq(r.read)
            else:                                                  self.no_primers.add_seq(r.read)
        for g in self.children: g.close()

    @property_cached
    def primer_positions(self):
        # Count positions #
        all_fwd_pos, all_rev_pos = Counter(), Counter()
        for r in self.flipped_reads.parse_primers():
            if r.fwd_pos is not None: all_fwd_pos.update((r.fwd_pos,))
            if r.rev_pos is not None: all_rev_pos.update((r.rev_pos,))
        # Return results #
        return all_fwd_pos, all_rev_pos

    def discard_reads_with_n(self):
        for g in self.children: g.n_filter()