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
65 changes: 65 additions & 0 deletions Makefile.simple
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Simple Makefile for TRF
# No autotools required - just plain gcc

CC = gcc
# Note: -fno-align-loops removed as it's not supported by clang
CFLAGS = -O2 -Wall -fno-align-functions
LDFLAGS = -lm

# Platform detection
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)

ifeq ($(UNAME_S),Linux)
PLATFORM = linux
ifeq ($(UNAME_M),x86_64)
TARGET = linux64
else
TARGET = linux32
endif
endif

ifeq ($(UNAME_S),Darwin)
PLATFORM = mac
TARGET = mac
endif

VERSION = 4.10.0

# Source files
# Note: tr30dat.c is included via trfrun.h, so we only compile trf.c
SRCDIR = src
SOURCES = $(SRCDIR)/trf.c
HEADERS = $(SRCDIR)/tr30dat.h $(SRCDIR)/tr30dat.c $(SRCDIR)/trfrun.h $(SRCDIR)/trfclean.h

# Output binary
BINARY = trf
VERSIONED_BINARY = trf$(VERSION).$(TARGET).exe

# Build target
all: $(BINARY)

$(BINARY): $(SOURCES) $(HEADERS)
@echo "Building TRF for $(PLATFORM) ($(TARGET))..."
$(CC) $(CFLAGS) -DUNIXCONSOLE $(SOURCES) -o $(BINARY) $(LDFLAGS)
@echo "Build complete: $(BINARY)"

# Create versioned binary
versioned: $(BINARY)
cp $(BINARY) $(VERSIONED_BINARY)
@echo "Created versioned binary: $(VERSIONED_BINARY)"

# Install (optional)
install: $(BINARY)
install -m 755 $(BINARY) /usr/local/bin/

# Clean
clean:
rm -f $(BINARY) $(VERSIONED_BINARY)
@echo "Clean complete"

# Test build
test: $(BINARY)
./$(BINARY) -v

.PHONY: all versioned install clean test
70 changes: 41 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,52 +61,58 @@ To obtain current and/or earlier, pre-compiled versions of TRF:

## Instructions for Compiling ##
To compile TRF, you will need a C compiler (e.g., gcc, clang) with the standard library installed.
We have tested compiling and installing TRF under UNIX-based systems (Linux, macOS) and for Windows under Cygwin/MinGW.
We have tested compiling and installing TRF under UNIX-based systems (Linux, macOS including Apple Silicon/ARM) and for Windows under Cygwin/MinGW.

Brief instructions (advanced):
### Simple Build (Recommended) ###

The easiest way to build TRF requires only gcc/clang - no autotools needed:

```bash
# Check actual version
tar xzvf trf-4.10.0.tar.gz
cd trf-4.10.0
mkdir build
cd build
../configure
make
# To install to system
sudo make install
# To copy binary elsewhere
cp src/trf DESTINATION
# Build with the simple script
./build.sh
```

If you are cloning the repository, replace the first two lines above with:
That's it! The binary `trf` is ready to use.

Alternatively, you can use the simple Makefile:

```bash
git clone https://github.com/Benson-Genomics-Lab/TRF.git
cd TRF
make -f Makefile.simple
```

Step by step:
Or compile directly with a single command:

- Open a terminal window and change directory to the TRF directory created by a clone of this repository.
- Create a directory named 'build': `mkdir build` and change directory to that
- Type `../configure` in the terminal.
- Type `make` in the terminal.
- If you wish to install the binary, type `sudo make install` in the terminal. Otherwise, simply copy the binary from the `src` directory under `build`.
This will:
```bash
gcc -O2 -Wall -fno-align-functions -DUNIXCONSOLE src/trf.c -o trf -lm
```

For more details on simplified building, see [BUILD.md](BUILD.md).

### Traditional Build with Autotools ###

- compile the code
- place the executable version in the build/src directory.
If you prefer the traditional autotools build process:

The file will be called `trf` (`trf.exe` on Windows). For backwards compatibility with automated scripts exepcting TRF to follow a certain naming scheme, the installation will also create a symbolic link named `trf<version>.<operating system>.exe`.
```bash
mkdir build
cd build
../configure
make

# To install to system
sudo make install

# Or to copy binary elsewhere
cp src/trf DESTINATION
```

