Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format Python code with black and isort #87

Merged
merged 3 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Format Python code with black and isort
a100c005f0714ebca78ec7770f770d6522b3b870
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install flake8
run: pip install flake8 flake8-import-order
run: pip install flake8
- name: Lint
run: flake8 .
test:
Expand Down
11 changes: 11 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[settings]
force_alphabetical_sort_within_sections=true
# Override force_grid_wrap value from profile=black, but black is still happy
force_grid_wrap=2
known_first_party=bx,bx_extras
# Same line length as for black
line_length=120
no_lines_before=LOCALFOLDER
profile=black
reverse_relative=true
skip_gitignore=true
88 changes: 44 additions & 44 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx']
extensions = ["sphinx.ext.autodoc", "sphinx.ext.doctest", "sphinx.ext.intersphinx"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['templates']
templates_path = ["templates"]

# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The encoding of source files.
#source_encoding = 'utf-8'
# source_encoding = 'utf-8'

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'bx-python'
copyright = '2017, James Taylor'
project = "bx-python"
copyright = "2017, James Taylor"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand All @@ -53,37 +53,37 @@

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# language = None

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# today_fmt = '%B %d, %Y'

# List of documents that shouldn't be included in the build.
#unused_docs = []
# unused_docs = []

# List of directories, relative to source directory, that shouldn't be searched
# for source files.
exclude_trees = []

# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# default_role = None

# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# add_function_parentheses = True

# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# add_module_names = True

# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"


# Options for HTML output
Expand All @@ -92,40 +92,40 @@
# The style sheet to use for HTML and HTML Help pages. A file of that name
# must exist either in Sphinx' static/ path, or in one of the custom paths
# given in html_static_path.
html_style = 'base.css'
html_style = "base.css"

# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# html_title = None

# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# html_short_title = None

# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# html_logo = None

# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# html_favicon = None

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['static']
html_static_path = ["static"]

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# html_last_updated_fmt = '%b %d, %Y'

# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# html_use_smartypants = True

# Custom sidebar templates, maps document names to template names.
html_index = 'index.html'
html_sidebars = {'index': 'indexsidebar.html'}
html_index = "index.html"
html_sidebars = {"index": "indexsidebar.html"}

# Additional templates that should be rendered to pages, maps page names to
# template names.
Expand All @@ -134,61 +134,61 @@
##}

# If false, no module index is generated.
#html_use_modindex = True
# html_use_modindex = True

# If false, no index is generated.
#html_use_index = True
# html_use_index = True

# If true, the index is split into individual pages for each letter.
#html_split_index = False
# html_split_index = False

# If true, the reST sources are included in the HTML build as _sources/<name>.
#html_copy_source = True
# html_copy_source = True

# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# html_use_opensearch = ''

# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = ''
# html_file_suffix = ''

# Output file base name for HTML help builder.
htmlhelp_basename = 'bx-doc'
htmlhelp_basename = "bx-doc"


# Options for LaTeX output
# ------------------------

# The paper size ('letter' or 'a4').
#latex_paper_size = 'letter'
# latex_paper_size = 'letter'

# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
# latex_font_size = '10pt'

# 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', 'bx-python Documentation',
'James Taylor', 'manual'), ]
latex_documents = [
("index", "bx-python.tex", "bx-python Documentation", "James Taylor", "manual"),
]

# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# latex_logo = None

# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# latex_use_parts = False

# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# latex_preamble = ''

# Documents to append as an appendix to all manuals.
#latex_appendices = []
# latex_appendices = []

# If false, no module index is generated.
#latex_use_modindex = True
# latex_use_modindex = True


# Example configuration for intersphinx: refer to the Python standard library.
#intersphinx_mapping = {'http://docs.python.org/dev': None}
# intersphinx_mapping = {'http://docs.python.org/dev': None}
2 changes: 1 addition & 1 deletion lib/bx/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.8.13'
__version__ = "0.8.13"
6 changes: 4 additions & 2 deletions lib/bx/_seqmapping.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ cdef extern from "Python.h":
int PyObject_AsWriteBuffer(object, void **, Py_ssize_t *) except -1
int PyBytes_AsStringAndSize(object, char **, Py_ssize_t *) except -1

from numpy import zeros
from math import floor
import random
import sys
from math import floor

from numpy import zeros


cdef class CharToIntArrayMapping:
"""Mapping for converting strings to int arrays"""
Expand Down
5 changes: 4 additions & 1 deletion lib/bx/align/_epo.pyx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@


import logging, gzip
import gzip
import logging
from collections import namedtuple

import numpy

cimport numpy

log = logging.getLogger(__name__)
Expand Down
47 changes: 32 additions & 15 deletions lib/bx/align/axt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from bx.align import (
Alignment,
Component,
src_split
src_split,
)

# Tools for dealing with pairwise alignments in AXT format
Expand All @@ -31,7 +31,16 @@ def get(self, src, start, end):
class Indexed:
"""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):
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"
self.indexes = interval_index_file.Indexes(filename=index_filename)
Expand All @@ -44,7 +53,7 @@ def __init__(self, axt_filename, index_filename=None, keep_open=False, species1=
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.support_ids = support_ids # for extra text at end of axt header lines
if keep_open:
self.f = open(axt_filename)
else:
Expand Down Expand Up @@ -80,7 +89,7 @@ def __init__(self, file, species1=None, species2=None, species_to_lengths=None,
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.support_ids = support_ids # for extra text at end of axt header lines
self.attributes = {}

def __next__(self):
Expand Down Expand Up @@ -108,7 +117,6 @@ def __next__(self):


class Writer:

def __init__(self, file, attributes=None):
if attributes is None:
attributes = {}
Expand All @@ -120,9 +128,7 @@ def __init__(self, file, attributes=None):

def write(self, alignment):
if len(alignment.components) != 2:
raise ValueError(
"%d-component alignment is not compatible with axt" %
len(alignment.components))
raise ValueError("%d-component alignment is not compatible with axt" % len(alignment.components))
c1 = alignment.components[0]
c2 = alignment.components[1]

Expand All @@ -137,10 +143,19 @@ def write(self, alignment):
chr1, chr2 = c1.src, c2.src

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))
"%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,
)
)
self.file.write("%s\n" % c1.text)
self.file.write("%s\n" % c2.text)
self.file.write("\n")
Expand All @@ -149,6 +164,7 @@ def write(self, alignment):
def close(self):
self.file.close()


# ---- Helper methods ---------------------------------------------------------

# typical axt block:
Expand Down Expand Up @@ -183,8 +199,9 @@ def read_next_axt(file, species1, species2, species_to_lengths=None, support_ids
component.src = fields[1]
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)
# axt intervals are origin-1 and inclusive on both ends
component.start = int(fields[2]) - 1
end = int(fields[3])
component.size = end - component.start
component.strand = "+"
component.text = seq1.strip()
Expand Down Expand Up @@ -217,5 +234,5 @@ def readline(file, skip_blank=False):
line = file.readline()
if not line:
return None
if line[0] != '#' and not (skip_blank and line.isspace()):
if line[0] != "#" and not (skip_blank and line.isspace()):
return line
Loading