Created
March 29, 2020 12:13
-
-
Save bsipos/e55625a8873d57255748f6edd71608f3 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
// CountFastxRecords counts the number of records in a fastx file. | |
func CountFastxRecords(fh *os.File, buffSize int, format string) int { | |
// Start the timer: | |
start := time.Now() | |
pattern := "+\n" // Pattern to look for. | |
// Create new buffered reader: | |
reader := bufio.NewReaderSize(fh, buffSize) | |
// Variable for counting records: | |
var records int | |
for { | |
// Read next line: | |
line, err := reader.ReadString('\n') | |
// Are we at the end of the file? | |
if err == io.EOF { | |
break | |
} | |
// Anything else went wrong? | |
checkError(err) | |
// Is this a fastq separator line? | |
if line == pattern { | |
records++ | |
} | |
} | |
// Print out the time needed for counting: | |
fmt.Fprintf(os.Stderr, "%d\n", time.Since(start).Microseconds()) | |
// Return the number of records: | |
return records | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment