Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
telatin committed Oct 5, 2022
1 parent 07af7fb commit 4e179ac
Show file tree
Hide file tree
Showing 14 changed files with 1,006 additions and 182 deletions.
9 changes: 9 additions & 0 deletions src/fastx_grep.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# --------------------------------------------
# LEGACY GREP
# --------------------------------------------

#[
This is the original implementation made using
klib instead of readfq
]#

import klib
import tables, strutils
from os import fileExists
Expand Down
1 change: 0 additions & 1 deletion src/fastx_head.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#import klib
import readfq
import strformat
import tables, strutils
Expand Down
54 changes: 54 additions & 0 deletions src/fastx_less.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import readfq
import strformat
import tables, strutils
from os import fileExists
import docopt
import ./seqfu_utils



proc fastx_head_v2(argv: var seq[string]): int =
let args = docopt("""
Usage: less [options] <file_1> [<file_2>]
View a single FASTQ file or paired-end FASTQ dataset.
Options:
-i, --interleaved Input is interleaved paired-end FASTQ
-n, --num NUM Print the first NUM sequences [default: 10]
-k, --skip SKIP Print one sequence every SKIP [default: 0]
-p, --prefix STRING Rename sequences with prefix + incremental number
-s, --strip-comments Remove comments
-b, --basename prepend basename to sequence name
-v, --verbose Verbose output
--print-last Print the name of the last sequence to STDERR (Last:NAME)
--fatal Exit with error if less than NUM sequences are found
--quiet Don't print warnings
--help Show this help
""", version=version(), argv=argv)

var
num, skip : int
prefix : string
files : seq[string]
printBasename: bool
separator : string

let
printLast = bool(args["--print-last"])
fatalWarning = bool(args["--fatal"])


if args["<file_1>"].len() == 0:
if getEnv("SEQFU_QUIET") == "":
stderr.writeLine("[seqfu head] Waiting for STDIN... [Ctrl-C to quit, type with --help for info].")
files.add("-")
else:
for file in args["<inputfile>"]:
files.add(file)



36 changes: 15 additions & 21 deletions src/fastx_rc.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import klib
import strformat
import tables, strutils
import readfq
import tables
from os import fileExists
import docopt
import ./seqfu_utils
Expand Down Expand Up @@ -58,26 +57,21 @@ Options:
else:
echoVerbose(filename, verbose)

var
f = xopen[GzFile](filename)
r: FastxRecord

defer: f.close()


while f.readFastx(r):
for record in readfq(filename):
var
r = record
let comment = if len(r.comment) > 0 and not args["--strip-comments"]: " " & r.comment
else: ""
if args["--only-rev"]:
r.seq = reverse(r.seq)
r.sequence = reverse(r.sequence)
else:
r.seq = revcompl(r.seq)
r.sequence = revcompl(r.sequence)

if len(r.qual) > 0:
r.qual = reverse(r.qual)
echo '@', r.name, comment, "\n", r.seq, "\n+\n", r.qual
if len(r.quality) > 0:
r.quality = reverse(r.quality)
echo '@', r.name, comment, "\n", r.sequence, "\n+\n", r.quality
else:
echo '>', r.name, comment, "\n", r.seq
echo '>', r.name, comment, "\n", r.sequence


#[
Expand Down Expand Up @@ -138,12 +132,12 @@ Options:
let comment = if len(r.comment) > 0 and not args["--strip-comments"]: " " & r.comment
else: ""
if args["--only-rev"]:
outRecord.sequence = reverse(r.sequence)
outRecord.sequence = reverse(r.sequenceuence)
else:
outRecord.sequence = revcompl(r.sequence)
outRecord.sequence = revcompl(r.sequenceuence)
if len(r.quality) > 0:
outRecord.quality = reverse(r.quality)
if len(r.qualityity) > 0:
outRecord.quality = reverse(r.qualityity)
echo '@', outRecord.name, comment, "\n", outRecord.sequence, "\n+\n", outRecord.quality
else:
echo '>', outRecord.name, comment, "\n", outRecord.sequence
Expand Down
26 changes: 11 additions & 15 deletions src/fastx_view.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import klib
import readfq
import tables, strutils
from os import fileExists
import docopt
Expand Down Expand Up @@ -247,36 +247,32 @@ Options:
stderr.writeLine("Error: input file not found: ", $args["<inputfile>"])
quit(1)

var
f = xopen[GzFile]($args["<inputfile>"])
read: FastxRecord

defer: f.close()
while f.readFastx(read):

for read in readfq($args["<inputfile>"]):
# Print seq name
if args["--nocolor"]:
echo "@", read.name, "\t", read.comment
else:
echo "@", (read.name).bold, "\t", (read.comment).fgLightGray

