Esempio n. 1
0
    def haplotypes(self, fragment, start, stop, VERBOSE=0, maxreads=-1, filters=None):
        from hivwholeseq.patients.get_local_haplotypes import get_local_haplotypes
        from .filenames import get_mapped_filtered_filename

        bam_fname = get_mapped_filtered_filename(self.patient, self.name, fragment, type='bam', decontaminated=True)
        try:
            return get_local_haplotypes(bam_fname, start, stop)
        except:
            raise ValueError("can't read haplotypes")
Esempio n. 2
0
    def haplotypes(self, fragment, start, stop, VERBOSE=0, maxreads=-1, filters=None):
        from hivwholeseq.patients.get_local_haplotypes import get_local_haplotypes
        from .filenames import get_mapped_filtered_filename

        bam_fname = get_mapped_filtered_filename(self.patient, self.name, fragment, type='bam', decontaminated=True)
        try:
            return get_local_haplotypes(bam_fname, start, stop)
        except:
            raise ValueError("can't read haplotypes")
Esempio n. 3
0
    def get_local_haplotypes(self,
                             fragment,
                             start,
                             end,
                             VERBOSE=0,
                             maxreads=-1,
                             filters=None,
                             PCR=1):
        '''Get local haplotypes'''
        from hivwholeseq.patients.get_local_haplotypes import get_local_haplotypes
        bamfilename = self.get_mapped_filtered_filename(fragment, PCR=PCR)
        haplo = get_local_haplotypes(bamfilename,
                                     start,
                                     end,
                                     VERBOSE=VERBOSE,
                                     maxreads=maxreads,
                                     label=self.name)

        if filters is not None:
            if 'noN' in filters:
                hnames = [hname for hname in haplo.iterkeys() if 'N' in hname]
                for hname in hnames:
                    del haplo[hname]

            if 'nosingletons' in filters:
                hnames = [hname for hname, c in haplo.iteritems() if c <= 1]
                for hname in hnames:
                    del haplo[hname]

            if any('mincount=' in ft for ft in filters):
                for ft in filters:
                    if 'mincount=' in ft:
                        break
                cmin = int(ft[len('mincount='):])
                hnames = [hname for hname, c in haplo.iteritems() if c < cmin]
                for hname in hnames:
                    del haplo[hname]

            if any('freqmin=' in ft for ft in filters):
                for ft in filters:
                    if 'freqmin=' in ft:
                        break
                fmin = float(ft[len('minfreq='):])
                csum = sum(haplo.itervalues())
                hnames = [
                    hname for hname, c in haplo.iteritems() if c < fmin * csum
                ]
                for hname in hnames:
                    del haplo[hname]

        return haplo