Skip to content

Commit

Permalink
added docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Chafin committed Feb 3, 2020
1 parent 7a8931b commit aa8fe7c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion SNPcall.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@
import random

def rebuild(pos, calls):
"""function for rebuilding a SNPcall object given its own values. necessary to make SNPcall objects pickle-able"""
sc = SNPcall(pos, calls)
return(sc)

cdef class SNPcall(object):
"""custom class for storing SNP nodes for IntervalTree; stores individual sample calls as a list, and a coordinate"""
cdef public:
int position
list calls

def __init__(self, pos, samps):
"""constructor for SNPcall"""
self.position = int(pos)
self.calls = list(samps)

# def __lt__(self, other):
# return(self.position < other.position)

def __richcmp__(self, other, op):
"""special method defining comparison rules for SNPcall objects"""
if op == 2:#Py_EQ
return(self.position == other.position)
elif op == 3:#Py_NE
Expand Down Expand Up @@ -48,6 +52,7 @@ cdef class SNPcall(object):

#TODO:try to speed this up. 32% of runtime currently
def FGT(self, other, rule):
"""method for comparing a SNPcall object (self) with another SNPcall object to run four-gamete test. Returns: boolean"""
#print("Four gamete test for",self.position,"and",other.position)
cdef list gametes = [0,0,0,0] #00, 01, 10, 11
cdef list hets = list()
Expand Down Expand Up @@ -105,6 +110,7 @@ cdef class SNPcall(object):
@staticmethod
#TODO: Optimize; currently 11% of runtime after 2X speedup
def hapCheck(geno):
"""finds gametes from a genotype"""
#print(geno)
if geno[0] == 0:
if geno[1] == 0:
Expand All @@ -124,6 +130,7 @@ cdef class SNPcall(object):
return(9)

def optimisticFGT(self, seen, hets):
""" Function returns True if any genotype comparison in a provided set of heterozygotes passes the four-gamete test"""
cdef list possibilities = list()
cdef list locals = list()
cdef possible1 = list()
Expand Down Expand Up @@ -151,4 +158,4 @@ cdef class SNPcall(object):
#print(opt)
if sum(opt) != 4: #if ANY possibilities
return True #return False if not compatible
return(False)
return(False)

0 comments on commit aa8fe7c

Please sign in to comment.