Skip to content

Commit

Permalink
Prerelease with seqfu-metadata updated for MetaPhage
Browse files Browse the repository at this point in the history
  • Loading branch information
telatin committed Mar 30, 2022
1 parent 6fb6518 commit a124cf9
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

BIN=./bin
SOURCE=./src
VERSION := $(shell grep version seqfu.nimble | grep -o "[0-9]\\+\.[0-9]\.[0-9]\\+")
VERSION := $(shell grep version seqfu.nimble | grep -o "[0-9]\\+\.[0-9]\\+\.[0-9]\\+")
NIMPARAM := --gc:arc -d:NimblePkgVersion=$(VERSION) -d:release --opt:speed
TARGETS=$(BIN)/seqfu $(BIN)/fu-msa $(BIN)/fu-primers $(BIN)/dadaist2-mergeseqs $(BIN)/fu-shred $(BIN)/fu-homocomp $(BIN)/fu-multirelabel $(BIN)/fu-index $(BIN)/fu-cov $(BIN)/fu-16Sregion $(BIN)/fu-nanotags $(BIN)/fu-orf $(BIN)/fu-sw $(BIN)/fu-virfilter $(BIN)/fu-tabcheck $(BIN)/fu-homocomp

Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions releases/changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Added support for MetaPhage to **seqfu metadata**
* Added `--header` to **fu-tabcheck**
* Minor fixes
2 changes: 1 addition & 1 deletion seqfu.nimble
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Package
version = "1.9.3"
version = "1.10.0"
author = "Andrea Telatin"
description = "SeqFu command-line tools"
license = "MIT"
Expand Down
49 changes: 45 additions & 4 deletions src/fastx_metadata.nim
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,29 @@ proc printDadaist(samples: seq[sample]) =

echo s.name, path, counts

proc printMetaphage(samples: seq[sample], splitStr = "_", pick = 0) =
let headerCounts = if addCounts: ",Counts"
else: ""


echo "Sample", ",", "Treatment", ",", "Files", headerCounts
for s in samples:
var condition = "Cond"
try:
let splittedID = (s.name).split(splitStr)
let part = if len(splittedID) > pick: splittedID[pick]
else: splittedID[0]
condition = part
except:
condition = "Cond"

let condStr = "," & condition
let counts = if addCounts: "," & $s.count
else: ""
let path = if isPe > 0: "," & joinPath(s.path, s.file1) & ";" & joinPath(s.path, s.file2)
else: "," & joinPath(s.path, s.file1)

echo s.name, condStr, path, counts

proc fastx_metadata(argv: var seq[string]): int =
let validFormats = {
Expand All @@ -174,6 +197,7 @@ proc fastx_metadata(argv: var seq[string]): int =
"dadaist": "Dadaist2 metadata file",
"lotus": "lOTUs mappint file",
"irida": "IRIDA uploader file",
"metaphage": "Metaphage metadata file",
}.toTable


Expand All @@ -186,13 +210,20 @@ Options:
-1, --for-tag STR String found in filename of forward reads [default: _R1]
-2, --rev-tag STR String found in filename of forward reads [default: _R2]
-s, --split STR Separator used in filename to identify the sample ID [default: _]
-f, --format TYPE Output format: dadaist, manifest, qiime1, qiime2, irida [default: manifest]
-P, --project INT Project ID (only for irida)
--pos INT... Which part of the filename is the Sample ID [default: 1]
-f, --format TYPE Output format: dadaist, irida, manifest, metaphage, qiime1, qiime2 [default: manifest]
--pe Enforce paired-end reads (not supported)
-p, --add-path Add the reads absolute path as column
-c, --counts Add the number of reads as a property column
-t, --threads INT Number of simultaneously opened files [default: 2]
FORMAT SPECIFIC OPTIONS
-P, --project INT Project ID (only for irida)
--meta-split STR Separator in the SampleID to extract metadata, used in MetaPhage [default: _]
--meta-part INT Which part of the SampleID to extract metadata, used in MetaPhage [default: 1]
--meta-default STR Default value for metadata, used in MetaPhage [default: Cond]
-v, --verbose Verbose output
-h, --help Show this help
Expand All @@ -206,9 +237,13 @@ Options:
posList: seq[Value]
threads: int
projectID = 0
metaDefault = $args["--meta-default"]
metaSplit = $args["--meta-split"]
metaPart = 0
try:
projectID = if args["--project"]: parseInt($args["--project"])
else: 0
metaPart = parseInt($args["--meta-part"]) - 1
outFmt = $args["--format"]
forTag = $args["--for-tag"]
revTag = $args["--rev-tag"]
Expand All @@ -233,16 +268,20 @@ Options:

