diff --git a/docs/HISTORY.rst b/docs/HISTORY.rst index 396ffa7..085e24c 100644 --- a/docs/HISTORY.rst +++ b/docs/HISTORY.rst @@ -17,6 +17,16 @@ New features should have test code sent with them. Changes ======= +0.6.0 Release +------------- + +* Backwards incompatible change: _Call.data is now a + namedtuple (previously it was a dict) +* Optional cython version, much improved performance. +* Improvements to writer (thanks @cmclean) +* Improvements to inheritance of classes (thanks @lennax) + + 0.5.0 Release ------------- diff --git a/vcf/__init__.py b/vcf/__init__.py index 2935c73..f7aa7ca 100644 --- a/vcf/__init__.py +++ b/vcf/__init__.py @@ -177,4 +177,4 @@ from vcf.filters import Base as Filter from vcf.parser import RESERVED_INFO, RESERVED_FORMAT -VERSION = '0.5.0' +VERSION = '0.6.0' diff --git a/vcf/model.py b/vcf/model.py index 9a27f87..9748784 100644 --- a/vcf/model.py +++ b/vcf/model.py @@ -2,6 +2,7 @@ import collections import sys + class _Call(object): """ A genotype call, a cell entry in a VCF file""" @@ -20,7 +21,7 @@ def __init__(self, site, sample, data): self.called = self.gt_nums is not None except AttributeError: self.gt_nums = None - # FIXME how do we know if a non GT call is called? + #62 a call without a genotype is not defined as called or not self.called = None def __repr__(self): @@ -70,10 +71,14 @@ def gt_type(self): if self.called: alleles = self.gt_alleles if all(X == alleles[0] for X in alleles[1:]): - if alleles[0] == "0": return 0 - else: return 2 - else: return 1 - else: return None + if alleles[0] == "0": + return 0 + else: + return 2 + else: + return 1 + else: + return None @property def phased(self): @@ -145,7 +150,7 @@ def __str__(self): return "Record(CHROM=%(CHROM)s, POS=%(POS)s, REF=%(REF)s, ALT=%(ALT)s)" % self.__dict__ def __cmp__(self, other): - return cmp( (self.CHROM, self.POS), (other.CHROM, other.POS)) + return cmp((self.CHROM, self.POS), (other.CHROM, other.POS)) def add_format(self, fmt): self.FORMAT = self.FORMAT + ':' + fmt @@ -199,7 +204,6 @@ def aaf(self): # skip if more than one alternate allele. assumes bi-allelic if len(self.ALT) > 1: return None - hom_ref = self.num_hom_ref het = self.num_het hom_alt = self.num_hom_alt num_chroms = float(2.0 * self.num_called) @@ -244,7 +248,8 @@ def get_unknowns(self): @property def is_snp(self): """ Return whether or not the variant is a SNP """ - if len(self.REF) > 1: return False + if len(self.REF) > 1: + return False for alt in self.ALT: if alt is None or alt.type != "SNV": return False @@ -257,7 +262,8 @@ def is_indel(self): """ Return whether or not the variant is an INDEL """ is_sv = self.is_sv - if len(self.REF) > 1 and not is_sv: return True + if len(self.REF) > 1 and not is_sv: + return True for alt in self.ALT: if alt is None: return True @@ -284,7 +290,8 @@ def is_sv(self): def is_transition(self): """ Return whether or not the SNP is a transition """ # if multiple alts, it is unclear if we have a transition - if len(self.ALT) > 1: return False + if len(self.ALT) > 1: + return False if self.is_snp: # just one alt allele @@ -294,14 +301,17 @@ def is_transition(self): (self.REF == "C" and alt_allele == "T") or (self.REF == "T" and alt_allele == "C")): return True - else: return False - else: return False + else: + return False + else: + return False @property def is_deletion(self): """ Return whether or not the INDEL is a deletion """ # if multiple alts, it is unclear if we have a transition - if len(self.ALT) > 1: return False + if len(self.ALT) > 1: + return False if self.is_indel: # just one alt allele @@ -310,8 +320,10 @@ def is_deletion(self): return True if len(self.REF) > len(alt_allele): return True - else: return False - else: return False + else: + return False + else: + return False @property def var_type(self): diff --git a/vcf/test/prof.py b/vcf/test/prof.py index 62c72fe..953d169 100755 --- a/vcf/test/prof.py +++ b/vcf/test/prof.py @@ -1,4 +1,4 @@ -import vcf +import vcf as vcf import cProfile import timeit import pstats