Skip to content

Commit

Permalink
seqkit subseq ­- accept reverse coordinates in gtf/bed. #392
Browse files Browse the repository at this point in the history
  • Loading branch information
shenwei356 committed Jun 25, 2023
1 parent c09d536 commit 819a528
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
- `seqkit seq`:
- update help message. [#387](https://github.com/shenwei356/seqkit/issues/387)
- `seqkit fxtab`:
- faster alphabet computation (`-a/--alphabet`) with a new data structure. [#388](https://github.com/shenwei356/seqkit/pull/388)
- faster alphabet computation (`-a/--alphabet`) with a new data structure. Thanks to @elliotwutingfeng [#388](https://github.com/shenwei356/seqkit/pull/388)
- `seqkit translate`:
- add options `-s/--out-subseqs` and `-m/--min-len` to write ORFs longer than `x` amino acids as individual records. [#389](https://github.com/shenwei356/seqkit/issues/389)
- `seqkit subseq`:
- accept reverse coordinates in BED/GTF. [#392](https://github.com/shenwei356/seqkit/issues/392)
- [SeqKit v2.4.0](https://github.com/shenwei356/seqkit/releases/tag/v2.4.0) - 2023-03-17
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/seqkit/v2.4.0/total.svg)](https://github.com/shenwei356/seqkit/releases/tag/v2.4.0)
- `seqkit`:
Expand Down
31 changes: 26 additions & 5 deletions seqkit/cmd/bed.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ type BedFeature struct {
// Threads for bread.NewBufferedReader()
var Threads = runtime.NumCPU()

var strandPositive = "+"
var strandNegative = "-"
var strandNotspecified = "."

// ReadBedFeatures returns gtf BedFeatures of a file
func ReadBedFeatures(file string) ([]BedFeature, error) {
return ReadBedFilteredFeatures(file, []string{})
Expand Down Expand Up @@ -84,20 +88,37 @@ func ReadBedFilteredFeatures(file string, chrs []string) ([]BedFeature, error) {
if err != nil {
return nil, false, fmt.Errorf("%s: bad end: %s", items[0], items[2])
}
if start >= end {
return nil, false, fmt.Errorf("%s: start (%d) must be <= end (%d)", items[0], start, end)
if start == end {
return nil, false, fmt.Errorf("%s: start (%d) should not be equal to end (%d)", items[0], start, end)
}

var name *string
if n >= 4 {
name = &items[3]
_name := items[3]
name = &_name
}
var strand *string
if n >= 6 {
if items[5] != "+" && items[5] != "-" && items[5] != "." {
switch items[5] {
case "+":
strand = &strandPositive
if start > end {
return nil, false, fmt.Errorf(`%s: start (%d) should be < end (%d) when the strand is "+"`, items[0], start, end)
}
case "-":
strand = &strandNegative
case ".":
strand = &strandNotspecified
default:
return nil, false, fmt.Errorf("bad strand: %s", items[5])
}
strand = &items[5]
}

if start > end {
strand = &strandNegative
tmp := start
start = end
end = tmp
}

return BedFeature{items[0], start + 1, end, name, strand}, true, nil
Expand Down

0 comments on commit 819a528

Please sign in to comment.