示例#1
0
    def filter_calls_by_sample(self, samples, reverse=False, keep_info=False):
        calls = [self.get_call(sample).call for sample in samples]
        if reverse:
            all_samples = set([c.sample for c in self.calls])
            chosen_samples = set([c.sample for c in calls])
            unchosen_samples = all_samples.difference(chosen_samples)
            calls = [self.get_call(sample).call for sample in unchosen_samples]

        sample_indexes = {call.sample: idx for idx, call in enumerate(calls)}

        int_alleles = set()
        for call in calls:
            if call.called:
                int_alleles.update([int(allele) for allele in call.gt_alleles])

        record = self.record
        alt_alleles = [a for i, a in enumerate(record.ALT) if i + 1 in int_alleles]
        if not alt_alleles:
            alt_alleles.append(None)
        info = record.INFO if keep_info else {}
        record = pyvcfRecord(record.CHROM, record.POS, record.ID,
                             record.REF, alt_alleles, record.QUAL,
                             record.FILTER, info, record.FORMAT,
                             sample_indexes, calls)
        snv = SNV(record, self.reader,
                  min_calls_for_pop_stats=self.min_calls_for_pop_stats)
        return snv
示例#2
0
 def copy_mapping_calls(self, call_mapper):
     calls = []
     sample_indexes = {}
     is_list = True if isinstance(call_mapper, list) else False
     for index, call in enumerate(self.calls):
         sample = call.sample
         if is_list:
             call = call_mapper[index]
         else:
             call = call_mapper(call)
         calls.append(call)
         sample_indexes[sample] = index
     record = self.record
     record = pyvcfRecord(record.CHROM, record.POS, record.ID,
                          record.REF, record.ALT, record.QUAL,
                          record.FILTER, record.INFO, record.FORMAT,
                          sample_indexes, calls)
     snv = SNV(record, self.reader,
               min_calls_for_pop_stats=self.min_calls_for_pop_stats)
     return snv