Created
May 23, 2013 07:08
-
-
Save Dubhead/5633214 to your computer and use it in GitHub Desktop.
calculating GC content in Dart
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
#!/usr/local/dart/dart-sdk/bin/dart | |
// gc.dart | |
// cf. http://saml.rilspace.org/moar-languagez-gc-content-in-python-d-fpc-c-and-c | |
import 'dart:io'; | |
import 'dart:async'; | |
main() | |
{ | |
int gcCount = 0; | |
int atCount = 0; | |
var f = new File("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa"); | |
var inputStream = f.openRead(); | |
inputStream | |
.transform(new StringDecoder(Encoding.ASCII)) | |
.transform(new LineTransformer()) | |
.listen( | |
(String line) { | |
if (line.startsWith(">")) { | |
return; | |
} | |
int lineLen = line.length; | |
for (var i = 0; i < lineLen; ++i) { // for each char in line | |
switch (line[i]) { | |
case 'G': | |
case 'C': | |
gcCount += 1; | |
break; | |
case 'A': | |
case 'T': | |
atCount += 1; | |
break; | |
} | |
} | |
}, | |
onDone: () { print(gcCount * 100 / (gcCount + atCount)); }, | |
onError: (e) { print(e.toString()); }); | |
} | |
// eof vim:set syntax=dart shiftwidth=2 expandtab: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment