Skip to content

Commit

Permalink
Merge pull request #24 from phaverty/julia_formatter
Browse files Browse the repository at this point in the history
format files with JuliaFormatter
  • Loading branch information
phaverty authored Aug 29, 2020
2 parents f39525f + 8a678ea commit 72995d4
Show file tree
Hide file tree
Showing 19 changed files with 881 additions and 663 deletions.
2 changes: 2 additions & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
indent = 4
margin = 100
82 changes: 64 additions & 18 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ version = "0.1.0"

[[BioSequences]]
deps = ["BioGenerics", "BioSymbols", "Combinatorics", "IndexableBitVectors", "Printf", "Random", "StableRNGs", "Twiddle"]
git-tree-sha1 = "3b04c643d3308b5c4f7f33bb02a578ab1ff13278"
git-tree-sha1 = "093ccb9211bdc71924abf8e74a0790af11da35a7"
uuid = "7e6ae17a-c86d-528c-b3b9-7f778a29fe59"
version = "2.0.4"
version = "2.0.5"

[[BioSymbols]]
deps = ["Automa"]
Expand All @@ -51,6 +51,12 @@ git-tree-sha1 = "5d55b9486590fdda5905c275bb21ce1f0754020f"
uuid = "e1450e63-4bb3-523b-b2a4-4ffa8c0fd77d"
version = "1.0.0"

[[CSTParser]]
deps = ["Tokenize"]
git-tree-sha1 = "60e9121d9ea044c30a04397e59b00c5d9eb826ee"
uuid = "00ebfdb7-1f24-5e51-bd34-a7502290713f"
version = "2.5.0"

[[CategoricalArrays]]
deps = ["Compat", "DataAPI", "Future", "JSON", "Missings", "Printf", "Reexport", "Statistics", "Unicode"]
git-tree-sha1 = "23d7324164c89638c18f6d7f90d972fa9c4fa9fb"
Expand All @@ -68,11 +74,22 @@ git-tree-sha1 = "08c8b6831dc00bfea825826be0bc8336fc369860"
uuid = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
version = "1.0.2"

[[CommonMark]]
deps = ["Crayons", "JSON", "URIParser"]
git-tree-sha1 = "df663743a8812677a74c9f3505a29002e017e59b"
uuid = "a80b9123-70ca-4bc0-993e-6e3bcb318db6"
version = "0.6.2"

