Last active
January 11, 2018 03:36
-
-
Save JoshGutman/90a001f9f144117d5b37c1e8d4ddd9eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"log" | |
"os" | |
"strings" | |
) | |
type Bounds struct { | |
lower string | |
upper string | |
} | |
func main() { | |
if len(os.Args) != 2 { | |
log.Fatal(" Invalid command-line args. Correct Usage:\n./repeat_formatter /path/to/file > outputfile.txt") | |
} | |
filename := os.Args[1] | |
seqs := getData(filename) | |
outputData(seqs) | |
} | |
func getData(filename string) map[string][]Bounds { | |
file, err := os.Open(filename) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer file.Close() | |
seqs := make(map[string][]Bounds) | |
scanner := bufio.NewScanner(file) | |
currentName := "" | |
for scanner.Scan() { | |
line := scanner.Text() | |
if strings.HasPrefix(line, "@") { | |
fields := strings.Split(line, " ") | |
name := fields[0][1:] | |
seqs[name] = make([]Bounds, 0) | |
currentName = name | |
} else { | |
fields := strings.Split(line, " ") | |
if len(fields) < 2 { | |
continue | |
} | |
seqs[currentName] = append(seqs[currentName], Bounds{fields[0], fields[1]}) | |
} | |
} | |
return seqs | |
} | |
func isBase(str string) bool { | |
bases := []string{"A", "C", "G", "T"} | |
for _, b := range bases { | |
if strings.HasPrefix(str, b) { | |
return false | |
} | |
} | |
return true | |
} | |
func outputData(seqs map[string][]Bounds) { | |
out := "" | |
for key, val := range seqs { | |
for _, b := range val { | |
out += key + "\t" + b.lower + "\t" + b.upper + "\n" | |
} | |
} | |
fmt.Println(out) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment