Exemplo n.º 1
0
def test_hash(o_region):
    """ a hash function returns an integer"""
    # the same int if called twice on the same object
    h = hash(o_region)
    assert isinstance(h, int)
    assert h == hash(o_region)

    # different ints if called on objects representing the same entity
    name = "charming"
    assert hash(Region(name)) != hash(Region(name))
Exemplo n.º 2
0
def extractRGP(contig, node, ID):
    """
        Extract the region from the given starting node
    """
    new_region = Region(contig.name + "_" + str(ID))
    while node.state:
        new_region.append(node.gene)
        node.state = 0
        node.score = 0
        node = node.prev
        if node is None:  #it's the end of the contig and the end of the region.
            break
    return new_region
Exemplo n.º 3
0
def test_cstr():
    ID = 4
    o_region = Region(ID)
    assert isinstance(o_region, Region)
    for attr in "genes", "name", "score":
        assert hasattr(o_region, attr)

    assert o_region.score == 0
    assert o_region.name == ID
    assert o_region.genes == []
Exemplo n.º 4
0
def test_equality(o_region, l_genes):
    """2 regions are equals if they contains the same list of genes."""
    for gene in l_genes:
        o_region.append(gene)

    # not the same list => False
    o_other = Region("other")
    assert o_region != o_other

    # the exact same list => True
    o_other = Region("other")
    for gene in l_genes:
        o_other.append(gene)
    assert o_region == o_other

    # the same list in reverse order => True
    o_other = Region("other")
    for gene in reversed(l_genes):
        o_other.append(gene)
    assert o_region == o_other
Exemplo n.º 5
0
 def getOrAddRegion(self, regionName):
     """Returns a region with the given `regionName`. Creates it if it does not exist.
     
     :param regionName: The name of the region to return
     :type regionName: str
     :return: The region
     :rtype: :class:`ppanggolin.region.Region`
     """
     try:
         return self._regionGetter[regionName]
     except KeyError:  #then the region is not stored in this pangenome.
         newRegion = Region(regionName)
         self._regionGetter[regionName] = newRegion
         return newRegion
Exemplo n.º 6
0
def extractRGP(contig, node, ID, naming):
    """
        Extract the region from the given starting node
    """
    if naming == "contig":
        new_region = Region(contig.name + "_RGP_" + str(ID))
    elif naming == "organism":
        new_region = Region(node.gene.organism.name + "_" + contig.name + "_RGP_" + str(ID))
    while node.state:
        new_region.append(node.gene)
        node.state = 0
        node.score = 0
        node = node.prev
        if node is None:#it's the end of the contig and the end of the region.
            break
    return new_region
Exemplo n.º 7
0
def o_region():
    return Region(4)