Commit 69a71606 authored by Eric Coissac's avatar Eric Coissac

Adds a reader for ngsfilter files

parent 9f000e03
......@@ -26,8 +26,6 @@ Collate:
'robiobject.R'
'dplyr.R'
'entropie.R'
'robiseq.R'
'fasta.R'
'robicategory.R'
'robiuniqueid.R'
'robisample.R'
......@@ -37,12 +35,15 @@ Collate:
'oligotag.R'
'randseq.R'
'rdna.R'
'robitag.R'
'read_ngsfilter.R'
'robiseq.R'
'read_obifasta.R'
'read_obitab.R'
'robidata.R'
'robimetabar.R'
'robimetabar_xlsx.R'
'robiseq_db.R'
'robitag.R'
'robitaxid.R'
'tags_categories.R'
'taxonomy_default.R'
......
......@@ -204,8 +204,9 @@ export(rainbow_tol)
export(rank.list)
export(rbarcode)
export(read.sequence)
export(read_fasta)
export(read_ncbi_taxdump)
export(read_ngsfilter)
export(read_obifasta)
export(read_obitab)
export(read_obitools_taxonomy)
export(read_robitaxonomy)
......
#' @import readr
#' @import stringr
#' @import dplyr
#' @include robitag.R
#' @include robiuniqueid.R
#'
NULL
#' Reads a ngsfilter file
#'
#' Ngsfilter file are used by the *OBITools* command ngsfilter
#' to demultiplex reads and trim the primers from the raw data.
#' They can contain metadata on the samples.
#'
#' @param filename the name of the ngsfiler file
#'
#' @return a tible
#' @export
#'
#' @examples
read_ngsfilter <- function(filename) {
lines <- read_lines(filename)
lines <- str_split_fixed(lines,pattern = "@",n = 2)
lines[,1] %>%
str_trim() %>%
str_split_fixed(pattern = "[ \t]",n=6) %>%
as_tibble() -> left
colnames(left) <- c("experiment","id","tags",
"forward_primer","reverse_primer",
"full_length")
left %>%
separate(tags,
into = c("forward_tag","reverse_tag"),
sep=":", remove = TRUE, fill = "right") %>%
mutate(id = robiuniqueid(id),
reverse_tag = ifelse(is.na(reverse_tag),forward_tag,reverse_tag),
full_length = parse_logical(full_length)) %>%
mutate(forward_tag = robitag_forward(ifelse(forward_tag=="-",
NA,
forward_tag)),
reverse_tag = robitag_reverse(ifelse(reverse_tag=="-",
NA,
reverse_tag))) -> left
lines[,2] %>%
str_trim() %>%
str_extract_all('[^ ]+ *= *([^;]+|"[^"]+|\'[^\']+)+') %>%
lapply(str_split_fixed,pattern = " *= *",n=2) %>%
lapply(function(x) {v <- x[,2]
names(v) <- x[,1]
v}) %>%
feature_as_matrix() %>%
as_tibble() -> right
bind_cols(left,right)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/read_ngsfilter.R
\name{read_ngsfilter}
\alias{read_ngsfilter}
\title{Reads a ngsfilter file}
\usage{
read_ngsfilter(filename)
}
\arguments{
\item{filename}{the name of the ngsfiler file}
}
\value{
a tible
}
\description{
Ngsfilter file are used by the *OBITools* command ngsfilter
to demultiplex reads and trim the primers from the raw data.
They can contain metadata on the samples.
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment