public static void align(SmithWatermanAlignment swa, Sequence ref, Read read, Sequence bwt, FmIndex fmIndex) {
        Sequence readSeq = read.getReadSeq();
        int readlength = readSeq.length();

        int lowerBound = 0;
        int upperBound = ref.length()-1;
        int savedLowerBound = lowerBound;
        int savedUpperBound = upperBound;

        int k = readlength-1;
        int matched = 0;
        boolean fromStart = true;
        boolean swaAligned = false;
        while(true){
            if(k < 0)
                break;
            int firstMatch = firstMatch(bwt, read.getReadSeq().baseAt(k).toChar(), lowerBound, upperBound);
            int lastMatch = lastMatch(bwt, read.getReadSeq().baseAt(k).toChar(), lowerBound, upperBound);
            k--;
            if(firstMatch == -1 || lastMatch == -1){
                fromStart = false;
                if(matched >= 15){
                    partialSWA(swa, ref, read, fmIndex, savedLowerBound, savedUpperBound);
                    swaAligned = true;
                    break;
                }
                else{
                    if(k >= 15){
                        matched = 0;
                        lowerBound = 0;
                        upperBound = ref.length()-1;
                        continue;
                    }
                    else{
                        break;
                    }
                }
            }
            else{
                matched++;
                savedLowerBound = lowerBound;
                savedUpperBound = upperBound;
                lowerBound = FmBwtHelpers.adjustBound(bwt, fmIndex, firstMatch);
                upperBound = FmBwtHelpers.adjustBound(bwt, fmIndex, lastMatch);
            }
        }

        if(k == -1 && fromStart){
            System.out.println("Read mapped to: "+ fmIndex.pos[lowerBound]);
        }
        else if(swaAligned){
            System.out.println("Aligned using SWA");
        }
        else{
            System.out.println("No Match");
        }
        System.out.println("Read was taken from: " + read.getStartPos());
    }