Skip to content

Commit 5a3354e

Browse files
authored
Merge pull request #53 from jakobnissen/master
Allow compact printing of alignments
2 parents 492cd58 + 2c6f47f commit 5a3354e

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ authors = ["Kenta Sato <[email protected]>", "Ben J. Ward <benjward@protonma
44
version = "2.0.0"
55

66
[deps]
7-
BioGenerics = "47718e42-2ac5-11e9-14af-e5595289c2ea" # Note: required for distance function.
7+
BioGenerics = "47718e42-2ac5-11e9-14af-e5595289c2ea"
88
BioSequences = "7e6ae17a-c86d-528c-b3b9-7f778a29fe59"
99
BioSymbols = "3c28c6f8-a34d-59c4-9654-267d177fcfa9"
1010
IntervalTrees = "524e6230-43b7-53ae-be76-1e9e4d08d11b"
1111
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1212

1313
[compat]
14-
julia = "1"
1514
BioGenerics = "0.1"
1615
BioSequences = "2"
1716
BioSymbols = "4"
1817
IntervalTrees = "1"
18+
julia = "1"
1919

2020
[extras]
2121
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/pairwise/alignment.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,22 @@ aln2ref(aln::PairwiseAlignment, i::Integer) = aln2ref(aln.a, i)
132132
# Printers
133133
# --------
134134

135-
function Base.show(io::IO, aln::PairwiseAlignment)
136-
println(io, summary(aln), ':')
137-
print(io, aln)
135+
function showshort(io::IO, aln::PairwiseAlignment)
136+
print(io, summary(aln), "(lengths=(",
137+
length(aln.a.seq), ", ", length(aln.b),
138+
")/", length(aln), ')'
139+
)
140+
end
141+
142+
Base.show(io::IO, aln::PairwiseAlignment) = showshort(io, aln)
143+
144+
function Base.show(io::IO, ::MIME"text/plain", aln::PairwiseAlignment)
145+
if get(io, :compact, false)
146+
showshort(io, aln)
147+
else
148+
println(io, summary(aln), ':')
149+
print(io, aln)
150+
end
138151
end
139152

140153
function Base.print(io::IO, aln::PairwiseAlignment)

src/pairwise/result.jl

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,24 @@ end
6868
# Printer
6969
# -------
7070

71+
7172
function Base.show(io::IO, aln::PairwiseAlignmentResult{T,S1,S2}) where {T,S1,S2}
72-
println(io, summary(aln), ':')
73-
if aln.isscore
74-
print(io, " score: ", aln.value)
73+
print(io, summary(aln), '(', aln.isscore ? "score" : "distance", '=', aln.value, ')')
74+
end
75+
76+
function Base.show(io::IO, ::MIME"text/plain", aln::PairwiseAlignmentResult{T,S1,S2}) where {T,S1,S2}
77+
if get(io, :compact, false)
78+
show(io, aln)
7579
else
76-
print(io, " distance: ", aln.value)
77-
end
78-
if hasalignment(aln)
79-
println(io)
80-
print(io, alignment(aln))
80+
println(io, summary(aln), ':')
81+
if aln.isscore
82+
print(io, " score: ", aln.value)
83+
else
84+
print(io, " distance: ", aln.value)
85+
end
86+
if hasalignment(aln)
87+
println(io)
88+
print(io, alignment(aln))
89+
end
8190
end
8291
end

test/runtests.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,9 @@ end
10141014
seqtype = VERSION >= v"1.6" ?
10151015
"BioSequences.LongAminoAcidSeq" :
10161016
"BioSequences.LongSequence{BioSequences.AminoAcidAlphabet}"
1017-
@test sprint(show, aln) ==
1017+
buf = IOBuffer()
1018+
show(buf, MIME"text/plain"(), aln)
1019+
@test String(take!(buf)) ==
10181020
"""
10191021
PairwiseAlignment{$(seqtype),$(VERSION >= v"1.6" ? " " : "")$(seqtype)}:
10201022
seq: 1 EPVTSHPKAVSPTETK--PTEKGQHLPVSAPPKITQSLKAEASKDIAKLTCAVESSALCA 58
@@ -1039,6 +1041,12 @@ end
10391041
| |||| | |
10401042
ref: 49 CVVESSVLRA 58
10411043
"""
1044+
buf = IOBuffer()
1045+
print(buf, (aln,))
1046+
@test String(take!(buf)) == (
1047+
"""(PairwiseAlignment{$seqtype,$(VERSION >= v"1.6" ? " " : "")$(seqtype)}""" *
1048+
"""(lengths=(58, 58)/60),)"""
1049+
)
10421050
# Result from EMBOSS Needle:
10431051
# EMBOSS_001 1 EPVTSHPKAVSPTETK--PTEKGQHLPVSAPPKITQSLKAEASKDIAKLT 48
10441052
# || |||||||||||| ||||.|||||||||||||.|||||||:|||||

0 commit comments

Comments
 (0)