| 1 | // interfaces for genomic relations |
| 2 | // irelate operates on "Relatable"s which keep a slice of related intervals. |
| 3 | package interfacesscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/ |
| 4 | |
| 5 | import "stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/" |
| 6 | |
| 7 | // RelatableChannel |
| 8 | type RelatableChannelscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelatableChannel# chan Relatablescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Relatable# |
| 9 | |
| 10 | // RelatableIterator provides a method to iterate over Relatables |
| 11 | type RelatableIteratorscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelatableIterator# interface { |
| 12 | Nextscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelatableIterator#Next.() (Relatablescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Relatable#, error) |
| 13 | Closescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelatableIterator#Close.() error |
| 14 | } |
| 15 | |
| 16 | // Queryable allows querying by genomic position. Anything that meets this interface |
| 17 | // can be used in irelate. |
| 18 | type Queryablescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Queryable# interface { |
| 19 | Queryscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Queryable#Query.(region IPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#) (RelatableIteratorscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelatableIterator#, error) |
| 20 | } |
| 21 | |
| 22 | // IPosition allows accessing positional interface for genomic types. |
| 23 | type IPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition# interface { |
| 24 | Chromscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#Chrom.() string |
| 25 | Startscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#Start.() uint32 |
| 26 | Endscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#End.() uint32 |
| 27 | } |
| 28 | |
| 29 | // Interface to get the CIPos and CIEND from a VCF. Returns start, end, ok. |
| 30 | type CIFacescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/CIFace# interface { |
| 31 | CIPosscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/CIFace#CIPos.() (uint32, uint32, bool) |
| 32 | CIEndscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/CIFace#CIEnd.() (uint32, uint32, bool) |
| 33 | } |
| 34 | |
| 35 | // Relatable provides all the methods for irelate to function. |
| 36 | // See Interval in parsers/interval.go for a class that satisfies this interface. |
| 37 | // Related() likely returns and AddRelated() likely appends to a slice of |
| 38 | // relatables. Note that for performance reasons, Relatable should be implemented |
| 39 | // as a pointer to your data-structure (see Interval). |
| 40 | type Relatablescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Relatable# interface { |
| 41 | IPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition# |
| 42 | Relatedscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Relatable#Related.() []Relatablescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Relatable# // A slice of related Relatable's filled by IRelate |
| 43 | AddRelatedscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Relatable#AddRelated.(Relatablescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Relatable#) // Adds to the slice of relatables |
| 44 | Sourcescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Relatable#Source.() uint32 |
| 45 | SetSourcescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Relatable#SetSource.(source uint32) |
| 46 | } |
| 47 | |
| 48 | // Info must implement stuff to get info out of a variant info field. |
| 49 | type Infoscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Info# interface { |
| 50 | Getscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Info#Get.(key string) (interface{}, error) |
| 51 | Setscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Info#Set.(key string, val interface{}) error |
| 52 | Deletescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Info#Delete.(key string) |
| 53 | Keysscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Info#Keys.() []string |
| 54 | Stringscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Info#String.() string |
| 55 | Bytesscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Info#Bytes.() []byte |
| 56 | } |
| 57 | |
| 58 | // IRefAlt will force matching on the Ref and Alt fields when they are present. |
| 59 | type IRefAltscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IRefAlt# interface { |
| 60 | IPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition# |
| 61 | Refscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IRefAlt#Ref.() string |
| 62 | Altscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IRefAlt#Alt.() []string |
| 63 | } |
| 64 | |
| 65 | // IVariant must implement IPosition, Ref, Alt, and Info() methods for genetic variants |
| 66 | type IVariantscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IVariant# interface { |
| 67 | IRefAltscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IRefAlt# |
| 68 | CIFacescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/CIFace# |
| 69 | Infoscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IVariant#Info.() Infoscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Info# |
| 70 | Idscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IVariant#Id.() string |
| 71 | Stringscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IVariant#String.() string |
| 72 | } |
| 73 | |
| 74 | type SIPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/SIPosition# interface { |
| 75 | IPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition# |
| 76 | Stringscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/SIPosition#String.() string |
| 77 | } |
| 78 | |
| 79 | // trun an IPosition into an IRelatalbe |
| 80 | type RelWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap# struct { |
| 81 | relatedscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#related. []Relatablescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Relatable# |
| 82 | sourcescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#source. uint32 |
| 83 | } |
| 84 | |
| 85 | func (w *RelWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#) Sourcescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#Source().() uint32 { |
| 86 | return w.sourcescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#source. |
| 87 | } |
| 88 | func (w *RelWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#) SetSourcescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#SetSource().(s uint32) { |
| 89 | w.sourcescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#source. = s |
| 90 | } |
| 91 | func (w *RelWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#) AddRelatedscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#AddRelated().(r Relatablescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Relatable#) { |
| 92 | if w.relatedscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#related. == nil { |
| 93 | w.relatedscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#related. = make([]Relatablescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Relatable#, 0, 2) |
| 94 | } |
| 95 | w.relatedscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#related. = append(w.relatedscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#related., r) |
| 96 | } |
| 97 | |
| 98 | func (w *RelWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#) Relatedscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#Related().() []Relatablescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Relatable# { |
| 99 | return w.relatedscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#related. |
| 100 | } |
| 101 | |
| 102 | type VarWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/VarWrap# struct { |
| 103 | IVariantscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/VarWrap#IVariant. |
| 104 | *RelWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/VarWrap#RelWrap. |
| 105 | } |
| 106 | |
| 107 | type PosWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/PosWrap# struct { |
| 108 | SIPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/PosWrap#SIPosition. |
| 109 | *RelWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/PosWrap#RelWrap. |
| 110 | } |
| 111 | |
| 112 | type RAWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RAWrap# struct { |
| 113 | IRefAltscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RAWrap#IRefAlt. |
| 114 | *RelWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RAWrap#RelWrap. |
| 115 | } |
| 116 | |
| 117 | // turn a position thingy into a Relatable |
| 118 | func AsRelatablescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/AsRelatable().(p SIPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/SIPosition#) Relatablescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Relatable# { |
| 119 | if v, ok := p.(IVariantscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IVariant#); ok { |
| 120 | return VarWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/VarWrap#{IVariantscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/VarWrap#IVariant.: v, RelWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/VarWrap#RelWrap.: &RelWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#{}} |
| 121 | } |
| 122 | if v, ok := p.(IRefAltscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IRefAlt#); ok { |
| 123 | return &RAWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RAWrap#{IRefAltscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RAWrap#IRefAlt.: v, RelWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RAWrap#RelWrap.: &RelWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#{}} |
| 124 | } |
| 125 | return &PosWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/PosWrap#{SIPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/PosWrap#SIPosition.: p, RelWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/PosWrap#RelWrap.: &RelWrapscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/RelWrap#{}} |
| 126 | } |
| 127 | |
| 128 | type ipscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/ip# struct { |
| 129 | chromscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/ip#chrom. string |
| 130 | startscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/ip#start. uint32 |
| 131 | endscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/ip#end. uint32 |
| 132 | } |
| 133 | |
| 134 | func (p ipscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/ip#) Chromscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/ip#Chrom().() string { |
| 135 | return p.chromscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/ip#chrom. |
| 136 | } |
| 137 | func (p ipscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/ip#) Startscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/ip#Start().() uint32 { |
| 138 | return p.startscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/ip#start. |
| 139 | } |
| 140 | func (p ipscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/ip#) Endscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/ip#End().() uint32 { |
| 141 | return p.endscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/ip#end. |
| 142 | } |
| 143 | |
| 144 | // AsIPosition take chrom, start, end and returns an struct that meets the IPosition interface |
| 145 | func AsIPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/AsIPosition().(chrom string, start int, end int) IPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition# { |
| 146 | return ipscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/ip#{chrom, uint32(start), uint32(end)} |
| 147 | } |
| 148 | |
| 149 | // SameChrom returns true if the strings are the same chromosome. Adjust for "chr" prefix. |
| 150 | func SameChromscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/SameChrom().(a, b string) bool { |
| 151 | if a == b { |
| 152 | return true |
| 153 | } |
| 154 | return StripChrscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/StripChr().(a) == StripChrscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/StripChr().(b) |
| 155 | } |
| 156 | |
| 157 | // StripChr removes the "chr" prefix if it is present |
| 158 | func StripChrscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/StripChr().(c string) string { |
| 159 | if stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.23.0 strings/HasPrefix().(c, "chr") { |
| 160 | return c[3:] |
| 161 | } |
| 162 | return c |
| 163 | } |
| 164 | |
| 165 | // SamePosition tests if 2 IPositions are the same |
| 166 | func SamePositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/SamePosition().(a, b IPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#) bool { |
| 167 | return a.Startscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#Start.() == b.Startscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#Start.() && a.Endscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#End.() == b.Endscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#End.() && SameChromscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/SameChrom().(a.Chromscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#Chrom.(), b.Chromscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#Chrom.()) |
| 168 | } |
| 169 | |
| 170 | // SamePosition tests if 2 IPositions overlap |
| 171 | func OverlapsPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/OverlapsPosition().(a, b IPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#) bool { |
| 172 | return (b.Startscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#Start.() < a.Endscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#End.() && b.Endscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#End.() > a.Startscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#Start.()) && SameChromscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/SameChrom().(a.Chromscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#Chrom.(), b.Chromscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#Chrom.()) |
| 173 | } |
| 174 | |
| 175 | // equalFoldASCII reports whether s and t are equal under ASCII case |
| 176 | // folding only: A-Z/a-z fold to each other, every other byte (including all |
| 177 | // non-ASCII) must match exactly. It is NOT equivalent to strings.EqualFold, |
| 178 | // which also applies Unicode simple folding. Intended for comparing REF and ALT |
| 179 | // VCF fields, which are limited to A, C, G, T, N by spec. |
| 180 | func equalFoldASCIIscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/equalFoldASCII().(s, t string) bool { |
| 181 | if len(s) != len(t) { |
| 182 | return false |
| 183 | } |
| 184 | for i := 0; i < len(s); i++ { |
| 185 | sb := s[i] |
| 186 | tb := t[i] |
| 187 | if sb == tb { |
| 188 | continue |
| 189 | } |
| 190 | // ASCII letters of opposite case differ by exactly 0x20. |
| 191 | if sb^tb != 0x20 { |
| 192 | return false |
| 193 | } |
| 194 | // Make sure the character is actually A-Z/a-z. |
| 195 | c := sb | 0x20 |
| 196 | if c < 'a' || c > 'z' { |
| 197 | return false |
| 198 | } |
| 199 | } |
| 200 | return true |
| 201 | } |
| 202 | |
| 203 | // SameVariant tests if 2 IRefAlts share the same position and ref and alt. |
| 204 | func SameVariantscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/SameVariant().(a, b IRefAltscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IRefAlt#) bool { |
| 205 | if !SamePositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/SamePosition().(a, b) || !equalFoldASCIIscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/equalFoldASCII().(a.Refscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IRefAlt#Ref.(), b.Refscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IRefAlt#Ref.()) { |
| 206 | return false |
| 207 | } |
| 208 | aalts := a.Altscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IRefAlt#Alt.() |
| 209 | balts := b.Altscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IRefAlt#Alt.() |
| 210 | for _, aalt := range aalts { |
| 211 | for _, balt := range balts { |
| 212 | if equalFoldASCIIscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/equalFoldASCII().(aalt, balt) { |
| 213 | return true |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | if len(aalts) == 0 || len(balts) == 0 { |
| 218 | return false |
| 219 | } |
| 220 | if aalts[0] == "<NON_REF>" || balts[0] == "<NON_REF>" { |
| 221 | return true |
| 222 | } |
| 223 | return false |
| 224 | } |
| 225 | |
| 226 | // Same tests the identity of 2 IPositions and attempts to cast to IRefAlts for more stringent |
| 227 | // checking. |
| 228 | func Samescip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/Same().(a, b IPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IPosition#, strict bool) bool { |
| 229 | // strict only applies if both are IVariants, otherwise, we just check for overlap. |
| 230 | if !strict { |
| 231 | return OverlapsPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/OverlapsPosition().(a, b) |
| 232 | } |
| 233 | if av, ok := a.(IRefAltscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IRefAlt#); ok { |
| 234 | if bv, ok := b.(IRefAltscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/IRefAlt#); ok { |
| 235 | if strict { |
| 236 | return SameVariantscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/SameVariant().(av, bv) |
| 237 | } |
| 238 | } |
| 239 | return OverlapsPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/OverlapsPosition().(a, b) |
| 240 | } |
| 241 | // at most one of them is a variant, just check overlap. |
| 242 | return OverlapsPositionscip-go gomod github.com/brentp/irelate . `github.com/brentp/irelate/interfaces`/OverlapsPosition().(a, b) |
| 243 | } |