Commit 404a772c authored by Andreas Tille's avatar Andreas Tille
Browse files

New upstream version 0.8.6

parent f4801501
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -6,6 +6,12 @@ python:
  - '2.7'
  - '3.5'

stages:
  - lint
  - test
  - name: deploy
    if: tag IS present

env:
  global:
    - PYTHON=python
@@ -13,12 +19,19 @@ env:
    - secure: 'kFoqHCxat/ETS2SUc2q9M7YvzvnlR7sgHmx7SRvVgTyLkk1efpJ++YPwDBEYZ3v+GLf2nRfc20GxtZkH6ey1f//aj4CT2q2CJiUsKAlkFAOHzKo/3mTLl/WDHkPAr9MW7AdnbNk6W8sIPCKqFsyKL2FTH70dBcxa1e7trQ2RC64hnOOkt/tm2cQhj6sX0gROggN5QrpHE8tDZb9ugF0uf92L/CGxeClAebWgb7zVChHDMTNsmnOvWUF9m6LZOvkgFmuIeh70EPuOWh6LxU/n5JyevYIGO5vVDbjgfmNELlG2KUTm6dWeoyofcj6hUqYmQsmI1ATrf7ThY1+b6asQGy+Exp/76MBXiYRh+RgVKifwaZMOWehzfjDQvPYOGvf6rXOVGeVZ+nBkskr0HARsX1KnyDE+k+XPoP7zqvW6mCic9ZQ+IdQJtxMHOTxxFjuPAlunvaUqDNM9VP6YEWOI4UqIOO1nQh4E2zkPhXI2yY744q+BV/5+3HHqNQj1+5qFPoZeyDEuNXwgDCjrJ8i3hna/LTTvRigx6/YQL1PF/C30R4h/nkqp8ghA4VpNRPnQ8nOO+oD6AdN7Pswc3C4qGPEwoeqfNzEIR1KfEWzB7HsfTFbgyGFFNGuQ/P26DMK+kPBNZ6GhZ9wb5/xT226OA+ovcAmVGn/Hnt/qVaylXNk='

_deploy_common: &deploy_common
  if: tag IS present
  install:
    - $PYTHON -m pip install cibuildwheel twine

matrix:
  include:
    - stage: lint
      python: '3.5'
      addons: {}
      install:
        - $PYTHON -m pip install flake8 flake8-import-order
      script:
        - flake8 .

    - stage: deploy
      python: '3.5'
      services:
@@ -32,6 +45,7 @@ matrix:
        - $PYTHON setup.py sdist
        - twine check dist/*
        - twine upload --skip-existing dist/*

    - stage: deploy
      os: osx
      language: generic
+4 −11
Original line number Diff line number Diff line
@@ -14,15 +14,9 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os

# If your extensions are in another directory, add it here. If the directory
# is relative to the documentation root, use os.path.abspath to make it
# absolute, like shown here.
#sys.path.append(os.path.abspath('.'))
## curr_dir = os.path.dirname( __file__ )
## bx_dir = os.path.join( curr_dir, '..', '..', 'lib')
## sys.path.insert( 0, bx_dir )
import bx

# General configuration
@@ -175,10 +169,9 @@ htmlhelp_basename = 'bx-doc'

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, document class [howto/manual]).
latex_documents = [
  ('index', 'bx-python.tex', ur'bx-python Documentation',
   ur'James Taylor', 'manual'),
]
latex_documents = [(
    'index', 'bx-python.tex', u'bx-python Documentation',
    u'James Taylor', 'manual'), ]

# The name of an image file (relative to this directory) to place at the top of
# the title page.
+24 −17
Original line number Diff line number Diff line
@@ -6,18 +6,16 @@ Setuptools bootstrapping installer.
Run this script to install or upgrade setuptools.
"""

import contextlib
import optparse
import os
import platform
import shutil
import subprocess
import sys
import tempfile
import zipfile
import optparse
import subprocess
import platform
import textwrap
import contextlib
import warnings

import zipfile
from distutils import log

try:
@@ -244,6 +242,8 @@ def has_powershell():
        except Exception:
            return False
    return True


download_file_powershell.viable = has_powershell


@@ -260,6 +260,8 @@ def has_curl():
        except Exception:
            return False
    return True


download_file_curl.viable = has_curl


@@ -276,6 +278,8 @@ def has_wget():
        except Exception:
            return False
    return True


download_file_wget.viable = has_wget


@@ -291,6 +295,8 @@ def download_file_insecure(url, target):
    # Write all the data in one block to avoid creating a partial file.
    with open(target, "wb") as dst:
        dst.write(data)


download_file_insecure.viable = lambda: True


@@ -387,5 +393,6 @@ def main():
    archive = download_setuptools(**_download_args(options))
    return _install(archive, _build_install_args(options))


if __name__ == '__main__':
    sys.exit(main())
+1 −1
Original line number Diff line number Diff line
@@ -4,4 +4,4 @@ the abstract alignment classes and `maf`, `axt`, and `lav` for readers and
writers in various formats.
"""

from bx.align.core import *
from bx.align.core import *  # noqa
+113 −86
Original line number Diff line number Diff line
@@ -4,22 +4,29 @@ alignments.

.. _AXT: http://genome.ucsc.edu/goldenPath/help/axt.html
"""
import itertools

from six import Iterator

from bx import interval_index_file
from bx.align import *
from bx.align import (
    Alignment,
    Component,
    src_split
)

# Tools for dealing with pairwise alignments in AXT format


class MultiIndexed(object):
    """Similar to 'indexed' but wraps more than one axt_file"""

    def __init__(self, axt_filenames, keep_open=False):
        self.indexes = [Indexed(axt_file, axt_file + ".index") for axt_file in axt_filenames]

    def get(self, src, start, end):
        blocks = []
        for index in self.indexes: blocks += index.get( src, start, end )
        for index in self.indexes:
            blocks += index.get(src, start, end)
        return blocks


@@ -27,14 +34,17 @@ class Indexed( object ):
    """Indexed access to a axt using overlap queries, requires an index file"""

    def __init__(self, axt_filename, index_filename=None, keep_open=False, species1=None, species2=None, species_to_lengths=None, support_ids=False):
        if index_filename is None: index_filename = axt_filename + ".index"
        if index_filename is None:
            index_filename = axt_filename + ".index"
        self.indexes = interval_index_file.Indexes(filename=index_filename)
        self.axt_filename = axt_filename
        # nota bene: (self.species1 = species1 or "species1") is incorrect if species1=""
        self.species1 = species1
        if (self.species1 == None): self.species1 = "species1"
        if self.species1 is None:
            self.species1 = "species1"
        self.species2 = species2
        if (self.species2 == None): self.species2 = "species2"
        if self.species2 is None:
            self.species2 = "species2"
        self.species_to_lengths = species_to_lengths
        self.support_ids = support_ids            # for extra text at end of axt header lines
        if keep_open:
@@ -58,6 +68,7 @@ class Indexed( object ):
            finally:
                f.close()


class Reader(Iterator):
    """Iterate over all axt blocks in a file in order"""

@@ -65,9 +76,11 @@ class Reader( Iterator ):
        self.file = file
        # nota bene: (self.species1 = species1 or "species1") is incorrect if species1=""
        self.species1 = species1
        if (self.species1 == None): self.species1 = "species1"
        if self.species1 is None:
            self.species1 = "species1"
        self.species2 = species2
        if (self.species2 == None): self.species2 = "species2"
        if self.species2 is None:
            self.species2 = "species2"
        self.species_to_lengths = species_to_lengths
        self.support_ids = support_ids            # for extra text at end of axt header lines
        self.attributes = {}
@@ -81,28 +94,34 @@ class Reader( Iterator ):
    def close(self):
        self.file.close()


class ReaderIter(Iterator):
    def __init__(self, reader):
        self.reader = reader

    def __iter__(self):
        return self

    def __next__(self):
        v = next(self.reader)
        if not v: raise StopIteration
        if not v:
            raise StopIteration
        return v


class Writer(object):

    def __init__(self, file, attributes={}):
        self.file = file
        self.block = 0
        self.src_split = True
        if ("src_split" in attributes):
        if "src_split" in attributes:
            self.src_split = attributes["src_split"]

    def write(self, alignment):
        if (len(alignment.components) != 2):
            raise ValueError("%d-component alignment is not compatible with axt" % \
        if len(alignment.components) != 2:
            raise ValueError(
                "%d-component alignment is not compatible with axt" %
                len(alignment.components))
        c1 = alignment.components[0]
        c2 = alignment.components[1]
@@ -111,13 +130,14 @@ class Writer( object ):
            c1 = c1.reverse_complement()
            c2 = c2.reverse_complement()

        if (self.src_split):
        if self.src_split:
            spec1, chr1 = src_split(c1.src)
            spec2, chr2 = src_split(c2.src)
        else:
            chr1, chr2 = c1.src, c2.src

        self.file.write( "%d %s %d %d %s %d %d %s %s\n" % \
        self.file.write(
            "%d %s %d %d %s %d %d %s %s\n" %
            (self.block, chr1, c1.start+1, c1.start+c1.size,
             chr2, c2.start+1, c2.start+c2.size, c2.strand,
             alignment.score))
@@ -139,25 +159,30 @@ class Writer( object ):
# first species is always on plus strand
# when second species is on minus strand, start and stop are counted from sequence end


def read_next_axt(file, species1, species2, species_to_lengths=None, support_ids=False):
    line = readline(file, skip_blank=True)
    if not line: return
    if not line:
        return
    fields = line.split()
    if (len(fields) < 9) or ((not support_ids) and (len(fields) > 9)):
    if len(fields) < 9 or (not support_ids and len(fields) > 9):
        raise ValueError("bad axt-block header: %s" % line)
    attributes = {}
    if (len(fields) > 9):
    if len(fields) > 9:
        attributes["id"] = "_".join(fields[9:])
    seq1 = readline(file)
    if not line or line.isspace(): raise ValueError("incomplete axt-block; header: %s" % line)
    if not line or line.isspace():
        raise ValueError("incomplete axt-block; header: %s" % line)
    seq2 = readline(file)
    if not line or line.isspace(): raise ValueError("incomplete axt-block; header: %s" % line)
    if not line or line.isspace():
        raise ValueError("incomplete axt-block; header: %s" % line)
    # Build 2 component alignment
    alignment = Alignment(attributes=attributes, species_to_lengths=species_to_lengths)
    # Build component for species 1
    component = Component()
    component.src = fields[1]
    if (species1 != ""): component.src = species1 + "." + component.src
    if species1 != "":
        component.src = species1 + "." + component.src
    component.start = int(fields[2]) - 1  # (axt intervals are origin-1
    end = int(fields[3])                  # and inclusive on both ends)
    component.size = end - component.start
@@ -167,7 +192,8 @@ def read_next_axt( file, species1, species2, species_to_lengths=None, support_id
    # Build component for species 2
    component = Component()
    component.src = fields[4]
    if (species2 != ""): component.src = species2 + "." + component.src
    if species2 != "":
        component.src = species2 + "." + component.src
    component.start = int(fields[5]) - 1
    end = int(fields[6])
    component.size = end - component.start
@@ -177,18 +203,19 @@ def read_next_axt( file, species1, species2, species_to_lengths=None, support_id
    # add score
    try:
        alignment.score = int(fields[8])
    except:
    except ValueError:
        try:
            alignment.score = float(fields[8])
        except:
        except ValueError:
            alignment.score = fields[8]
    return alignment


def readline(file, skip_blank=False):
    """Read a line from provided file, skipping any blank or comment lines"""
    while 1:
    while True:
        line = file.readline()
        if not line: return None
        if not line:
            return None
        if line[0] != '#' and not (skip_blank and line.isspace()):
            return line
Loading