[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "054993b6611376ddb40203e973e954fd9d1d1902"
git-tree-sha1 = "a6a8197ae253f2c1a22b2ae17c2dfaf5812c03aa"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.12.0"
version = "3.13.0"

[[Crayons]]
git-tree-sha1 = "c437a9c2114c7ba19322712e58942b383ffbd6c0"
uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
version = "4.0.3"

[[DataAPI]]
git-tree-sha1 = "176e23402d80e7743fc26c19c681bfb11246af32"
Expand All @@ -87,9 +104,9 @@ version = "0.20.2"

[[DataStructures]]
deps = ["InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "be680f1ad03c0a03796aa3fda5a2180df7f83b46"
git-tree-sha1 = "88d48e133e6d3dd68183309877eac74393daa7eb"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.17.18"
version = "0.17.20"

[[DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
Expand All @@ -108,6 +125,18 @@ uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[DocStringExtensions]]
deps = ["LibGit2", "Markdown", "Pkg", "Test"]
git-tree-sha1 = "c5714d9bcdba66389612dc4c47ed827c64112997"
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.8.2"

[[Documenter]]
deps = ["Base64", "Dates", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"]
git-tree-sha1 = "fb1ff838470573adc15c71ba79f8d31328f035da"
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
version = "0.25.2"

[[Future]]
deps = ["Random"]
uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820"
Expand All @@ -126,9 +155,9 @@ version = "1.0.0"

[[Indexes]]
deps = ["BGZFStreams", "BioCore", "BufferedStreams", "GenomicFeatures"]
git-tree-sha1 = "68352120035ed5a9328ef918d3e867e5e6d5b36e"
git-tree-sha1 = "c124510dd96e53f9095dbb484f4a8781cbfa0dcc"
uuid = "4ffb77ac-cb80-11e8-1b35-4b78cc642f6d"
version = "0.1.0"
version = "0.1.1"

[[InteractiveUtils]]
deps = ["Markdown"]
Expand Down Expand Up @@ -157,6 +186,12 @@ git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.0"

[[JuliaFormatter]]
deps = ["CSTParser", "CommonMark", "DataStructures", "Documenter", "Pkg", "Test", "Tokenize"]
git-tree-sha1 = "f119630a3439586c1a7d65ed0837cb5ff257945e"
uuid = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
version = "0.7.2"

[[LibGit2]]
deps = ["Printf"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
Expand Down Expand Up @@ -185,15 +220,15 @@ version = "0.4.3"
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[OrderedCollections]]
git-tree-sha1 = "12ce190210d278e12644bcadf5b21cbdcf225cd3"
git-tree-sha1 = "293b70ac1780f9584c89268a6e2a560d938a7065"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.2.0"
version = "1.3.0"

[[Parsers]]
deps = ["Dates", "Test"]
git-tree-sha1 = "eb3e09940c0d7ae01b01d9291ebad7b081c844d3"
git-tree-sha1 = "8077624b3c450b15c087944363606a6ba12f925e"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "1.0.5"
version = "1.0.10"

[[Pkg]]
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
Expand Down Expand Up @@ -286,14 +321,19 @@ version = "1.0.0"

[[Tables]]
deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"]
git-tree-sha1 = "c45dcc27331febabc20d86cb3974ef095257dcf3"
git-tree-sha1 = "b7f762e9820b7fab47544c36f26f54ac59cf8abf"
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
version = "1.0.4"
version = "1.0.5"

[[Test]]
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[Tokenize]]
git-tree-sha1 = "73c00ad506d88a7e8e4f90f48a70943101728227"
uuid = "0796e94c-ce3b-5d07-9a54-7f471281c624"
version = "0.5.8"

[[TranscodingStreams]]
deps = ["Random", "Test"]
git-tree-sha1 = "7c53c35547de1c5b9d46a4797cf6d8253807108c"
Expand All @@ -305,6 +345,12 @@ git-tree-sha1 = "29509c4862bfb5da9e76eb6937125ab93986270a"
uuid = "7200193e-83a8-5a55-b20d-5d36d44a0795"
version = "1.1.2"

[[URIParser]]
deps = ["Unicode"]
git-tree-sha1 = "53a9f49546b8d2dd2e688d216421d050c9a31d0d"
uuid = "30578b45-9adc-5946-b283-645ec420af67"
version = "0.4.1"

[[UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
Expand All @@ -314,9 +360,9 @@ uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[[XAM]]
deps = ["Automa", "BGZFStreams", "BioAlignments", "BioGenerics", "BioSequences", "GenomicFeatures", "Indexes", "Printf", "TranscodingStreams"]
git-tree-sha1 = "166ad569e0b47e9eb2b575f7c014e56de1f2e948"
git-tree-sha1 = "fc98c10e8151054353ded66914f38fbac15fc899"
uuid = "d759349c-bcba-11e9-07c2-5b90f8f05f7c"
version = "0.2.4"
version = "0.2.6"

[[YAML]]
deps = ["Base64", "Dates", "Printf"]
Expand All @@ -326,6 +372,6 @@ version = "0.4.0"

[[Zlib_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "a2e0d558f6031002e380a90613b199e37a8565bf"
git-tree-sha1 = "d5bba6485811931e4b8958e2d7ca3738273ac468"
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
version = "1.2.11+10"
version = "1.2.11+15"
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "1.1.0"
[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
GenomicFeatures = "899a7d2d-5c61-547b-bef9-6698a8d05446"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
RLEVectors = "17b45ede-fd0d-54ef-b825-8cf9fc64da95"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Expand Down
72 changes: 38 additions & 34 deletions src/AbstractGenomicVector_type.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ abstract type AbstractGenomicVector{T} <: AbstractVector{T} end
genostarts(x::AbstractGenomicVector) = copy(_genostarts(x))
genoends(x::AbstractGenomicVector) = copy(_genoends(x))
strands(x::AbstractGenomicVector) = copy(_strands(x))
RLEVectors.starts(x::AbstractGenomicVector) = chrpos(_genostarts(x),chr_info(x))
RLEVectors.ends(x::AbstractGenomicVector) = chrpos(_genoends(x),chr_info(x))
RLEVectors.starts(x::AbstractGenomicVector) = chrpos(_genostarts(x), chr_info(x))
RLEVectors.ends(x::AbstractGenomicVector) = chrpos(_genoends(x), chr_info(x))
RLEVectors.widths(x::AbstractGenomicVector) = (_genoends(x) - _genostarts(x)) .+ 1
RLEVectors.eachrange(x::AbstractGenomicVector) = zip(_genostarts(x),_genoends(x))
chromosomes(x::AbstractGenomicVector) = chromosomes(_genostarts(x),chr_info(x))
RLEVectors.eachrange(x::AbstractGenomicVector) = zip(_genostarts(x), _genoends(x))
chromosomes(x::AbstractGenomicVector) = chromosomes(_genostarts(x), chr_info(x))

## FIXME: add RLEVector creation from AbstractGenomicVector and a Vector of data

Expand Down Expand Up @@ -74,23 +74,23 @@ in the linear genome.
starts, ends, widths, chromosomes, genostarts, genoends, strands, each, chrpos, genopos, chrindex

## Sorting
Base.sort(x::AbstractGenomicVector; rev::Bool=false) = sort!(copy(x))
Base.issorted(x::AbstractGenomicVector; rev::Bool=false) = issorted( eachrange(x), rev=rev )
Base.sortperm(x::AbstractGenomicVector; rev=false) = sortperm( collect(eachrange(x)), rev=rev ) # No method for iterator
Base.sort(x::AbstractGenomicVector; rev::Bool = false) = sort!(copy(x))
Base.issorted(x::AbstractGenomicVector; rev::Bool = false) = issorted(eachrange(x), rev = rev)
Base.sortperm(x::AbstractGenomicVector; rev = false) = sortperm(collect(eachrange(x)), rev = rev) # No method for iterator

## Modifying
slide(g::AbstractGenomicVector, x::Integer) = slide!( copy(g), x )
slide(g::AbstractGenomicVector, x::Integer) = slide!(copy(g), x)

## Show
function Base.show(io::IO, x::AbstractGenomicVector)
if length(x) > 8
out = convert(Vector{String},x[1:8])
out = convert(Vector{String}, x[1:8])
Base.show_vector(io, out[1:4], "[", "")
print(io, "")
Base.show_vector(io, out[5:8], "", "]")
else
out = convert(Vector{String},x)
println(io,convert(Vector{String},out))
out = convert(Vector{String}, x)
println(io, convert(Vector{String}, out))
end
end

Expand All @@ -106,45 +106,49 @@ end

## Indexing
Base.IndexStyle(::Type{<:AbstractGenomicVector}) = IndexLinear()
Base.getindex(x::AbstractGenomicVector,i::AbstractGenomicVector) = getindex(x, findall(in(x), y))
Base.getindex(x::AbstractGenomicVector, i::AbstractGenomicVector) = getindex(x, findall(in(x), y))

## Searching
_exact_overlap(el_a::Interval, el_b::Interval) = first(el_a) == first(el_b) && last(el_a) == last(el_b)
_exact_overlap(el_a::Interval, el_b::Interval) =
first(el_a) == first(el_b) && last(el_a) == last(el_b)

function findoverlaps(x::AbstractGenomicVector, y::AbstractGenomicVector, exact::Bool=false)
function findoverlaps(x::AbstractGenomicVector, y::AbstractGenomicVector, exact::Bool = false)
same_genome(x, y) || throw(ArgumentError("Both inputs must be from the same genome."))
xit = convert(IntervalCollection,x)
yit = convert(IntervalCollection,y)
xit = convert(IntervalCollection, x)
yit = convert(IntervalCollection, y)
if exact
ol = eachoverlap(xit, yit, filter=_exact_overlap)
ol = eachoverlap(xit, yit, filter = _exact_overlap)
else
ol = eachoverlap(xit,yit)
ol = eachoverlap(xit, yit)
end
ol
end

function Base.indexin(x::AbstractGenomicVector, y::AbstractGenomicVector, exact::Bool=true)
ol = findoverlaps(x,y,exact)
inds = Array{Union{Nothing, Int64}}(nothing, length(x))
for (el_a,el_b) in ol
function Base.indexin(x::AbstractGenomicVector, y::AbstractGenomicVector, exact::Bool = true)
ol = findoverlaps(x, y, exact)
inds = Array{Union{Nothing,Int64}}(nothing, length(x))
for (el_a, el_b) in ol
m_a = metadata(el_a)
m_b = metadata(el_b)
if inds[m_a] === nothing || inds[m_a] > m_b
inds[ m_a ] = m_b
inds[m_a] = m_b
end
end
inds
end

function overlap_table(x::AbstractGenomicVector, y::AbstractGenomicVector, exact::Bool=true)
ol = findoverlaps(x,y,exact)
olap_pairs = [ [metadata(el_a), metadata(el_b)]' for (el_a,el_b) in ol ]
function overlap_table(x::AbstractGenomicVector, y::AbstractGenomicVector, exact::Bool = true)
ol = findoverlaps(x, y, exact)
olap_pairs = [[metadata(el_a), metadata(el_b)]' for (el_a, el_b) in ol]
vcat(olap_pairs...)
end

Base.in(x::AbstractGenomicVector, y::AbstractGenomicVector, exact::Bool=true) = indexin(x,y,exact) .!= nothing
Base.intersect(x::AbstractGenomicVector, y::AbstractGenomicVector, exact::Bool=true) = x[ in(x,y,exact) ]
Base.setdiff(x::AbstractGenomicVector, y::AbstractGenomicVector, exact::Bool=true) = x[in(x,y,exact) .== false]
Base.in(x::AbstractGenomicVector, y::AbstractGenomicVector, exact::Bool = true) =
indexin(x, y, exact) .!= nothing
Base.intersect(x::AbstractGenomicVector, y::AbstractGenomicVector, exact::Bool = true) =
x[in(x, y, exact)]
Base.setdiff(x::AbstractGenomicVector, y::AbstractGenomicVector, exact::Bool = true) =
x[in(x, y, exact).==false]

#nearest(x::AbstractGenomicVector, query::Interval)
#
Expand Down Expand Up @@ -198,10 +202,10 @@ set of ranges in `gr`.
"""
function coverage(gr::AbstractGenomicVector)
out = RLEVector(0, last(chr_ends(gr)))
@inbounds for (s,e) in eachrange(gr)
@inbounds for (s, e) in eachrange(gr)
r = s:e
x = out[r]
for i in 1:length(x.runvalues)
for i = 1:length(x.runvalues)
@inbounds x.runvalues[i] = x.runvalues[i] + 1
end
out[r] = x
Expand Down Expand Up @@ -230,7 +234,7 @@ AbstractGenomicVector. The vector must span the full length of the genome
specified by the chr_info of the AbstractGenomicVector. This is useful for summarizing
an RLEVector of data (say DNA copy number) by genome regions (e.g. genes).
"""
function Base.getindex(v::T1, g::T2) where T2 <: AbstractGenomicVector where T1 <: RLEVector
function Base.getindex(v::T1, g::T2) where {T2<:AbstractGenomicVector} where {T1<:RLEVector}
if length(v) != chr_ends(g)[end]
error("When subsetting an Vector with a GenomicVector, the Vector must span the entire genome.")
end
Expand All @@ -240,9 +244,9 @@ end
function Base.iterate(x::GenomicVectorIterator, state = 1)
state > length(x) && return nothing
newstate = state + 1
( x.v[ x.genostarts[state]:x.genoends[state] ], newstate )
(x.v[x.genostarts[state]:x.genoends[state]], newstate)
end

function Base.length(x::GenomicVectorIterator)
size(x.genostarts,1)
size(x.genostarts, 1)
end
Loading

0 comments on commit 72995d4

Please # to comment.