How to use the pyensembl.locus.Locus function in pyensembl

To help you get started, we’ve selected a few pyensembl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openvax / pyensembl / test / test_locus.py View on Github external
def test_locus_distance():
    locus_chr1_10_20_pos = Locus("1", 10, 20, "+")
    locus_chr1_21_25_pos = Locus("1", 21, 25, "+")
    locus_chr2_21_25_pos = Locus("2", 21, 25, "+")
    locus_chr1_21_25_neg = Locus("1", 21, 25, "-")
    assert locus_chr1_10_20_pos.distance_to_locus(locus_chr1_21_25_pos) == 1
    assert locus_chr1_21_25_pos.distance_to_locus(locus_chr1_10_20_pos) == 1
    inf = float("inf")
    assert locus_chr1_10_20_pos.distance_to_locus(locus_chr2_21_25_pos) == inf
    assert locus_chr1_10_20_pos.distance_to_locus(locus_chr1_21_25_neg) == inf
github openvax / pyensembl / test / test_locus.py View on Github external
def test_locus_overlaps():
    locus = Locus("1", 10, 20, "+")
    assert locus.overlaps("1", 10, 20, "+")
    assert locus.overlaps("1", 10, 20)
    assert locus.overlaps("1", 5, 30)
    assert locus.overlaps("1", 15, 16)
    assert locus.overlaps("1", 15, 30)
    assert locus.overlaps("1", 5, 15)
    assert locus.overlaps("1", 10, 10)
    assert locus.overlaps("1", 20, 20)
    # before start
    assert not locus.overlaps(1, 9, 9)
    # after end
    assert not locus.overlaps(21, 30, 30)
    # wrong contig
    assert not locus.overlaps("2", 10, 20)
    # wrong strand
    assert not locus.overlaps("1", 10, 20, "-")
github openvax / pyensembl / test / test_locus.py View on Github external
def test_locus_distance():
    locus_chr1_10_20_pos = Locus("1", 10, 20, "+")
    locus_chr1_21_25_pos = Locus("1", 21, 25, "+")
    locus_chr2_21_25_pos = Locus("2", 21, 25, "+")
    locus_chr1_21_25_neg = Locus("1", 21, 25, "-")
    assert locus_chr1_10_20_pos.distance_to_locus(locus_chr1_21_25_pos) == 1
    assert locus_chr1_21_25_pos.distance_to_locus(locus_chr1_10_20_pos) == 1
    inf = float("inf")
    assert locus_chr1_10_20_pos.distance_to_locus(locus_chr2_21_25_pos) == inf
    assert locus_chr1_10_20_pos.distance_to_locus(locus_chr1_21_25_neg) == inf
github openvax / pyensembl / test / test_locus.py View on Github external
def test_range_offset():
    forward_locus = Locus("1", 10, 20, "+")
    assert forward_locus.offset_range(10, 20) == (0, 10)
    assert forward_locus.offset_range(11, 14) == (1, 4)
    assert forward_locus.offset_range(20, 20) == (10, 10)

    negative_locus = Locus("1", 10, 20, "-")
    assert negative_locus.offset_range(10, 20) == (0, 10)
    assert negative_locus.offset_range(11, 14) == (6, 9)
    assert negative_locus.offset_range(20, 20) == (0, 0)

    # start shouldn't be larger than end
    with assert_raises(ValueError):
        forward_locus.offset_range(21, 20)

    # start shouldn't be larger than end
    with assert_raises(ValueError):
        negative_locus.offset_range(21, 20)
github openvax / pyensembl / test / test_locus.py View on Github external
def test_position_offset():
    forward_locus = Locus("1", 10, 20, "+")
    assert forward_locus.offset(10) == 0
    assert forward_locus.offset(15) == 5
    assert forward_locus.offset(19) == 9
    assert forward_locus.offset(20) == 10

    negative_locus = Locus("1", 10, 20, "-")
    assert negative_locus.offset(10) == 10
    assert negative_locus.offset(15) == 5
    assert negative_locus.offset(19) == 1
    assert negative_locus.offset(20) == 0

    # don't allow negative offsets
    with assert_raises(ValueError):
        forward_locus.offset(9)

    # don't allow negative offsets
github openvax / pyensembl / pyensembl / database.py View on Github external
feature : str
            Feature names such as 'transcript', 'gene', and 'exon'

        Returns list of Locus objects
        """
        # list of values containing (contig, start, stop, strand)
        result_tuples = self.query(
            select_column_names=["seqname", "start", "end", "strand"],
            filter_column=filter_column,
            filter_value=filter_value,
            feature=feature,
            distinct=True,
            required=True)
        return [
            Locus(contig, start, end, strand)
            for (contig, start, end, strand)
            in result_tuples
        ]
github openvax / pyensembl / pyensembl / exon.py View on Github external
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function, division, absolute_import

from .locus import Locus


class Exon(Locus):
    def __init__(
            self,
            exon_id,
            contig,
            start,
            end,
            strand,
            gene_name,
            gene_id):
        Locus.__init__(self, contig, start, end, strand)
        self.exon_id = exon_id
        self.gene_name = gene_name
        self.gene_id = gene_id

    @property
    def id(self):
github openvax / pyensembl / pyensembl / locus_with_genome.py View on Github external
def __init__(self, contig, start, end, strand, biotype, genome):
        Locus.__init__(self, contig, start, end, strand)
        self.genome = genome
        self.db = self.genome.db
        self.biotype = biotype
github openvax / pyensembl / pyensembl / exon.py View on Github external
def to_dict(self):
        state_dict = Locus.to_dict(self)
        state_dict["exon_id"] = self.id
        state_dict["gene_name"] = self.gene_name
        state_dict["gene_id"] = self.gene_id
        return state_dict