Skip to content

Instantly share code, notes, and snippets.

View samuell's full-sized avatar
💻
Hacking away

Samuel Lampa samuell

💻
Hacking away
View GitHub Profile
@samuell
samuell / gc_ds_wholefile_tbl_parallel.c
Created May 10, 2013 17:13
Daniel Spångber's C code, when reading whole file, and using table to count, and parallellizing it with OpenMP. See http://saml.rilspace.org/node/248
#include <stdio.h>
#include <stdlib.h>
#define MAXFLEN 70000000 /* Larger than the file. */
int main()
{
char *m=malloc(MAXFLEN);
char tablegc[256];
char tableat[256];
@samuell
samuell / gc_DanielSpaangberg_Tbl.c
Created May 11, 2013 11:35
Daniel Spångberg's line by line C code with table optimization.
#include <stdio.h>
int main()
{
char buf[1000];
int gc=0;
int total=0;
char tablegc[256]={0,};
char tabletotal[256]={0,};
FILE *f=fopen("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa","r");
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXFLEN 70000000 /* Larger than the file. */
/* Assume that sizeof(short)==2, unaligned reads ok, etc. */
int main()
{
char *m=malloc(MAXFLEN);
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXFLEN 70000000 /* Larger than the file. */
/* Assume that sizeof(short)==2, unaligned reads ok, etc. */
int main()
{
char *m=malloc(MAXFLEN);
import std.stdio;
import std.string;
import std.algorithm;
void main() {
File file = File("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa","r");
int countat[256];
int countgc[256];
countat['A'] = 1;
countat['T'] = 1;
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
package main
import (
"bufio"
"fmt"
"log"
"os"
)
func main() {
@samuell
samuell / read_fanin_as_range.go
Created June 15, 2013 23:49
This code snippet describes how to read a "select statement" based fan-in channel in Go, as a range, without deadlocks or strange race conditions. The key to get this right is to use "ok-variables" from the input channels to see if they are closed, and if so, set the channels to nil. Then, if in the for loop you continue until both inputs are ni…
package main
import "fmt"
import "time"
//import "runtime"
func numberGenerator() <-chan int {
c := make(chan int)
go func() {
for i := 1; i <= 10; i++ {