from TASSELpy.net.maizegenetics.util.OpenBitSet import OpenBitSet
from TASSELpy.javaObj import javaObj
from TASSELpy.utils.helper import make_sig
from TASSELpy.utils.Overloading import javaOverload, javaConstructorOverload
from TASSELpy.utils.primativeArray import javaPrimativeArray
from TASSELpy.java.lang.Object import Object
from TASSELpy.java.lang.String import String
from TASSELpy.java.lang.Long import Long
from TASSELpy.java.lang.Boolean import metaBoolean
from TASSELpy.java.lang.Byte import metaByte
from TASSELpy.java.lang.Integer import metaInteger
import javabridge
import numpy as np



## Dictionary to hold java imports
java_imports = {'genotypecall':'net/maizegenetics/dna/snp/genotypecall', 
        'GenotypeCallTable':'net/maizegenetics/dna/snp/genotypecall/GenotypeCallTable',
        'String':'java/lang/String',
        'Object':'java/lang/Object',
        'Boolean':'java/lang/Boolean'}

class GenotypeCallTable(Object):
    """ Interface for genotype calls for a table of taxa and sites.
    GenotypeCallTable only contain information on the genotype calls. The call
    table does not have the TaxaList or PositionList. The calls are diploid genotype
    calls stored and retrieved as bytes. Conversions to string are also provided.

    Generally these methods are accessed through the GenotypeTable interface
    """
    _java_name = java_imports['GenotypeCallTable']
    @javaConstructorOverload(java_imports['GenotypeCallTable'])
    def __init__(self, *args, **kwargs):
        pass
    @javaOverload("genotype", (make_sig(['int', 'int'], 'byte'), (metaInteger, metaInteger), None))
    def genotype(self, *args):
        """ Returns diploid value (genotype) for a given taxon and site

        Signatures:

        byte genotype(int taxon, int site)

        Arguments:

        taxon -- taxon
        site -- site

        Returns:

        High 4 bites generally encode the more frequent allele, and the lower
        4 bits encode the less frequent allele
        """
        pass
    @javaOverload("genotypeArray", (make_sig(['int', 'int'], 'byte[]'), (metaInteger, metaInteger), None))
    def genotypeArray(self, *args):
        """ Returns the diploid values for given taxon and site

        Same values as genotype(), except two values are already separated into two bytes

        Signatures:

        byte[] genotypeArray(int taxon, int site)

        Returns:

        First byte (index 0) hold sfirst allele value in right-most 4 bits. Second byte (index 1)
        holds second value in right-most 4 bits
        """
        pass
    @javaOverload("genotypeRange",(make_sig(['int','int','int'],'byte[]'),(metaInteger, metaInteger, metaInteger),None))
    def genotypeRange(self, *args):
        """ Returns sequence of diploid allele values for given taxon in specified range (end site excluded).
        Each value in array is what would be returned by genotype().

        Signatures:

        byte[] genotypeRange(int taxon, int startSite, int endSite)

        Arguments:

        taxon -- taxon
        startSite -- start site
        endSite -- end site

        Returns:

        sequence of diploid allele values     
        """
        pass
    @javaOverload("genotypeAllSites",(make_sig(['int'],'byte[]'),(metaInteger,),None))
    def genotypeAllSites(self, *args):
        """ Returns sequence of diploid allele values for all sites for given taxon

        Each value in array is what would be returned by genotype()

        Signatures:

        byte[] genotypeAllSites(int taxon)

        Arguments:

        taxon -- taxon

        Returns:

        Sequence of diploid allele values
        """
        pass
    @javaOverload("genotypeAsString",(make_sig(['int','int'],java_imports['String']),(metaInteger,metaInteger),None),
                  (make_sig(['int','byte'],java_imports['String']),(metaInteger,metaByte),None))
    def genotypeAsString(self, *args):
        """ Returns string representation of diploid allele values returned
        by genotype() for given taxon and site. The two allele values will be
        separated by a colon(:) delimiter

        Signatures:

        String genotypeAsString(int taxon, int site)
        String genotypeAsString(int site, byte value)

        Arguments:

        String genotypeAsString(int taxon, int site)
            taxon -- taxon
            site -- site
        String genotypeAsString(int site, byte value)
            site -- site
            value -- diploid allele value

        Returns:

        String representation
        """
        pass
    @javaOverload("genotypeAsStringRange",(make_sig(['int','int','int'],java_imports['String']),    
            (metaInteger,metaInteger,metaInteger),None))
    def genotypeAsStringRange(self, *args):
        """ Returns string representation of diploid alleles for given taxon in
        specified range (end site excluded). Each vlaue in string is what would
        be returned by genotypeAsString

        Signatures:

        String genotypeAsStringRange(int taxon, int startSite, int endSite)

        Arguments:

        taxon -- taxon
        startSite -- start site
        endSite -- end site

        Returns:

        String representation of alleles in range
        """
        pass
    @javaOverload("genotypeAsStringRow",(make_sig(['int'],java_imports['String']),(metaInteger,),None))
    def genotypeAsStringRow(self, *args):
        """ Returns string representation of diploid alleles for given taxon for all sites.

        Each value in string is what would be returned by genotypeAsString()

        Signatures:

        String genotypeAsStringRow(int taxon)
        
        Arguments:

        taxon -- taxon

        Returns:

        String representation of alleles
        """
        pass
    @javaOverload("genotypeAsStringArray",(make_sig(['int','int'],java_imports['String']+'[]'),
            (metaInteger,metaInteger),lambda x: map(lambda y: javabridge.get_env().get_string(y),
                                 javabridge.get_env().get_object_array_elements(x))))
    def genotypeAsStringArray(self, *args):
        """ Returns string representation of diploid values returned by genotypeArray() for
        given taxon and site. Same 2 allele values as genotypeAsString(), except already separated
        into 2 Strings

        Signatures:

        String[] genotypeAsStringArray(int taxon, int site)

        Arguments:

        taxon -- taxon
        site -- site

        Returns:

        String representation of diploid vlaues
        """
        pass
    @javaOverload("isHeterozygous", (make_sig(['int', 'int'], 'boolean'),(metaInteger, metaInteger),    
            None))
    def isHeterozygous(self, *args):
        """ Returns whether allele values at given taxon and site are heterozygous.
        If 2 values returned by genotype() are different, this will return false

        Signatures:

        boolean isHeterozygous(int taxon, int site)

        Arguments:

        taxon -- taxon
        site -- site

        Returns:

        Whether heterozygous
        """
        pass
    @javaOverload("heterozygousCount",
                  (make_sig(['int'],'int'),(metaInteger,),None))
    def heterozygousCount(self, *args):
        """ Returns the number of heterozygous taxa at given site

        Signatures:

        int heterozygousCount(int site)

        Arguments:

        site -- site

        Returns:

        Number of heterozygous taxa
        """
        pass
    @javaOverload("isAllPolymorphic",
                  (make_sig([],'boolean'),(),None))
    def isAllPolymorphic(self, *args):
        """ Returns whether all sites are polymorphic

        Signatures:

        boolean isAllPolymorphic()

        Returns:

        true if all sites are polymorphic
        """
        pass
    @javaOverload("isPolymorphic", (make_sig(['int'], 'boolean'),(metaInteger,),None))
    def isPolymorphic(self, *args):
        """ Returns whether a given site is polymorphic

        Signatures:

        boolean isPolymorphic(int site)

        Arguments:

        site -- site

        Returns:

        true if given site is polymorphic
        """
        pass
    @javaOverload("isPhased", (make_sig([],'boolean'),(),None))
    def isPhased(self, *args):
        """ Returns whether this alignment is phased

        Signatures:

        boolean isPhased()

        Returns:

        true if phased
        """
        pass
    @javaOverload("retainsRareAlleles", (make_sig([],'boolean'),(),None))
    def retainsRareAlleles(self, *args):
        """ Returns true if this Alignment retains rare alleles. If false,
        rare alleles are recorded as unknown