# Path: denovoFilter/allele_counts.py
# def extract_alt_and_ref_counts(de_novos):
#     """extract ALT and REF counts of forward and reverse reads for trio members
#     
#     Args:
#         de_novos: dataframe of de novo variants
#     
#     Returns:
#         data frame of de novos, but with an extra columns for the read depths
#         of forward and reverse reads for each member of the trio.
#     """
#     
#     members = ["child", "father", "mother"]
#     
#     counts = de_novos[['person_stable_id', 'chrom', 'pos', 'ref', 'alt', 'symbol']].copy()
#     
#     for member in members:
#         dp4 = de_novos["dp4_{0}".format(member)].str.split(",")
#         
#         # split the forward and reverse counts by ref and alt for each member
#         counts["{0}_ref_F".format(member)] = [ int(x[0]) for x in dp4 ]
#         counts["{0}_ref_R".format(member)] = [ int(x[1]) for x in dp4 ]
#         counts["{0}_alt_F".format(member)] = [ int(x[2]) for x in dp4 ]
#         counts["{0}_alt_R".format(member)] = [ int(x[3]) for x in dp4 ]
#     
#     # get the minimum alternate allele count from the parents
#     alts = pandas.DataFrame({"a": counts[["mother_alt_F", "mother_alt_R"]].sum(axis=1),
#         "b": counts[["father_alt_F", "father_alt_R"]].sum(axis=1)})
#     counts["min_parent_alt"] = alts.min(axis=1)
#     
#     return counts
# 
# def get_depths_and_proportions(counts):
#     """ get the read depths, alt depths and alt proportions for the trio members
#     
#     Args:
#         counts: pandas dataframe containing colums of child_ref_F, child alt_R
#             etc
#     
#     Returns:
#         dataframe including additional alt depth, total depth, and alt
#         proportion columns for each trio member.
#     """
#     
#     # get the trio depths
#     child_depth = counts[["child_ref_F", "child_ref_R", "child_alt_F", "child_alt_R"]].sum(axis=1)
#     dad_depth = counts[["father_ref_F", "father_ref_R", "father_alt_F", "father_alt_R"]].sum(axis=1)
#     mom_depth = counts[["mother_ref_F", "mother_ref_R", "mother_alt_F", "mother_alt_R"]].sum(axis=1)
#     
#     # get the depth of the alternate alleles
#     child_alts = counts[["child_alt_F", "child_alt_R"]].sum(axis=1)
#     dad_alts = counts[["father_alt_F", "father_alt_R"]].sum(axis=1)
#     mom_alts = counts[["mother_alt_F", "mother_alt_R"]].sum(axis=1)
#     
#     values = pandas.DataFrame({
#         'child_depth': child_depth, 'dad_depth': dad_depth, 'mom_depth': mom_depth,
#         'child_alts': child_alts, 'dad_alts': dad_alts, 'mom_alts': mom_alts,
#         'child_prp': child_alts/child_depth, 'dad_prp': dad_alts/dad_depth,
#         'mom_prp': mom_alts/mom_depth}, index=counts.index)
#     
#     return values


from denovoFilter.allele_counts import extract_alt_and_ref_counts, \
    get_depths_and_proportions

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
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.
"""


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.
    """
    

# Path: denovoFilter/allele_counts.py
# def extract_alt_and_ref_counts(de_novos):
#     """extract ALT and REF counts of forward and reverse reads for trio members
#     
#     Args:
#         de_novos: dataframe of de novo variants
#     
#     Returns:
#         data frame of de novos, but with an extra columns for the read depths
#         of forward and reverse reads for each member of the trio.
#     """
#     
#     members = ["child", "father", "mother"]
#     
#     counts = de_novos[['person_stable_id', 'chrom', 'pos', 'ref', 'alt', 'symbol']].copy()
#     
#     for member in members:
#         dp4 = de_novos["dp4_{0}".format(member)].str.split(",")
#         
#         # split the forward and reverse counts by ref and alt for each member
#         counts["{0}_ref_F".format(member)] = [ int(x[0]) for x in dp4 ]
#         counts["{0}_ref_R".format(member)] = [ int(x[1]) for x in dp4 ]
#         counts["{0}_alt_F".format(member)] = [ int(x[2]) for x in dp4 ]
#         counts["{0}_alt_R".format(member)] = [ int(x[3]) for x in dp4 ]
#     
#     # get the minimum alternate allele count from the parents
#     alts = pandas.DataFrame({"a": counts[["mother_alt_F", "mother_alt_R"]].sum(axis=1),
#         "b": counts[["father_alt_F", "father_alt_R"]].sum(axis=1)})
#     counts["min_parent_alt"] = alts.min(axis=1)
#     
#     return counts
# 
# def get_depths_and_proportions(counts):
#     """ get the read depths, alt depths and alt proportions for the trio members
#     
#     Args:
#         counts: pandas dataframe containing colums of child_ref_F, child alt_R
#             etc
#     
#     Returns:
#         dataframe including additional alt depth, total depth, and alt
#         proportion columns for each trio member.
#     """
#     
#     # get the trio depths
#     child_depth = counts[["child_ref_F", "child_ref_R", "child_alt_F", "child_alt_R"]].sum(axis=1)
#     dad_depth = counts[["father_ref_F", "father_ref_R", "father_alt_F", "father_alt_R"]].sum(axis=1)
#     mom_depth = counts[["mother_ref_F", "mother_ref_R", "mother_alt_F", "mother_alt_R"]].sum(axis=1)
#     
#     # get the depth of the alternate alleles
#     child_alts = counts[["child_alt_F", "child_alt_R"]].sum(axis=1)
#     dad_alts = counts[["father_alt_F", "father_alt_R"]].sum(axis=1)
#     mom_alts = counts[["mother_alt_F", "mother_alt_R"]].sum(axis=1)
#     
#     values = pandas.DataFrame({
#         'child_depth': child_depth, 'dad_depth': dad_depth, 'mom_depth': mom_depth,
#         'child_alts': child_alts, 'dad_alts': dad_alts, 'mom_alts': mom_alts,
#         'child_prp': child_alts/child_depth, 'dad_prp': dad_alts/dad_depth,
#         'mom_prp': mom_alts/mom_depth}, index=counts.index)
#     
#     return values


# Path: denovoFilter/missing_indels.py
from denovoFilter.allele_counts import extract_alt_and_ref_counts, \
    get_depths_and_proportions


The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
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.
"""


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)