Skip to content

Commit

Permalink
UCSC TwoBit caching works in main
Browse files Browse the repository at this point in the history
  • Loading branch information
yhoogstrate committed May 7, 2019
1 parent cc92bd6 commit ea4991b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project(fastafs)
# Do this once in a while - find different bugs
#set(CMAKE_CXX_COMPILER "clang++")

set(PROJECT_VERSION "1.1.1")
set(PROJECT_VERSION "1.2.0")
set(PACKAGE_URL "https://github.com/yhoogstrate/fastafs")
set(PACKAGE_BUGREPORT "${PACKAGE_URL}/issues")

Expand Down Expand Up @@ -103,6 +103,7 @@ endif()
add_executable(fastafs
src/main.cpp
src/fasta_to_fastafs.cpp
src/ucsc2bit_to_fastafs.cpp
src/fastafs.cpp
src/twobit_byte.cpp
src/database.cpp
Expand Down
4 changes: 4 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2019-05-07 Youri Hoogstrate

* Full support for UCSC TwoBit files in `fastafs cache` (adding to db)

2019-04-30 Youri Hoogstrate

* Performance update.
Expand Down
2 changes: 2 additions & 0 deletions include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ void sha1_digest_to_hash(unsigned char *, char *);

std::string std_string_nullbyte_safe(char *, size_t, size_t);
std::string std_string_nullbyte_safe(char *, size_t);

bool is_fasta_file(char *filename);
22 changes: 15 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "config.hpp"
#include "fasta_to_fastafs.hpp"
#include "ucsc2bit_to_fastafs.hpp"
#include "database.hpp"
#include "fuse.hpp"

Expand Down Expand Up @@ -61,6 +62,12 @@ void usage_check(void)
std::cout << std::endl;
}

void usage_cache(void)
{
std::cout << "usage: " << PACKAGE << " cache <fastafs-id> <fasta file | ucsc TwoBit file>\n\n";
std::cout << "\n";
}

int main(int argc, char *argv[])
{
if (argc > 1) {
Expand All @@ -80,14 +87,15 @@ int main(int argc, char *argv[])
database d = database();
std::string fname_out = d.add(argv[argc - 2]);

fasta_to_fastafs(argv[argc - 1], fname_out);
//fasta_to_fastafs f = fasta_to_fastafs(std::string(argv[argc - 2]), std::string(argv[argc - 1]));
//f.cache();
//f.write(fname_out);
// @ todo progress bar
if(is_fasta_file(argv[argc - 1])) {
fasta_to_fastafs(argv[argc - 1], fname_out);
} else {
ucsc2bit_to_fastafs(argv[argc - 1], fname_out);
}

} else {
std::cout << "usage: " << PACKAGE << " cache <fastafs-id> <fasta file>\n\n";
std::cout << "\n";
usage_cache();
exit(0);
}
} else if (strcmp(argv[1], "view") == 0) {
uint32_t padding = 60;
Expand Down
19 changes: 19 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,22 @@ std::string std_string_nullbyte_safe(char *ref, size_t len)
return s;
}


bool is_fasta_file(char *filename)
{
char buf[2];
FILE *fp;

if ((fp = fopen(filename, "rb")) == NULL) {
throw std::runtime_error("Could not read first byte of putative FASTA file.");

return false;
}

if (fread(buf, 1, 2, fp) == 2) {
return (buf[0] == '>');// return true if first byte equals >
}

fclose(fp);
}

0 comments on commit ea4991b

Please sign in to comment.