Skip to content

Commit

Permalink
Add option to translate command to skip errors while translating (she…
Browse files Browse the repository at this point in the history
…nwei356#458)

* Skip errors on translate

* init skip translate error

---------

Co-authored-by: Khalil Chatoo <[email protected]>
  • Loading branch information
khalilchatoo and kchatoo-sc authored Apr 26, 2024
1 parent 98a4782 commit 9530bc8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions seqkit/cmd/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Translate Tables/Genetic Codes:
listTable := getFlagInt(cmd, "list-transl-table")
listTableAmb := getFlagInt(cmd, "list-transl-table-with-amb-codons")
appendFrame := getFlagBool(cmd, "append-frame")
skipTranslateErrors := getFlagBool(cmd, "skip-translate-errors")

outSubseqs := getFlagBool(cmd, "out-subseqs")
minLen := getFlagNonNegativeInt(cmd, "min-len")
Expand Down Expand Up @@ -193,6 +194,11 @@ Translate Tables/Genetic Codes:

for _, frame = range frames {
_seq, err = record.Seq.Translate(translTable, frame, trim, clean, allowUnknownCodon, markInitCodonAsM)
if err != nil && skipTranslateErrors {
outfh.WriteString(fmt.Sprintf(">%s %s\n\n", record.ID, record.Desc))
continue
}

if err != nil {
if err == seq.ErrUnknownCodon {
log.Error("unknown codon detected, you can use flag -x/--allow-unknown-codon to translate it to 'X'.")
Expand Down Expand Up @@ -285,4 +291,5 @@ func init() {
translateCmd.Flags().BoolP("append-frame", "F", false, "append frame information to sequence ID")
translateCmd.Flags().BoolP("out-subseqs", "s", false, `output individual amino acid subsequences seperated by the stop symbol "*"`)
translateCmd.Flags().IntP("min-len", "m", 0, `the minimum length of amino acid sequence`)
translateCmd.Flags().BoolP("skip-translate-errors", "e", false, `skip errors during translate and output blank sequence`)
}

0 comments on commit 9530bc8

Please sign in to comment.