diff --git a/pkg/obiapat/pcr.go b/pkg/obiapat/pcr.go index 67e415d..5a30c53 100644 --- a/pkg/obiapat/pcr.go +++ b/pkg/obiapat/pcr.go @@ -333,6 +333,9 @@ func _Pcr(seq ApatSequence, annot["reverse_primer"] = reverse.String() match, _ = seq.pointer.reference.Subsequence(rm[0], rm[1], opt.pointer.circular) + if match == nil { + log.Fatalf("error in extracting sequence from reference: %d:%d (%v)\n", rm[0], rm[1], opt.pointer.circular) + } match = match.ReverseComplement(true) annot["reverse_match"] = match.String() match.Recycle() diff --git a/pkg/obiseq/revcomp.go b/pkg/obiseq/revcomp.go index 580ea40..d9d1391 100644 --- a/pkg/obiseq/revcomp.go +++ b/pkg/obiseq/revcomp.go @@ -43,6 +43,10 @@ func nucComplement(n byte) byte { // The function returns the reverse complemented BioSequence. func (sequence *BioSequence) ReverseComplement(inplace bool) *BioSequence { + if sequence == nil { + return nil + } + if !inplace { sequence = sequence.Copy() } diff --git a/pkg/obiseq/subseq.go b/pkg/obiseq/subseq.go index c288c2e..7d714f1 100644 --- a/pkg/obiseq/subseq.go +++ b/pkg/obiseq/subseq.go @@ -2,6 +2,8 @@ package obiseq import ( "fmt" + + log "github.com/sirupsen/logrus" ) // Subsequence returns a subsequence of the BioSequence. @@ -23,14 +25,20 @@ func (sequence *BioSequence) Subsequence(from, to int, circular bool) (*BioSeque return nil, fmt.Errorf("from out of bounds %d < 0", from) } - if from >= sequence.Len() { + if from >= sequence.Len() && !circular { return nil, fmt.Errorf("from out of bounds %d >= %d", from, sequence.Len()) + } else { + log.Debugf("(%s) correcting from position from %d to %d", sequence.Id(), to, (to-1)%sequence.Len()+1) + from = from % sequence.Len() } - if to > sequence.Len() { + if to > sequence.Len() && !circular { return nil, fmt.Errorf("to out of bounds %d > %d", to, sequence.Len()) + } else { + log.Debugf("(%s) correcting to position from %d to %d", sequence.Id(), to, (to-1)%sequence.Len()+1) + to = ((to - 1) % sequence.Len()) + 1 } var newSeq *BioSequence