Skip to content

Commit

Permalink
Merge pull request #16 from Mirmu/fix07
Browse files Browse the repository at this point in the history
Fixes for julia 0.7, drop support of 0.5
  • Loading branch information
carlobaldassi committed Jul 17, 2018
2 parents 9f79146 + 977e08d commit 5557657
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ os:
- linux
- osx
julia:
- 0.5
- 0.6
- 0.7
- nightly
notifications:
email: false
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The code is written in [Julia][julia], and the functions are called
from within Julia. However, a command-line interface is also provided for
those unfamiliar with the language (see the documentation).

The package is tested against Julia `0.5` and `0.6` on Linux, OS X, and Windows.
The package is tested against Julia `0.6` and `0.7` on Linux, OS X, and Windows.

## Installation

Expand Down
5 changes: 3 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
julia 0.5
julia 0.6
FastaIO
Iterators
IterTools
Distributions
MathProgBase 0.6.0 0.8-
ExtractMacro
ArgParse
GLPKMathProgInterface 0.3.0
Compat 0.66
20 changes: 13 additions & 7 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
environment:
matrix:
- JULIAVERSION: "julialang/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIAVERSION: "julialang/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

branches:
only:
Expand All @@ -19,9 +19,15 @@ notifications:
on_build_status_changed: false

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# if there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$("http://s3.amazonaws.com/"+$env:JULIAVERSION),
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The code is written in [Julia](http://julialang.org), and the functions are call
from within Julia. However, a [command-line interface](@ref CLI) is also provided for
those unfamiliar with the language.

The current code was tested on Julia versions 0.4 and 0.5.
The current code was tested on Julia versions 0.6 and 0.7.

### Installation

Expand Down
4 changes: 3 additions & 1 deletion src/ParalogMatching.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

module ParalogMatching

using FastaIO, ExtractMacro, Iterators
using Compat
using Compat.LinearAlgebra, Compat.Random, Compat.SparseArrays
using FastaIO, ExtractMacro
using Distributions
using MathProgBase
using GLPKMathProgInterface
Expand Down
18 changes: 9 additions & 9 deletions src/matching_fasta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function start_matching(X12::HarmonizedAlignments)
@extract X12 : X1 X2
@extract X1 : spec_id1=spec_id
@extract X2 : spec_id2=spec_id
match = zeros(spec_id1)
match = fill!(similar(spec_id1), 0)

# Finds the indices of the species with one single sequence
ind1 = index_of_unique(spec_id1)
Expand All @@ -37,8 +37,8 @@ function start_matching(X12::HarmonizedAlignments)
candi = intersect(spec_id1[ind1], spec_id2[ind2])

for el in candi
a1 = findfirst(spec_id1, el)
a2 = findfirst(spec_id2, el)
a1 = findfirst(isequal(el), spec_id1)::Int
a2 = findfirst(isequal(el), spec_id2)::Int
match[a1] = a2
end
return match
Expand All @@ -58,13 +58,13 @@ function initialize_matching(X12::HarmonizedAlignments, pseudo_count::Float64)
corr = FastC(freq)

# First compute corr from single matched families
single = X1.spec_id[find(match)]
single = X1.spec_id[findall(match .≠ 0)]

# Computes the freq matrix for the given matched species "single"
unitFC!(X1, X2, match, single, freq)

# Finally compute the inverse of the corr matrix
if isempty(find(match))
if isempty(findall(match .≠ 0))
println("WARNING ! 0 sequence matched by uniqueness. No covariation strategy possible.")
invC = zeros(size(corr.Cij))
else
Expand Down Expand Up @@ -115,8 +115,8 @@ function apply_matching!(X1, X2, match, lspec, lmatch)
length(lspec) == length(lmatch) || error("data non compatible")

for (i,el) in enumerate(lspec)
ind1 = find(spec_id1 .== el)
ind2 = find(spec_id2 .== el)
ind1 = findall(spec_id1 .== el)
ind2 = findall(spec_id2 .== el)
match[ind1[lmatch[i][1]]] = ind2[lmatch[i][2]]
end
return nothing
Expand Down Expand Up @@ -184,13 +184,13 @@ function run_matching(X12::HarmonizedAlignments;
# Performs the matching for each species of the batch
res = par_corr(X1, X2, freq, invC, el, strategy, lpsolver)
println("batch of species")

for (i,spids) in enumerate(el)
println(X1.spec_name[spids]," ")
println(res[i])
end
println()

# Applies the matching to the global matching vector
apply_matching!(X1, X2, match, el, res)

Expand Down
2 changes: 1 addition & 1 deletion src/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function trim_cov_match(nameX1, nameX2, namematch, prop, nameoutput)
propo = round(Int, prop * len)
edges1 = Int[a[1][1] for a in retsor[1:propo]]
edges2 = Int[a[1][2] for a in retsor[1:propo]]
nuovomatch = zeros(X1.M)
nuovomatch = fill(0.0, X1.M)
nuovomatch[edges1] = edges2

write_fasta_match(X1, X2, nuovomatch, nameoutput)
Expand Down
24 changes: 12 additions & 12 deletions src/readdata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ then you can use a regex like this one: `header_regex=r"^(?<species>[^/]+)/([^/]
i.e. line start, anything except a slash (capture as the species name), followed by a slash, then anything
except a slash (captured but ignored), followed by a slash, then the rest of the line (captured as the ID).
"""
function read_fasta_alignment(filename::AbstractString, max_gap_fraction::Float64 = 1.0; header_regex::Union{Void,Regex} = nothing)
function read_fasta_alignment(filename::AbstractString, max_gap_fraction::Float64 = 1.0; header_regex::Union{Nothing,Regex} = nothing)
f = FastaReader(filename)

# pass 1
Expand Down Expand Up @@ -80,9 +80,9 @@ function read_fasta_alignment(filename::AbstractString, max_gap_fraction::Float6

# pass 2

Z = Array{Int8}(fseqlen, length(seqs))
header = Array{String}(length(seqs));
sequence = Array{String}(length(seqs));
Z = Array{Int8}(undef, fseqlen, length(seqs))
header = Array{String}(undef, length(seqs));
sequence = Array{String}(undef, length(seqs));
seqid = 1
for (name, seq) in f
header[seqid] = name
Expand All @@ -104,10 +104,10 @@ function read_fasta_alignment(filename::AbstractString, max_gap_fraction::Float6
return Alignment(size(Z, 1), size(Z, 2), Int(maximum(Z)), Z', sequence, header, spec_name, spec_id, uniprot_id)
end

function specname(s::String, header_regex::Union{Void,Regex}, captureinds::NTuple{2,Integer})
function specname(s::String, header_regex::Union{Nothing,Regex}, captureinds::NTuple{2,Integer})
if header_regex nothing
# user-defined format
if ismatch(header_regex, s)
if occursin(header_regex, s)
captures = match(header_regex, s).captures
length(captures) 2 ||
error("invalid header regex: should always return at least 2 captured groups if it matches; has returned: $(length(captures))")
Expand All @@ -124,14 +124,14 @@ function specname(s::String, header_regex::Union{Void,Regex}, captureinds::NTupl
regex_joined = r"^(.*?)::(.*?)/(.*)$"

# standard format
if ismatch(regex_uniprot, s)
if occursin(regex_uniprot, s)
uniprot_id, spec_name = match(regex_uniprot, s).captures

# custom internal formats
elseif ismatch(regex_oldskrr, s)
elseif occursin(regex_oldskrr, s)
spec_name = match(regex_oldskrr, s).captures[1]
uniprot_id = "000000"
elseif ismatch(regex_joined, s)
elseif occursin(regex_joined, s)
spec_name = match(regex_joined, s).captures[3]
uniprot_id = "000000"
else
Expand All @@ -141,11 +141,11 @@ function specname(s::String, header_regex::Union{Void,Regex}, captureinds::NTupl
return convert(String, uniprot_id), convert(String, spec_name)
end

function compute_spec(header::Vector{String}, header_regex::Union{Void,Regex} = nothing)
function compute_spec(header::Vector{String}, header_regex::Union{Nothing,Regex} = nothing)
M = length(header)

spec_name = Array{String}(M)
uniprot_id = Array{String}(M)
spec_name = Array{String}(undef, M)
uniprot_id = Array{String}(undef, M)

captureinds = (1,2)
if header_regex nothing
Expand Down
8 changes: 4 additions & 4 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

########################### BLOCK FOR TYPES DEFINITION AND ALLOCATION #####################

immutable Alignment
struct Alignment
N::Int
M::Int
q::Int
Expand All @@ -16,7 +16,7 @@ end

Base.:(==)(X1::Alignment, X2::Alignment) = all(fn->getfield(X1, fn) == getfield(X2, fn), fieldnames(Alignment))

immutable HarmonizedAlignments
struct HarmonizedAlignments
X1::Alignment
X2::Alignment
end
Expand All @@ -30,7 +30,7 @@ Base.:(==)(H1::HarmonizedAlignments, H2::HarmonizedAlignments) =
# M contains the number of sequences and their pseudo count
# matching contains the current matching between the two alignments used to compute FreqC
# q is the number of different amino acids
type FreqC
mutable struct FreqC
Pij::Matrix{Float64}
Pi::Vector{Float64}
specs::Vector{Int}
Expand All @@ -49,7 +49,7 @@ end
# FastC is the type of the correlation matrix
# specs is the specs presently matched and used for the computation
# M contains the number of sequences and their pseudo count
type FastC
mutable struct FastC
Cij::Matrix{Float64}
specs::Vector{Int}
M::Vector{Int}
Expand Down
Loading

0 comments on commit 5557657

Please sign in to comment.