mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-12-08 16:50:27 +00:00
Adds the command obimultiplex
This commit is contained in:
@@ -6,29 +6,10 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obingslibrary"
|
||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiseq"
|
||||
)
|
||||
|
||||
type PrimerPair struct {
|
||||
Forward string
|
||||
Reverse string
|
||||
}
|
||||
|
||||
type TagPair struct {
|
||||
Forward string
|
||||
Reverse string
|
||||
}
|
||||
|
||||
type PCR struct {
|
||||
Experiment string
|
||||
Sample string
|
||||
Partial bool
|
||||
Annotations obiseq.Annotation
|
||||
}
|
||||
|
||||
type PCRs map[TagPair]PCR
|
||||
type NGSFilter map[PrimerPair]PCRs
|
||||
|
||||
func _readLines(reader io.Reader) []string {
|
||||
r := bufio.NewReader(reader)
|
||||
bytes := []byte{}
|
||||
@@ -53,12 +34,15 @@ func _readLines(reader io.Reader) []string {
|
||||
return lines
|
||||
}
|
||||
|
||||
func _parseMainNGSFilterTags(text string) TagPair {
|
||||
func _parseMainNGSFilterTags(text string) obingslibrary.TagPair {
|
||||
|
||||
tags := strings.Split(text, ":")
|
||||
|
||||
if len(tags) == 1 {
|
||||
return TagPair{tags[0], tags[0]}
|
||||
return obingslibrary.TagPair{
|
||||
Forward: tags[0],
|
||||
Reverse: tags[0],
|
||||
}
|
||||
}
|
||||
|
||||
if tags[0] == "-" {
|
||||
@@ -69,28 +53,34 @@ func _parseMainNGSFilterTags(text string) TagPair {
|
||||
tags[1] = ""
|
||||
}
|
||||
|
||||
return TagPair{tags[0], tags[1]}
|
||||
return obingslibrary.TagPair{
|
||||
Forward: tags[0],
|
||||
Reverse: tags[1],
|
||||
}
|
||||
}
|
||||
|
||||
func _parseMainNGSFilter(text string) (PrimerPair, TagPair, string, string, bool) {
|
||||
func _parseMainNGSFilter(text string) (obingslibrary.PrimerPair, obingslibrary.TagPair, string, string, bool) {
|
||||
fields := strings.Fields(text)
|
||||
|
||||
tags := _parseMainNGSFilterTags(fields[2])
|
||||
partial := fields[5] == "T" || fields[5] == "t"
|
||||
|
||||
return PrimerPair{fields[3], fields[4]},
|
||||
return obingslibrary.PrimerPair{
|
||||
Forward: fields[3],
|
||||
Reverse: fields[4],
|
||||
},
|
||||
tags,
|
||||
fields[0],
|
||||
fields[1],
|
||||
partial
|
||||
}
|
||||
|
||||
func ReadNGSFilter(reader io.Reader) (NGSFilter, error) {
|
||||
ngsfilter := make(NGSFilter, 10)
|
||||
func ReadNGSFilter(reader io.Reader) (obingslibrary.NGSLibrary, error) {
|
||||
ngsfilter := obingslibrary.MakeNGSLibrary()
|
||||
|
||||
lines := _readLines(reader)
|
||||
|
||||
for _, line := range lines {
|
||||
for i, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
|
||||
if strings.HasPrefix(line, "#") || len(line) == 0 {
|
||||
@@ -100,33 +90,25 @@ func ReadNGSFilter(reader io.Reader) (NGSFilter, error) {
|
||||
split := strings.SplitN(line, "@", 2)
|
||||
|
||||
primers, tags, experiment, sample, partial := _parseMainNGSFilter(split[0])
|
||||
newPCR := PCR{
|
||||
Experiment: experiment,
|
||||
Sample: sample,
|
||||
Partial: partial,
|
||||
Annotations: nil,
|
||||
}
|
||||
|
||||
if len(split) > 1 && len(split[1]) > 0 {
|
||||
newPCR.Annotations = obiseq.GetAnnotation()
|
||||
ParseOBIFeatures(split[1], newPCR.Annotations)
|
||||
}
|
||||
|
||||
samples, ok := ngsfilter[primers]
|
||||
marker, _ := ngsfilter.GetMarker(primers.Forward, primers.Reverse)
|
||||
pcr, ok := marker.GetPCR(tags.Forward, tags.Reverse)
|
||||
|
||||
if ok {
|
||||
pcr, ok := samples[tags]
|
||||
|
||||
if ok {
|
||||
return nil, fmt.Errorf("pair of tags %v used for samples %s in %s and %s in %s",
|
||||
tags, sample, experiment, pcr.Sample, pcr.Experiment)
|
||||
}
|
||||
|
||||
samples[tags] = newPCR
|
||||
} else {
|
||||
ngsfilter[primers] = make(PCRs, 1000)
|
||||
ngsfilter[primers][tags] = newPCR
|
||||
return ngsfilter,
|
||||
fmt.Errorf("line %d : tag pair (%s,%s) used more than once with marker (%s,%s)",
|
||||
i, tags.Forward, tags.Reverse, primers.Forward, primers.Reverse)
|
||||
}
|
||||
|
||||
pcr.Experiment = experiment
|
||||
pcr.Sample = sample
|
||||
pcr.Partial = partial
|
||||
|
||||
if len(split) > 1 && len(split[1]) > 0 {
|
||||
pcr.Annotations = make(obiseq.Annotation)
|
||||
ParseOBIFeatures(split[1], pcr.Annotations)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ngsfilter, nil
|
||||
|
||||
Reference in New Issue
Block a user