Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions cmd/multiFaExtract/multiFaExtract.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,35 @@ func multiFaExtract(s Settings) {
var ans []fasta.Fasta
records := fasta.Read(s.InFile)
if s.Bed == "" {
if !(s.Start < s.End) {
log.Fatalf("Invalid arguments, start must be lower than end")
}
ans = extractMultiHelper(records, s.Start, s.End)
if s.RemoveGaps {
ans = fasta.RemoveGaps(ans)
}
ans = extractMultiHelper(records, s.Start, s.End, s.RemoveGaps, false)
fasta.Write(s.OutFile, ans)
} else {
bedChan := bed.GoReadToChan(s.Bed)
for b := range bedChan {
ans = extractMultiHelper(records, b.ChromStart, b.ChromEnd)
if s.RemoveGaps {
ans = fasta.RemoveGaps(ans)
ans = extractMultiHelper(records, b.ChromStart, b.ChromEnd, s.RemoveGaps, b.Strand == bed.Negative)
if b.FieldsInitialized >= 4 {
fasta.Write(fmt.Sprintf("%s.fa", b.Name), ans)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me understand why we would name the output file differently if the fields initialized are less than or equal to 4? I'm assuming it would be to not lose information, but then we do not seem to include the chrom start end anymore?

} else {
fasta.Write(fmt.Sprintf("%s.%d.%d.fa", b.Chrom, b.ChromStart, b.ChromEnd), ans)
}
fasta.Write(fmt.Sprintf("%s.%d.%d.fa", b.Chrom, b.ChromStart, b.ChromEnd), ans)
}
}
}

func extractMultiHelper(records []fasta.Fasta, start int, end int) []fasta.Fasta {
func extractMultiHelper(records []fasta.Fasta, start int, end int, removeGaps bool, revComp bool) []fasta.Fasta {
var ans = make([]fasta.Fasta, len(records))
if !(start < end) {
log.Fatalf("Invalid arguments, start must be lower than end. start=%d end=%d\n", start, end)
}
for i := range records {
ans[i] = fasta.Extract(records[i], fasta.RefPosToAlnPos(records[0], start), fasta.RefPosToAlnPos(records[0], end), records[i].Name)
if revComp {
ans[i] = fasta.Copy(ans[i])
Comment thread
RavenYL marked this conversation as resolved.
fasta.ReverseComplement(ans[i])
}
}
if removeGaps {
ans = fasta.RemoveGaps(ans)
}
return ans
}
Expand Down
9 changes: 9 additions & 0 deletions fasta/modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import (
"strings"
)

// Copy makes a copy of the fasta struct and the associated slice of dna so that
// modifying one will not also modify the other
func Copy(a Fasta) Fasta {
var ans Fasta
ans = Fasta{a.Name, make([]dna.Base, len(a.Seq))}
copy(ans.Seq, a.Seq)
return ans
}

// Remove fasta record with index i from slice of fasta.
func Remove(slice []Fasta, i int) []Fasta {
return append(slice[:i], slice[i+1:]...)
Expand Down