# Parameters validation: input dir
if len(args["<dir>"]) == 0:
stderr.writeLine("SeqFu tabulate\nERROR: Specify (at least) one input directory. Use --help for more info.")
stderr.writeLine("SeqFu metadata\nERROR: Specify (at least) one input directory. Use --help for more info.")
quit(0)

# Parameters validation: valid formats
if outFmt notin validFormats:
stderr.writeLine("SeqFu tabulate\nERROR: Invalid format (", outFmt, "). Accepted formats:")
stderr.writeLine("SeqFu metadata\nERROR: Invalid format (", outFmt, "). Accepted formats:")
for key, desc in validFormats.pairs:
stderr.writeLine(" - ", key, " (", desc, ")")
quit(1)

# Parameters validation: --meta-part
if metaPart < 0:
stderr.writeLine("SeqFu metadata\nERROR: Invalid value for --meta-part. It must be > 1.")
quit(1)

for dir in args["<dir>"]:
if not dirExists(dir):
Expand Down Expand Up @@ -317,6 +356,8 @@ Options:
printManifest(samples)
of "dadaist":
printDadaist(samples)
of "metaphage":
printMetaphage(samples, metaSplit, metaPart)
of "qiime1":
printQiime1(samples)
of "qiime2":
Expand Down
13 changes: 10 additions & 3 deletions src/fu_tabcheck.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ type
sep: string
errormsg: string

proc `$`(s: checkResult): string =
proc toString(s: checkResult, withHeader=false): string =
if s.valid:
result &= "Pass\t"
else:
result &= "Error"
return

result &= $(s.columns) & "\t" & $(s.records) & "\tseparator=" & s.sep
let sepStr = if not withHeader: "separator="
else: ""
result &= $(s.columns) & "\t" & $(s.records) & "\t" & sepStr & s.sep

proc checkFile(f: string, sep: char, header: char): checkResult =
var parser: CsvParser
Expand Down Expand Up @@ -79,6 +81,7 @@ proc main(): int =
-s --separator CHAR Character separating the values, 'tab' for tab and 'auto'
to try tab or commas [default: auto]
-c --comment CHAR Comment/Header char [default: #]
--header Print a header to the report
--verbose Enable verbose mode
""", version=version, argv=commandLineParams())

Expand All @@ -98,6 +101,7 @@ proc main(): int =

let
separators = sepList
printHeader = bool(args["--header"])

if args["--verbose"]:
stderr.writeLine("Separator: ", separators)
Expand All @@ -107,6 +111,9 @@ proc main(): int =
var
okFiles = 0
badFiles = 0

if printHeader:
echo "File\tPassQC\tColumns\tRows\tSeparator"
for file in @(args["<FILE>"]):
var
bestFile: checkResult
Expand All @@ -125,7 +132,7 @@ proc main(): int =
okFiles += 1
else:
badFiles += 1
echo file, "\t", bestFile
echo file, "\t", bestFile.toString(printHeader)
if args["--verbose"]:
stderr.writeLine(okFiles, " valid. ", badFiles, " non-valid files.")

Expand Down
10 changes: 8 additions & 2 deletions test/mini.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"


BINDIR="$DIR/../bin/"
BIN="$BINDIR"/seqfu
FILES="$DIR"/../data/
Expand Down Expand Up @@ -32,7 +31,14 @@ done
# Check version

VERSION=$("$BIN" version)
grep $VERSION $DIR/../seqfu.nimble
if [[ $VERSION == "" ]];
then
echo "Version not found"
ERRORS=$((ERRORS+1))
else
grep $VERSION $DIR/../seqfu.nimble
fi


# Dereiplicate
if [[ $("$BIN" derep "$iAmpli" | grep -c '>') -eq "18664" ]]; then
Expand Down

0 comments on commit a124cf9

Please sign in to comment.