Skip to content

Commit

Permalink
Add fapack and fapacks (lowercase)
Browse files Browse the repository at this point in the history
  • Loading branch information
jemma-nelson committed Jun 9, 2014
1 parent 3a7dd26 commit 753c8de
Show file tree
Hide file tree
Showing 9 changed files with 5,545 additions and 5,404 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
fastqz
fapack
fapacks
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
default: fastqz
default: fastqz fapack fapacks

fastqz: fastqz15.cpp libzpaq.3.pod libzpaq.cpp libzpaq.h
g++ -O3 -msse2 -s -lpthread fastqz15.cpp libzpaq.cpp -o $@

clean:
- rm -f fastqz fapack fapacks
71 changes: 71 additions & 0 deletions fapack.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* fapack.cpp - pack FASTA 4 bases per byte
Copyright (C) 2012, Matt Mahoney, Dell Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
This program produces packed DNA sequences from FASTA files.
The output may be used as a reference genome for the program fastqz.
To use: fapack output *.fa
where *.fa is a list of FASTA input files. For each file,
input lines starting with ">" are ignored. For all other lines,
the letters A,C,G,T are packed MSB first with A=00,C=01,G=10,T=11.
All other characters are ignored. The last partial byte is discarded.
To compile: g++ -O3 fapack.cpp -o fapack
*/

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {
if (argc<3)
printf("To pack FASTA files: fapack output *.fa\n"), exit(1);
FILE *out=fopen(argv[1], "wb");
int b=1, c;
for (int i=2; i<argc; ++i) {
printf("%s\n", argv[i]);
FILE *in=fopen(argv[i], "rb");
if (!in) continue;
bool dna=true;
while ((c=getc(in))!=EOF) {
if (c=='>') dna=false;
else if (c==10) dna=true;
if (dna) {
if (c=='A') b=b*4;
if (c=='C') b=b*4+1;
if (c=='G') b=b*4+2;
if (c=='T') b=b*4+3;
if (b>=256) putc(b&255, out), b=1;
}
}
if (in) fclose(in);
}
fclose(out);
return 0;
}


65 changes: 65 additions & 0 deletions fapacks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* fapacks.cpp - pack FASTA 4 bases per byte
includes lowercase a,c,g,t
Copyright (C) 2012, Matt Mahoney, Dell Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
This program produces packed DNA sequences from FASTA files.
The output may be used as a reference genome for the program fastqz.
*/

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main(int argc, char** argv) {
if (argc<3)
printf("To pack FASTA files: fapack output *.fa\n"), exit(1);
FILE *out=fopen(argv[1], "wb");
int b=1, c;
for (int i=2; i<argc; ++i) {
printf("%s\n", argv[i]);
FILE *in=fopen(argv[i], "rb");
if (!in) continue;
bool dna=true;
while ((c=getc(in))!=EOF) {
if (c=='>') dna=false;
else if (c==10) dna=true;
if (islower(c)) c=toupper(c);
if (dna) {
if (c=='A') b=b*4;
if (c=='C') b=b*4+1;
if (c=='G') b=b*4+2;
if (c=='T') b=b*4+3;
if (b>=256) putc(b&255, out), b=1;
}
}
if (in) fclose(in);
}
fclose(out);
return 0;
}


Loading

0 comments on commit 753c8de

Please sign in to comment.