<commit_before>// Copyright ©2011-2013 The bíogo Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package alphabet describes biological sequence letters, including quality scores.
package alphabet

import (
	"github.com/biogo/biogo/feat"

	"errors"
	"fmt"
	"strings"
	"unicode"
)

const (
	CaseSensitive = true
)

// Package alphabet provides default Alphabets for DNA, RNA and Protein. These
// alphabets are case insensitive and for the non-redundant nucleic acid alphabets
// satisfy the condition that the index of a letter is equal to the bitwise-complement
// of the index of the base-complement, modulo 4.
var (
	DNA = MustComplement(NewComplementor(
		"acgt",
		feat.DNA,
		MustPair(NewPairing("acgtnxACGTNX-", "tgcanxTGCANX-")),
		'-', 'n',
		!CaseSensitive,
	))

	DNAgapped = MustComplement(NewComplementor(
		"-acgt",
		feat.DNA,
		MustPair(NewPairing("acgtnxACGTNX-", "tgcanxTGCANX-")),
		'-', 'n',
		!CaseSensitive,
	))

	DNAredundant = MustComplement(NewComplementor(
		"-acmgrsvtwyhkdbn",
		feat.DNA,
		MustPair(NewPairing("acmgrsvtwyhkdbnxACMGRSVTWYHKDBNX-", "tgkcysbawrdmhvnxTGKCYSBAWRDMHVNX-")),
		'-', 'n',
		!CaseSensitive,
	))

	RNA = MustComplement(NewComplementor(
		"acgu",
		feat.RNA,
		MustPair(NewPairing("acgunxACGUNX-", "ugcanxUGCANX-")),
		'-', 'n',
		!CaseSensitive,
	))

	RNAgapped = MustComplement(NewComplementor(
		"-acgu",
		feat.RNA,
		MustPair(NewPairing("acgunxACGUNX-", "ugcanxUGCANX-")),
		'-', 'n',
		!CaseSensitive,
	))

	RNAredundant = MustComplement(NewComplementor(
		"-acmgrsvuwyhkdbn",
		feat.RNA,
		MustPair(NewPairing("acmgrsvuwyhkdbnxACMGRSVUWYHKDBNX-", "ugkcysbawrdmhvnxUGKCYSBAWRDMHVNX-")),
		'-', 'n',
		!CaseSensitive,
	))

	Protein = Must(NewAlphabet(
		"-abcdefghijklmnpqrstvwxyz*",
		feat.Protein,
		'-', 'x',
		!CaseSensitive,
	))
)

// Must is a helper that wraps a call to a function returning (Alphabet, error)
// and panics if the error is non-nil. It is intended for use in variable
// initializations.
func Must(a Alphabet, err error) Alphabet {
	if err != nil {
		panic(err)
	}
	return a
}

// MustComplement is a helper that wraps a call to a function returning (Complementor, error)
// and panics if the error is non-nil. It is intended for use in variable
// initializations.
func MustComplement(c Complementor, err error) Complementor {
	if err != nil {
		panic(err)
	}
	return c
}

// MustPair is a helper that wraps a call to a function returning (*Pairing, error)
// and panics if the error is non-nil. It is intended for use in variable
// initializations.
func MustPair(p *Pairing, err error) *Pairing {
	if err != nil {
		panic(err)
	}
	return p
}

// Type Index is a pointer to an index table.
type Index *[256]int

// An Alphabet describes valid single character letters within a sequence.
type Alphabet interface {
	// IsValid returns whether a letter conforms to the alphabet.
	IsValid(Letter) bool

	// AllValid checks that a slice of bytes conforms to the alphabet,
	// returning false and the position of the first invalid byte if
	// invalid and true and a negative int if valid.
	AllValid([]Letter) (ok bool, pos int)

	// AllValidQLetter checks that a slice of bytes conforms to the alphabet,
	// returning false and the position of the first invalid byte if invalid
	// and true and a negative int if valid.
	AllValidQLetter([]QLetter) (ok bool, pos int)

	// Len returns the number of distinct valid letters in the alphabet.
	Len() int

	// IndexOf returns the index of a given letter.
	IndexOf(Letter) int

	// Letter returns the letter corresponding to the given index.
	Letter(int) Letter

	// LetterIndex returns a pointer to the internal array specifying
	// letter to index conversion. The returned index should not be altered.
	LetterIndex() Index

	// Letters returns a string of letters conforming to the alphabet in index
	// order. In case insensitive alphabets, both cases are presented.
	Letters() string

	// ValidLetters return a slice of the internal []bool indicating valid
	// letters. The returned slice should not be altered.
	ValidLetters() []bool

	// Gap return the gap character used by the alphabet.
	Gap() Letter

	// Ambiguous return the character representing an ambiguous letter.
	Ambiguous() Letter

	// Moltype returns the molecule type of the alphabet.
	Moltype() feat.Moltype

	// IsCased returns whether the alphabet is case sensitive.
	IsCased() bool
}

// A Complementor is an Alphabet that describes the complementation relationships
// between letters.
type Complementor interface {
	Alphabet
	Complement(Letter) (Letter, bool)
	ComplementTable() []Letter<commit_msg>alphabet: fix documentation typos<commit_after>// Copyright ©2011-2013 The bíogo Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package alphabet describes biological sequence letters, including quality scores.
package alphabet

import (
	"github.com/biogo/biogo/feat"

	"errors"
	"fmt"
	"strings"
	"unicode"
)

const (
	CaseSensitive = true
)

// Package alphabet provides default Alphabets for DNA, RNA and Protein. These
// alphabets are case insensitive and for the non-redundant nucleic acid alphabets
// satisfy the condition that the index of a letter is equal to the bitwise-complement
// of the index of the base-complement, modulo 4.
var (
	DNA = MustComplement(NewComplementor(
		"acgt",
		feat.DNA,
		MustPair(NewPairing("acgtnxACGTNX-", "tgcanxTGCANX-")),
		'-', 'n',
		!CaseSensitive,
	))

	DNAgapped = MustComplement(NewComplementor(
		"-acgt",
		feat.DNA,
		MustPair(NewPairing("acgtnxACGTNX-", "tgcanxTGCANX-")),
		'-', 'n',
		!CaseSensitive,
	))

	DNAredundant = MustComplement(NewComplementor(
		"-acmgrsvtwyhkdbn",
		feat.DNA,
		MustPair(NewPairing("acmgrsvtwyhkdbnxACMGRSVTWYHKDBNX-", "tgkcysbawrdmhvnxTGKCYSBAWRDMHVNX-")),
		'-', 'n',
		!CaseSensitive,
	))

	RNA = MustComplement(NewComplementor(
		"acgu",
		feat.RNA,
		MustPair(NewPairing("acgunxACGUNX-", "ugcanxUGCANX-")),
		'-', 'n',
		!CaseSensitive,
	))

	RNAgapped = MustComplement(NewComplementor(
		"-acgu",
		feat.RNA,
		MustPair(NewPairing("acgunxACGUNX-", "ugcanxUGCANX-")),
		'-', 'n',
		!CaseSensitive,
	))

	RNAredundant = MustComplement(NewComplementor(
		"-acmgrsvuwyhkdbn",
		feat.RNA,
		MustPair(NewPairing("acmgrsvuwyhkdbnxACMGRSVUWYHKDBNX-", "ugkcysbawrdmhvnxUGKCYSBAWRDMHVNX-")),
		'-', 'n',
		!CaseSensitive,
	))

	Protein = Must(NewAlphabet(
		"-abcdefghijklmnpqrstvwxyz*",
		feat.Protein,
		'-', 'x',
		!CaseSensitive,
	))
)

// Must is a helper that wraps a call to a function returning (Alphabet, error)
// and panics if the error is non-nil. It is intended for use in variable
// initializations.
func Must(a Alphabet, err error) Alphabet {
	if err != nil {
		panic(err)
	}
	return a
}

// MustComplement is a helper that wraps a call to a function returning (Complementor, error)
// and panics if the error is non-nil. It is intended for use in variable
// initializations.
func MustComplement(c Complementor, err error) Complementor {
	if err != nil {
		panic(err)
	}
	return c
}

// MustPair is a helper that wraps a call to a function returning (*Pairing, error)
// and panics if the error is non-nil. It is intended for use in variable
// initializations.
func MustPair(p *Pairing, err error) *Pairing {
	if err != nil {
		panic(err)
	}
	return p
}

// Type Index is a pointer to an index table.
type Index *[256]int

// An Alphabet describes valid single character letters within a sequence.
type Alphabet interface {
	// IsValid returns whether a letter conforms to the alphabet.
	IsValid(Letter) bool

	// AllValid checks that a slice of bytes conforms to the alphabet,
	// returning false and the position of the first invalid byte if
	// invalid and true and a negative int if valid.
	AllValid([]Letter) (ok bool, pos int)

	// AllValidQLetter checks that a slice of bytes conforms to the alphabet,
	// returning false and the position of the first invalid byte if invalid
	// and true and a negative int if valid.
	AllValidQLetter([]QLetter) (ok bool, pos int)

	// Len returns the number of distinct valid letters in the alphabet.
	Len() int

	// IndexOf returns the index of a given letter.
	IndexOf(Letter) int

	// Letter returns the letter corresponding to the given index.
	Letter(int) Letter

	// LetterIndex returns a pointer to the internal array specifying
	// letter to index conversion. The returned index should not be altered.
	LetterIndex() Index

	// Letters returns a string of letters conforming to the alphabet in index
	// order. In case insensitive alphabets, both cases are presented.
	Letters() string

	// ValidLetters returns a slice of the internal []bool indicating valid
	// letters. The returned slice should not be altered.
	ValidLetters() []bool

	// Gap returns the gap character used by the alphabet.
	Gap() Letter

	// Ambiguous returns the character representing an ambiguous letter.
	Ambiguous() Letter

	// Moltype returns the molecule type of the alphabet.
	Moltype() feat.Moltype

	// IsCased returns whether the alphabet is case sensitive.
	IsCased() bool
}

// A Complementor is an Alphabet that describes the complementation relationships
// between letters.
type Complementor interface {
	Alphabet
	Complement(Letter) (Letter, bool)
	ComplementTable() []Letter
{'fraction_non_alphanumeric': 0.09896665601363588, 'fraction_numerical': 0.002556727388942154, 'mean_word_length': 3.935856992639327, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1416200', 'n_tokens_mistral': 3299, 'n_tokens_neox': 2996, 'n_words': 1080}