# Path: denovoFilter/missing_indels.py
# def filter_missing_indels(candidates, *args):
#     """ filter the candidate missing indels.
#     
#     We have a set of sites that have been called in the child, but not in the
#     parents. These are the candidates for de novo mutations. Many of these sites
#     have been checked by denovogear, for which we have a different filtering
#     process. This function filters candidate sites which have not been examined
#     by denovogear. Denovogear has a reduced sensitivity for indels, so this
#     filtering only examines candidate indel sites not examined by denovogear.
#     
#     Args:
#         candidates: pandas dataframe of de novo indel sites
#     
#     Returns:
#         dataframe of candidate sites that pass the required criteria.
#     """
#     
#     counts = extract_alt_and_ref_counts(candidates)
#     depths = get_depths_and_proportions(counts)
#     
#     depths["min_parent_depth"] = depths[["mom_depth", "dad_depth"]].min(axis=1)
#     depths["max_parent_proportion"] = depths[["mom_prp", "dad_prp"]].max(axis=1)
#     
#     # apply the filtering criteria for the missing indels
#     good_depth = depths["child_alts"] > 2
#     low_parental_alt = counts["min_parent_alt"] < 2
#     good_parental_depth = depths["min_parent_depth"] > 7
#     good_parental_proportion = depths["max_parent_proportion"] < 0.1
#     good_child_proportion = depths["child_prp"] > 0.2
#     
#     return good_depth & low_parental_alt & good_parental_depth & \
#         good_parental_proportion & good_child_proportion


import unittest
from pandas import DataFrame, Series
from denovoFilter.missing_indels import filter_missing_indels
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'''




class TestMissingIndels(unittest.TestCase):
    
    def setUp(self):
        
        self.variants = DataFrame({'person_stable_id': ['a', 'b'],
            'chrom': ['1', '1'],
            'pos': [1, 1],
            'ref': ['A', 'A'],
            'alt': ['C', 'TC'],
            'symbol': ['TEST1', 'TEST1'],
            })
        
        self.variants['dp4_child'] = ['20,15,30,25', '20,15,30,25']
        self.variants['dp4_mother'] = ['20,20,0,1', '20,20,0,1']
        self.variants['dp4_father'] = ['30,30,0,1', '30,30,0,1']
    
    def test_filter_missing_indels(self):
        ''' test that filter_missing_indels() passes the default variants
        '''
        

# Path: denovoFilter/missing_indels.py
# def filter_missing_indels(candidates, *args):
#     """ filter the candidate missing indels.
#     
#     We have a set of sites that have been called in the child, but not in the
#     parents. These are the candidates for de novo mutations. Many of these sites
#     have been checked by denovogear, for which we have a different filtering
#     process. This function filters candidate sites which have not been examined
#     by denovogear. Denovogear has a reduced sensitivity for indels, so this
#     filtering only examines candidate indel sites not examined by denovogear.
#     
#     Args:
#         candidates: pandas dataframe of de novo indel sites
#     
#     Returns:
#         dataframe of candidate sites that pass the required criteria.
#     """
#     
#     counts = extract_alt_and_ref_counts(candidates)
#     depths = get_depths_and_proportions(counts)
#     
#     depths["min_parent_depth"] = depths[["mom_depth", "dad_depth"]].min(axis=1)
#     depths["max_parent_proportion"] = depths[["mom_prp", "dad_prp"]].max(axis=1)
#     
#     # apply the filtering criteria for the missing indels
#     good_depth = depths["child_alts"] > 2
#     low_parental_alt = counts["min_parent_alt"] < 2
#     good_parental_depth = depths["min_parent_depth"] > 7
#     good_parental_proportion = depths["max_parent_proportion"] < 0.1
#     good_child_proportion = depths["child_prp"] > 0.2
#     
#     return good_depth & low_parental_alt & good_parental_depth & \
#         good_parental_proportion & good_child_proportion


# Path: tests/test_missing_indels.py
import unittest
from pandas import DataFrame, Series
from denovoFilter.missing_indels import filter_missing_indels

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'''




class TestMissingIndels(unittest.TestCase):
    
    def setUp(self):
        
        self.variants = DataFrame({'person_stable_id': ['a', 'b'],
            'chrom': ['1', '1'],
            'pos': [1, 1],
            'ref': ['A', 'A'],
            'alt': ['C', 'TC'],
            'symbol': ['TEST1', 'TEST1'],
            })
        
        self.variants['dp4_child'] = ['20,15,30,25', '20,15,30,25']
        self.variants['dp4_mother'] = ['20,20,0,1', '20,20,0,1']
        self.variants['dp4_father'] = ['30,30,0,1', '30,30,0,1']
    
    def test_filter_missing_indels(self):
        ''' test that filter_missing_indels() passes the default variants
        '''
        

        status = filter_missing_indels(self.variants)