Skip to content
Open
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
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ clean:
*/gc.bin \
*/gc \
*/gc.o \
cython/gc.c \
cython*/gc.c \
java/gc.class \
nim/nimcache \
rust*/target \
Expand Down Expand Up @@ -72,6 +72,7 @@ report.md: ada.time ada.version \
crystal.001.csp.time crystal.version \
crystal.002.peek.time crystal.version \
cython.time cython.version \
cython.001.fopen.time cython.version \
d.time d.version \
fpc.time fpc.version \
go.time go.version \
Expand All @@ -85,7 +86,9 @@ report.md: ada.time ada.version \
node.time node.version \
perl.time perl.version \
pypy.time pypy.version \
pypy.001.binary.time pypy.version \
python.time python.version \
python.001.binary.time python.version \
rust.time rust.version \
rust.001.time rust.version \
rust.002.bitshift.time rust.version \
Expand Down Expand Up @@ -186,6 +189,10 @@ cython/gc.bin: cython/gc.pyx
cython --embed $< \
&& gcc -I/usr/include/python2.7 -O3 -o $@ cython/gc.c -lpython2.7

cython%/gc.bin: cython%/gc.pyx
cython --embed $< \
&& gcc -I/usr/include/python2.7 -O3 -o $@ $(patsubst %.pyx,%.c,$<) -lpython2.7

# D
%.bin: %.d
ldc2 -O5 -boundscheck=off -release -of=$@ $<
Expand Down Expand Up @@ -240,12 +247,18 @@ perl/gc.bin: perl/gc.pl
python/gc.bin: python/gc.py
cp $< $@

python%/gc.bin: python%/gc.py
cp $< $@

# Pypy
# We need to copy the pypy script to the canonical path to simplify the e.g.
# the cleaning rule
pypy/gc.bin: pypy/gc.py
cp $< $@

pypy%/gc.bin: pypy%/gc.py
cp $< $@

# Rust
rust/gc.bin: rust/src/main.rs rust/Cargo.toml
RUSTFLAGS="-C target-cpu=native" cargo +nightly build --release --manifest-path $(word 2,$^) -Z unstable-options --out-dir $(shell dirname $@) \
Expand Down
45 changes: 45 additions & 0 deletions cython.001.fopen/gc.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# cython: boundscheck=False, wraparound=False, initializedcheck=False, cdivision=True

from libc.stdio cimport fopen, fgets, fclose, FILE
from libc.stdint cimport uint64_t


cdef uint64_t value[256];

for i in range(256):
value[i] = 0;
value[ord('A')] = value[ord('T')] = 1;
value[ord('G')] = value[ord('C')] = 1ull << 32;


cpdef void main():
cdef FILE* f
cdef double at
cdef double gc
cdef char line[4096]
cdef uint64_t totals = 0
cdef size_t i = 0

f = fopen("chry_multiplied.fa","r")
if f == NULL:
raise OSError("Can't open input file")

with nogil:

while fgets(line, sizeof(line), f):
if line[0] == '>':
continue
while line[i] != 0:
totals += value[line[i]]
i += 1
i = 0

fclose(f)
at = totals & 0xFFFFFFFFull;
gc = totals >> 32;

print( gc / (at + gc) )


if __name__ == '__main__':
main()
22 changes: 22 additions & 0 deletions pypy.001.binary/gc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env pypy
import string

def main():
file = open("chry_multiplied.fa","rb")
a = 0
t = 0
g = 0
c = 0
for line in file:
if line[0] != b">" and len(line) != line.count(b"N") + 1:
g += line.count(b"G")
c += line.count(b"C")
a += line.count(b"A")
t += line.count(b"T")
totalBaseCount = a + t + c + g
gcCount = g + c
gcFraction = float(gcCount) / totalBaseCount
print( gcFraction * 100 )

if __name__ == '__main__':
main()
25 changes: 25 additions & 0 deletions python.001.binary/gc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python
import string

A,T,G,C,N = map(ord, "ATGCN")

def main():
file = open("chry_multiplied.fa","rb")
a = 0
t = 0
g = 0
c = 0
for line in file:
if line[0] != 62 and len(line) != line.count(N) + 1:
g += line.count(G)
c += line.count(C)
a += line.count(A)
t += line.count(T)
totalBaseCount = a + t + c + g
gcCount = g + c

gcFraction = float(gcCount) / totalBaseCount
print( gcFraction * 100 )

if __name__ == '__main__':
main()