The file will be called `trf` (`trf.exe` on Windows). For backwards compatibility with automated scripts expecting TRF to follow a certain naming scheme, the installation will also create a symbolic link named `trf<version>.<operating system>.exe`.
For example the file on a linux 64 bit operating system for version 4.10.0 will be called `trf4.10.0.linux64.exe`.

## Testing the Installation ##
Run the executable on the included test file `test_seqs.fasta`. (This assumes the executable has been named TRF.):
Run the executable on the included test file `t/test_seqs.fasta`:

```bash
trf test_seqs.fasta 2 5 7 80 10 50 2000 -l 10
./trf t/test_seqs.fasta 2 5 7 80 10 50 2000 -l 10
```
This should produce 9 files:
```bash
Expand Down Expand Up @@ -362,6 +368,12 @@ Tandem Repeats Finder finds repeats for period sizes in the range from 1 to 2000
Some of these changes may be present in 4.09 and were undocumented, if
they were caught during launch. They are officially present in 4.10.0.

**Build improvements:**

* **ARM Mac (Apple Silicon) support:** TRF now compiles and runs natively on ARM-based Macs (M1, M2, M3, etc.)
* **Simplified build process:** New simple build script (`build.sh`) and Makefile (`Makefile.simple`) that require only gcc/clang - no autotools needed. See [BUILD.md](BUILD.md) for details.
* **One-command compilation:** TRF can now be built with a single gcc command for easy integration into containers and build systems.

Major:

* TRF now has an exit status of 0 on success, and non-zero otherwise.
Expand Down
52 changes: 52 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
# Simple build script for TRF - no dependencies required
# Just needs gcc (or clang) and standard C library

set -e # Exit on error

# Detect platform
UNAME_S=$(uname -s)
UNAME_M=$(uname -m)

case "$UNAME_S" in
Linux*)
PLATFORM="linux"
if [ "$UNAME_M" = "x86_64" ]; then
TARGET="linux64"
else
TARGET="linux32"
fi
;;
Darwin*)
PLATFORM="mac"
TARGET="mac"
;;
CYGWIN*|MINGW*)
PLATFORM="windows"
if [ "$UNAME_M" = "x86_64" ]; then
TARGET="dos64"
else
TARGET="dos32"
fi
;;
*)
echo "Unknown platform: $UNAME_S"
exit 1
;;
esac

echo "Building TRF for $PLATFORM ($TARGET)..."

# Compile flags
# Note: -fno-align-loops removed as it's not supported by clang
CFLAGS="-O2 -Wall -fno-align-functions"
LDFLAGS="-lm"

# Use CC environment variable if set, otherwise default to gcc
CC="${CC:-gcc}"

# Build
$CC $CFLAGS -DUNIXCONSOLE src/trf.c -o trf $LDFLAGS

echo "Build complete: ./trf"
echo "Test with: ./trf -v"
2 changes: 1 addition & 1 deletion src/tr30dat.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ License along with TRF. If not, see <https://www.gnu.org/licenses/>.


#define new1Darrayfunc(type,functionname,length)\
type *functionname(int length)\
type *functionname(size_t length)\
{\
type *objptr=calloc(length,sizeof(*objptr));\
if(objptr==NULL)\
Expand Down
40 changes: 20 additions & 20 deletions src/tr30dat.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int counterInSeq = 0;
//#endif
/* 02/05/16 Y. Hernandez */
/* Since this is no longer a macro, use all lower case to avoid confusion. */
unsigned int maxwraplength = 0;
size_t maxwraplength = 0;

/* Added by Yevgeniy Gelfand on Jan 27, 2010 */
/* To have smaller sequences not send results */
Expand Down Expand Up @@ -200,7 +200,7 @@ int *Index;
int *ACGTcount;

unsigned char *Sequence;
int Length;
size_t Length;

/* int S[MAXWRAPLENGTH+1][MAXPATTERNSIZE];*/
int Delta; /* indel penalty */
Expand All @@ -223,10 +223,10 @@ int *Tag; /* list of tags for linking active distances */
int Toptag; /* last tag in list */

struct pairalign {
int length;
int score;
char *textprime, *textsecnd;
int * indexprime, *indexsecnd;
size_t length;
int score;
char *textprime, *textsecnd;
int *indexprime, *indexsecnd;
} AlignPair;

struct cons_data {
Expand All @@ -247,8 +247,8 @@ struct cons_data {
/*** new program started 11-29-95 **********/

struct bestperiodlistelement {
int indexhigh;
int indexlow;
size_t indexhigh;
size_t indexlow;
int best1;
int best2;
int best3;
Expand All @@ -258,14 +258,14 @@ struct bestperiodlistelement {
} Bestperiodlist[1];

struct distanceentry {
int location;
size_t location;
int size;
};

struct distancelist {
int k_run_sums_criteria, waiting_time_criteria, lo_d_range, hi_d_range;
int numentries, nummatches;
int lowindex, highindex;
size_t lowindex, highindex;
int linked;
int linkdown, linkup;
struct distanceentry *entry;
Expand All @@ -279,18 +279,18 @@ struct distancelist {
alignment in the same region with the same distance */

struct distanceseenarrayelement {
int index;
int end;
size_t index;
size_t end;
int score;
} * Distanceseenarray;

struct distancelistelement {
int index;
size_t index;
int distance;
int changed_from_distance; /* use for test in
search_for_distance_match_in_distanceseenlist
3/10/05 */
int end;
size_t end;
int score;
int best_possible_score; /* number of copies X length X match weight */
int accepted;
Expand Down Expand Up @@ -360,7 +360,7 @@ typedef struct {
int redundoff;
int ngs;
int use_stdin;
unsigned int maxwraplength;
size_t maxwraplength;

char inputfilename[_MAX_PATH]; /* constant defined in stdlib */
char outputprefix[_MAX_PATH];
Expand Down Expand Up @@ -491,11 +491,11 @@ int print_flanking = 0;

typedef struct {
/* Changed to unsigned Feb 16, 2016 Yozen */
unsigned int length;
int composition[26];
int nucleotides;
char name[MAXSEQNAMELEN];
char * sequence;
size_t length;
int composition[26];
int nucleotides;
char name[MAXSEQNAMELEN];
char *sequence;

} FASTASEQUENCE;

Expand Down
17 changes: 16 additions & 1 deletion src/trf.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ char* GetNamePartAddress(char* name);
void PrintBanner(void);
static int ParseInt(const char *str, int *dest);
static int ParseUInt(const char *str, unsigned int *dest);
static int ParseSize(const char *str, size_t *dest);

int main(int ac, char** av)
{
Expand Down Expand Up @@ -204,7 +205,7 @@ int main(int ac, char** av)
exit(2);
}

if (ParseUInt(av[8], &paramset.maxwraplength) == 0) {
if (ParseSize(optarg, &paramset.maxwraplength) == 0) {
fprintf(stderr, "Error while parsing max TR length (option '-L') value\n");
PrintBanner();
exit(1);
Expand Down Expand Up @@ -368,6 +369,20 @@ static int ParseUInt(const char *str, unsigned int *dest)
}
}

static int ParseSize(const char *str, size_t *dest)
{
errno = 0;
char *temp;
unsigned long long val = strtoull(str, &temp, 0);

if (temp == str || *temp != '\0' || (val == ULLONG_MAX && errno == ERANGE)) {
return 0;
}

*dest = val;
return 1;
}

void PrintBanner(void)
{
fprintf(stderr,"\nTandem Repeats Finder, Version %s", versionstring);
Expand Down
2 changes: 1 addition & 1 deletion src/trfclean.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ IL* GetList(char * datafile)
for (counter =0; counter<3; counter++) fgets(hparameters, 255, fp);

/* get hlength from another global variable (bad practice)*/
sprintf(hlength, "Length: %d", Length);
sprintf(hlength, "Length: %zu", Length);

/* loop to fill out list from buffer */
counter = 1; /* keeps track of order they are found */
Expand Down
Loading