Skip to content

Commit f6a061b

Browse files
committed
stranded-wig
1 parent 8a8ab20 commit f6a061b

File tree

6 files changed

+30
-10
lines changed

6 files changed

+30
-10
lines changed

bamtocov.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Package
22

3-
version = "2.3.1"
3+
version = "2.4.0"
44
author = "Andrea Telatin, Giovanni Birolo"
55
description = "BAM to Coverage"
66
license = "MIT"

bin/covtotarget

-65.4 KB
Binary file not shown.

bin/gff2bed

-69.7 KB
Binary file not shown.

docs/5_history.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ permalink: /history
77
This project extends [covtobed](https://github.com/telatin/covtobed),
88
reimplementing the core algorithm in Nim.
99

10+
* 2.4.0
11+
* Standed analysis is now supported with Wig-like output
12+
* 2.3.0:
13+
* Improved Wig support
14+
* Improved GTF format detection
15+
* Expanded test suite
1016
* 2.2.0:
1117
* Support for wiggle output (`--wig STEP` and `--op FUNCT`)
1218
* 2.1.1:

src/bamtocov.nim

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ Target files:
707707
-i, --gff-id <ID> GFF identifier [default: ID]
708708
--gff-separator <sep> GFF attributes separator [default: ;]
709709
--gff Force GFF input (otherwise assumed by extension .gff)
710+
--gtf Force GTF input (otherwise assumed by extension .gtf)
710711
711712
BAM reading options:
712713
-T, --threads <threads> BAM decompression threads [default: 0]
@@ -734,15 +735,25 @@ Other options:
734735
var
735736
#bams: seq[BAM]
736737
format_gff = false
738+
format_gtf = false
737739

738740
# Set target format (GFF/BED) using extension or forced by the user
739-
if ($args["--regions"]).toLower().contains(".gff") or ($args["--regions"]).toLower().contains(".gtf") or args["--gff"]:
741+
if ($args["--regions"]).toLower().contains(".gff"):
740742
dbEcho("Parsing target as GFF")
741743
format_gff = true
744+
elif ($args["--regions"]).toLower().contains(".gtf"):
745+
format_gtf = true
742746
else:
743747
dbEcho("Parsing target as BED")
744748

745-
749+
if (args["--gtf"] and args["--gff"]) or (format_gff and format_gtf):
750+
echo "ERROR: Target format is ambiguous: specify a GFF or GTF target (ideally autoinferred from the extension)"
751+
quit(1)
752+
elif args["--gtf"]:
753+
format_gtf = true
754+
elif args["--gff"]:
755+
format_gff = true
756+
746757
assert( $args["--op"] in @["mean", "min", "max"], "--op must be one of mean, min, max, got: " & $args["--op"])
747758

748759
let
@@ -760,7 +771,9 @@ Other options:
760771
min_mapping_quality: uint8(parse_int($args["--mapq"])),
761772
eflag: uint16(parse_int($args["--flag"])),
762773
physical: bool(args["--physical"]),
763-
target: if format_gff: gff_to_table(target_file, gffField, gffSeparator, gffIdentifier) else: bed_to_table(target_file)
774+
target: if format_gff: gff_to_table(target_file, gffField, gffSeparator, gffIdentifier)
775+
elif format_gtf: gtf_to_table(target_file, gffField, gffSeparator, gffIdentifier)
776+
else: bed_to_table(target_file)
764777
)
765778
output_opts: output_option_t = (
766779
strand: bool(args["--stranded"]),

src/covtotarget.nim

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var
3838
gffField = "CDS"
3939
bedOutput = false
4040

41-
type
41+
#[ type
4242
region_t = ref object
4343
chrom: string
4444
start: int
@@ -49,6 +49,7 @@ type
4949
5050
proc start(r: region_t): int {.inline.} = return r.start
5151
proc stop(r: region_t): int {.inline.} = return r.stop
52+
]#
5253
#proc `$`(m:region_t): string = return "($#-$#:$#, $#)" % [$m.chrom, $m.start, $m.stop, $m.name]
5354
#proc inc_count(r:region_t) = inc(r.count)
5455

@@ -61,7 +62,7 @@ proc overlapLen(reference, feature: region_t): int =
6162
return feature.stop - feature.start
6263

6364
# Converts a GFF line to region object
64-
proc gff_line_to_region(line: string): region_t =
65+
#[ proc gff_line_to_region(line: string): region_t =
6566
var
6667
cse = line.strip().split('\t')
6768
@@ -157,7 +158,7 @@ proc gff_to_table(bed: string): TableRef[string, seq[region_t]] =
157158
158159
hts.free(kstr.s)
159160
return bed_regions
160-
161+
]#
161162

162163
proc processCoverage(f: File, target: TableRef[string, seq[region_t]], normalize: bool, bedout: bool) =
163164
var
@@ -231,7 +232,7 @@ Arguments:
231232
232233
Options:
233234
234-
-g, --gff Force GFF for input (otherwise autodetected by .gff extension)
235+
-g, --gff Force GFF for input (otherwise autodetected by .gff/.gtf extension)
235236
-t, --type <feat> GFF feature type to parse [default: CDS]
236237
-i, --id <ID> GFF identifier [default: ID]
237238
-l, --norm-len Normalize by gene length
@@ -251,15 +252,15 @@ Options:
251252
gffField = $args["--type"]
252253
bedOutput = args["--bed-output"]
253254

254-
if ($args["<Target>"]).contains(".gff"):
255+
if ($args["<Target>"]).contains(".gff") or (($args["<Target>"]).contains(".gtf") ):
255256
prokkaGff = true
256257

257258

258259
if not fileExists($args["<Target>"]):
259260
stderr.writeLine("FATAL ERROR: Unable to read target regions: ", $args["<Target>"])
260261
quit(1)
261262

262-
var targetRegions = if prokkaGff == true: gff_to_table($args["<Target>"])
263+
var targetRegions = if prokkaGff == true: gff_to_table($args["<Target>"],gffField, gffSeparator, gffIdentifier)
263264
else: bed_to_table($args["<Target>"])
264265

265266
var

0 commit comments

Comments
 (0)