if $args["--oligo1"] != "nil":
let matches = findPrimerMatches(read.seq, $args["--oligo1"], matchThs, maxMismatches, minMatches)
let forString = highlightOligoMatches(read.seq, matches, len($args["--oligo1"]), bgBlue)
let matches = findPrimerMatches(read.sequence, $args["--oligo1"], matchThs, maxMismatches, minMatches)
let forString = highlightOligoMatches(read.sequence, matches, len($args["--oligo1"]), bgBlue)
if forString.isOnlySpaces == false:
echo forString
if $args["--oligo2"] != "nil":
let matches = findPrimerMatches(read.seq, $args["--oligo2"], matchThs, maxMismatches, minMatches)
let revString = highlightOligoMatches(read.seq, matches, len($args["--oligo2"]), bgRed)
let matches = findPrimerMatches(read.sequence, $args["--oligo2"], matchThs, maxMismatches, minMatches)
let revString = highlightOligoMatches(read.sequence, matches, len($args["--oligo2"]), bgRed)
if revString.isOnlySpaces == false:
echo revString
echo read.seq
echo read.sequence
if args["--qual-chars"]:
echo qualToColor(read.qual, thresholdValues, colorOutput)
echo qualToColor(read.quality, thresholdValues, colorOutput)
else:
if args["--ascii"]:
echo qualToAscii(read.qual, thresholdValues, colorOutput)
echo qualToAscii(read.quality, thresholdValues, colorOutput)
else:
echo qualToUnicode(read.qual, thresholdValues, colorOutput)
echo qualToUnicode(read.quality, thresholdValues, colorOutput)

if args["--verbose"]:
stderr.writeLine("Encoding: ", ce)
Expand Down
Binary file removed src/fqcheck
Binary file not shown.
47 changes: 47 additions & 0 deletions src/fqpair.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import iterutils
import sequtils
import readfq
import docopt
import seqfu_utils

template initClosure(id:untyped,iter:untyped) =
let id = iterator():auto {.closure.} =
for x in iter:
yield x

iterator letters: auto =
for c in 'a' .. 'z':
yield c


proc main(argv: var seq[string]): int =
let args = docopt("""
USAGE:
fqpair FILE1 FILE2
""", argv=argv)

let
file1 = $args["FILE1"]
file2 = $args["FILE2"]

echo "Reading file1: ", file1
echo "Reading file2: ", file2

initClosure(f1,readfq(file1))
initClosure(f2,readfq(file2))

var
c = 0
for (fwd, rev) in zip(f1, f2):
var
newseq : FQRecord

newseq = fwd
newseq.sequence &= "*"
c = c + 1
echo c, "\tfwd: ", fwd.name, " : ", rev.name
echo newseq.sequence


when isMainModule:
main_helper(main)
22 changes: 10 additions & 12 deletions src/fu_cov.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import klib
import readfq
import docopt
import strutils
import stats
Expand Down Expand Up @@ -140,9 +140,7 @@ proc main(args: var seq[string]): int =
echo "FATAL ERROR: File ", filename, " not found."
quit(1)

var f = xopen[GzFile](filename)
defer: f.close()
var r: FastxRecord

if args["--verbose"]:
stderr.writeLine "Reading ", filename

Expand All @@ -151,10 +149,10 @@ proc main(args: var seq[string]): int =
#var match: array[1, string]


while f.readFastx(r):
for r in readfq(filename):
c+=1
total_bases += len(r.seq)
lenStats.push(len(r.seq))
total_bases += len(r.sequence)
lenStats.push(len(r.sequence))
var cov = getCovFromString(r.name & " " & r.comment)

# Coverage check
Expand All @@ -168,20 +166,20 @@ proc main(args: var seq[string]): int =
continue

# Contig length filter
if optminlen > 0 and len(r.seq) < optminlen:
if optminlen > 0 and len(r.sequence) < optminlen:
skip_short += 1
continue
if optmaxlen > 0 and len(r.seq) > optmaxlen:
if optmaxlen > 0 and len(r.sequence) > optmaxlen:
skip_long += 1
continue


pf += 1
bases_printed += len(r.seq)
bases_printed += len(r.sequence)
if args["--sort"] == false:
echo ">", r.name, " ", r.comment, "\n", r.seq;
echo ">", r.name, " ", r.comment, "\n", r.sequence;
else:
covTable.add((name: r.name, comment: r.comment, cov: cov, length: len(r.seq), sequence: r.seq))
covTable.add((name: r.name, comment: r.comment, cov: cov, length: len(r.sequence), sequence: r.sequence))
let
ratio = 100.0 * float(bases_printed) / float(total_bases)

Expand Down
Loading

0 comments on commit 4e179ac

Please sign in to comment.