Skip to content

Commit 254fa23

Browse files
authored
1.1.0
* init commit 1.1.0 * steps for standalone get repeats function * An implementation of GetRepeatsForSequence has been added * Includes some lib prep testing, also fixes the exclusion of last nucleotide bug * Prepping update for release. * Prepping update for release. * Prepping update for release. * vhangin ubuntu version in github actions * changing ubuntu version in github actions and did a tool/run-format.sh * Changing how the library is compiled and adding an example of using the library. * Adding back in the examples check to the github actions * Updating run-all examples code * Updating run-all examples code
1 parent d04547b commit 254fa23

28 files changed

+626
-347
lines changed

.github/workflows/build-and-test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [push, pull_request]
44

55
jobs:
66
check-build:
7-
runs-on: ubuntu-20.04
7+
runs-on: ubuntu-latest
88
container:
99
image: traviswheelerlab/ultra-build
1010
volumes:
@@ -14,17 +14,17 @@ jobs:
1414
- run: cmake . && make
1515

1616
check-examples:
17-
runs-on: ubuntu-20.04
17+
runs-on: ubuntu-latest
1818
container:
1919
image: traviswheelerlab/ultra-build
2020
volumes:
2121
- ${{ github.workspace }}:/code
2222
steps:
2323
- uses: actions/checkout@v3
2424
- run: cmake . && make examples
25-
25+
2626
check-format:
27-
runs-on: ubuntu-20.04
27+
runs-on: ubuntu-latest
2828
container:
2929
image: traviswheelerlab/ultra-build
3030
volumes:

CMakeLists.txt

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ project(
44
HOMEPAGE_URL https://github.com/TravisWheelerLab/ULTRA
55
)
66

7+
# By default we do NOT build the standalone ULTRA library
8+
option(BUILD_ULTRA_LIB "Also build ULTRA as a standalone library" OFF)
79

10+
# Default to Release if no build type is set
811
if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
912
message(STATUS "Setting CMAKE_BUILD_TYPE=Release")
1013
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
1114
endif()
1215

13-
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
16+
# Add a debug flag when not in Release
17+
if (NOT CMAKE_BUILD_TYPE STREQUAL "Release")
1418
add_definitions(-DDEBUG_PRAGMA=1)
1519
endif()
1620

1721
set(CMAKE_CXX_STANDARD 11)
1822
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1923

20-
set(
21-
LIB_CPP_FILES
22-
)
23-
set(
24-
HPP_FILES
25-
24+
# Header files (for installation / PUBLIC_HEADER)
25+
set(HPP_FILES
2626
src/FASTAReader.hpp
2727
src/FileReader.hpp
2828
src/SequenceWindow.hpp
@@ -39,10 +39,10 @@ set(
3939
src/RepeatSplitter.hpp
4040
src/cli.hpp
4141
src/mask.hpp
42-
)
43-
set(
44-
CPP_FILES
42+
)
4543

44+
# All source files
45+
set(CPP_FILES
4646
src/FASTAReader.cpp
4747
src/FileReader.cpp
4848
src/SequenceWindow.cpp
@@ -63,21 +63,46 @@ set(
6363

6464
find_package(Threads REQUIRED)
6565

66-
add_executable(
67-
ultra
66+
# LIB_SOURCES = everything except main.cpp
67+
set(LIB_SOURCES ${CPP_FILES})
68+
list(REMOVE_ITEM LIB_SOURCES src/main.cpp)
6869

69-
${LIB_CPP_FILES}
70-
${CPP_FILES}
71-
)
72-
target_link_libraries(ultra PRIVATE Threads::Threads)
70+
# 1) Build static library only if requested
71+
if (BUILD_ULTRA_LIB)
72+
add_library(ultra_core STATIC ${LIB_SOURCES})
73+
target_include_directories(ultra_core
74+
PUBLIC ${CMAKE_SOURCE_DIR}/src
75+
)
76+
target_link_libraries(ultra_core
77+
PUBLIC Threads::Threads
78+
)
79+
80+
install(
81+
TARGETS ultra_core
82+
ARCHIVE DESTINATION lib
83+
PUBLIC_HEADER DESTINATION include
84+
)
85+
endif()
86+
87+
# 2) Build the CLI executable
88+
if (BUILD_ULTRA_LIB)
89+
# Link only main.cpp against ultra_core
90+
add_executable(ultra src/main.cpp)
91+
target_link_libraries(ultra PRIVATE ultra_core)
92+
else()
93+
# Monolithic: compile everything into the exe
94+
add_executable(ultra ${CPP_FILES})
95+
target_link_libraries(ultra PRIVATE Threads::Threads)
96+
endif()
7397

74-
target_include_directories(ultra SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/lib)
98+
target_include_directories(ultra PRIVATE ${CMAKE_SOURCE_DIR}/src)
7599

76-
install(TARGETS ultra RUNTIME)
100+
install(TARGETS ultra RUNTIME DESTINATION bin)
77101

102+
# Optional examples target
78103
add_custom_target(
79104
examples
80-
COMMAND examples/run-all.sh
105+
COMMAND /usr/bin/env sh examples/run-all.sh
81106
VERBATIM
82107
)
83108
add_dependencies(examples ultra)

examples/Makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# examples/Makefile — build the ULTRA example program
2+
3+
# C++ compiler and flags
4+
CXX := g++
5+
CXXFLAGS := -std=c++11 -Wall -I../src
6+
7+
# Path to the ULTRA static library
8+
ULTRA_LIB := ../build/libultra_core.a
9+
10+
# Libraries to link against
11+
LDLIBS := $(ULTRA_LIB) -pthread
12+
13+
# Your example source & target
14+
SRC := library_example.cpp
15+
OBJ := $(SRC:.cpp=.o)
16+
TARGET := library_example
17+
18+
# Default target: build the example executable
19+
all: $(TARGET)
20+
21+
# Link step
22+
$(TARGET): $(OBJ)
23+
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDLIBS)
24+
25+
# Compile step
26+
%.o: %.cpp
27+
$(CXX) $(CXXFLAGS) -c $< -o $@
28+
29+
# Clean up build artifacts
30+
clean:
31+
rm -f $(OBJ) $(TARGET)
32+
33+
.PHONY: all clean

examples/library_example.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//
2+
// Created by Daniel Olson on 5/5/25.
3+
//
4+
#include <cstdio>
5+
#include <ultra.hpp>
6+
#include <cli.hpp>
7+
8+
int main() {
9+
printf("Note that the Makefile is currently linking against ULTRA/build/libultra_core.a\n");
10+
printf(" and is using ULTRA/src/ as the source of ULTRA header files.\n");
11+
printf("The location of the ULTRA lib and header files will need to be adjusted in real use-cases.\n\n\n");
12+
13+
printf("Starting test of library.\n");
14+
15+
16+
// These are the settings we will use with ULTRA
17+
Settings *settings = new Settings();
18+
settings->run_without_reader = true; // This must be set to true when using as lib
19+
settings->window_size = 1000000; // window size should be equal to the largest sequence you will analyze
20+
settings->overlap = 0; // overlap should be turned off
21+
22+
23+
// We can also pass in an argument string to settings like so:
24+
int argc;
25+
char **argv;
26+
std::string arg_string = "-p 25 -i 3 -d 3";
27+
string_to_args(arg_string, argc, argv);
28+
29+
settings->prepare_settings(); // This should be called before running settings->parse_input()
30+
if (!settings->parse_input(argc, (const char**)argv)) {
31+
exit(0);
32+
}
33+
34+
// Finally, we call settings->assign_settings()
35+
settings->assign_settings();
36+
37+
// We create a reusable ULTRA object
38+
auto ultra = new Ultra(settings);
39+
// We can find repeats in a C++ string using "FindRepeatsInString(std::string)"
40+
41+
printf("Finding repeats in string ``aaaaaaaaaaaaaaaaaaaaaaaaaa''\n");
42+
auto repeats = ultra->FindRepeatsInString("aaaaaaaaaaaaaaaaaaaaaaaaaa");
43+
44+
printf("Start Length Pattern\n");
45+
for (int i= 0; i < repeats->size(); ++i) {
46+
auto r = repeats->at(i);
47+
printf("%lu %lu %i %s\n", r->windowStart, r->repeatLength, r->repeatPeriod, r->GetConsensus().c_str());
48+
delete r; // We are in charge of the memory management of the repeats returned by FindRepeatsInString
49+
}
50+
51+
delete repeats; // We are also in charge of the memory for the repeat array itself
52+
printf("---------\n");
53+
54+
55+
printf("Finding repeats in string ``aggtaaggtaaggtaaggtaaggtaagcggtataacatacagatctgactactactactactactactactactac''\n");
56+
repeats = ultra->FindRepeatsInString("aggtaaggtaaggtaaggtaaggtaagcggtataacatacagatctgactactactactactactactactactac");
57+
printf("Start Length Pattern\n");
58+
for (int i= 0; i < repeats->size(); ++i) {
59+
auto r = repeats->at(i);
60+
printf("%lu %lu %i %s\n", r->windowStart, r->repeatLength, r->repeatPeriod, r->GetConsensus().c_str());
61+
delete r;
62+
}
63+
64+
delete repeats;
65+
printf("---------\n");
66+
67+
printf("All positions reported are 0 indexed.\n");
68+
69+
return 0;
70+
}

examples/run-all.sh

100755100644
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ run_one() {
1616

1717
run_one examples/example_1.fa
1818
run_one examples/example_2.fa
19+
run_one examples/example_3.fa

lib/README.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/BEDFileWriter.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
#include "ultra.hpp"
88
#include <algorithm>
99
#include <iostream>
10-
void BEDFileWriter::InitializeWriter(Ultra *ultra, FILE *out_file) { owner = ultra; out=out_file; }
10+
void BEDFileWriter::InitializeWriter(Ultra *ultra, FILE *out_file) {
11+
owner = ultra;
12+
out = out_file;
13+
}
1114

1215
void BEDFileWriter::WriteRepeat(RepeatRegion *repeat) {
1316

@@ -35,7 +38,8 @@ void BEDFileWriter::WriteRepeat(RepeatRegion *repeat) {
3538
// We need to decide what to do with the overall sequence
3639

3740
std::string rep_con = std::to_string(repeat->repeatPeriod);
38-
if (owner->settings->max_consensus_period >= repeat->repeatPeriod && !repeat->string_consensus.empty())
41+
if (owner->settings->max_consensus_period >= repeat->repeatPeriod &&
42+
!repeat->string_consensus.empty())
3943
rep_con = repeat->string_consensus;
4044

4145
fprintf(out, "\t%s\n", rep_con.c_str());
File renamed without changes.

src/FASTAReader.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ bool FASTAReader::ReadWindow(SequenceWindow *window) {
130130
window->PrepareWindow(sequenceName, sequenceID, symbolsReadInSeq,
131131
overlapLength);
132132

133-
134133
if (overlapLength > 0)
135134
window->CopyOverlap(overlapBuffer);
136135

@@ -188,7 +187,6 @@ bool FASTAReader::ReadWindow(SequenceWindow *window) {
188187

189188
window->readID = readID++;
190189

191-
192190
return true;
193191
}
194192

src/FASTAReader.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ class FASTAReader {
4545
double C_pctg;
4646
double G_pctg;
4747

48-
symbol *overlapBuffer; // = NULL;
49-
unsigned long overlapLength = 0; // = 0;
48+
symbol *overlapBuffer; // = NULL;
49+
unsigned long overlapLength = 0; // = 0;
5050

51-
std::string sequenceName = ""; // = "";
51+
std::string sequenceName = ""; // = "";
5252
unsigned long sequenceID = 0; // = 0;
5353
unsigned long readID = 0; // = 0; // read id's may not be contiguous
5454
unsigned long symbolsReadInSeq = 0; // = 0;
5555

56-
bool doneReadingFile; // = false;
56+
bool doneReadingFile; // = false;
5757
bool isReading;
5858

5959
bool CopyOverlapBufferFromWindow(SequenceWindow *window,

0 commit comments

Comments
 (0)