Last active
October 21, 2017 17:51
-
-
Save bsipos/64c1c49ace83c9c2e3833d9dde6e4a0b 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 the standard formatting library: | |
import "fmt" | |
// Import the os library - needed for opening files: | |
import "os" | |
// Import the io library - needed for checking for EOF: | |
import "io" | |
//Import the necessary biogo fastq input/output library: | |
import ( | |
"github.com/biogo/biogo/alphabet" | |
"github.com/biogo/biogo/io/seqio/fastq" | |
"github.com/biogo/biogo/seq/linear" | |
) | |
func main() { | |
// Open the fastq file specified on the command line | |
// for reading: | |
fh, err := os.Open(os.Args[1]) | |
// Check for open errors and abort: | |
if err != nil { | |
panic(err) | |
} | |
// Create a template seuence for the reader: | |
template := linear.NewQSeq("", alphabet.QLetters{}, alphabet.DNA, alphabet.Sanger) | |
// Create a fastq reader: | |
reader := fastq.NewReader(fh, template) | |
for { | |
// Read the next record: | |
seq, err := reader.Read() | |
// Break loop if we reached the end of the file: | |
if err == io.EOF { | |
break | |
} | |
var qtmp float64 | |
// For positions across the sequence: | |
for i := 0; i < seq.Len(); i++ { | |
// Acummulate error probabilities: | |
qtmp += seq.At(i).Q.ProbE() | |
} | |
// Calculate mean error probability: | |
mean_prob := qtmp / float64(seq.Len()) | |
// Calculate mean Q-score: | |
mean_qual := alphabet.Ephred(mean_prob) | |
fmt.Println(seq.CloneAnnotation().ID, "\t", byte(mean_qual)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment