Usage: align <input file> Error in python

Viewed 22

Code implements the dynamic programming solution for global pairwise alignment of two sequences. Trying to perform a semi-global alignment between the SARS-CoV-2 reference genome and the first read in the Nanopore sample. The length of the reference genome is 29903 base pairs and the length of the first Nanopore read is 1246 base pairs. When I run the following code, I get this message in my terminal: enter image description here

import sys
import numpy as np
GAP = -2
MATCH = 5
MISMATCH = -3
MAXLENGTH_A = 29904
MAXLENGTH_B = 1247

# insert sequence files
A = open("SARS-CoV-2 reference genome.txt", "r")
B = open("Nanopore.txt", "r")

def max(A, B, C):
    if (A >= B and A >= C):
        return A
    elif (B >= A and B >= C):
        return B
    else:
        return C
def Tmax(A, B, C):
    if (A > B and A > C):
        return 'D'
    elif (B > A and B > C):
        return 'L'
    else:
        return 'U'
def m(p, q):
    if (p == q):
        return MATCH
    else:
        return MISMATCH
def append(st, c):
    return c + "".join(i for i in st)
if __name__ == "__main__":
    if (len(sys.argv) != 2):
        print("Usage: align <input file>")
        sys.exit()
    if (not os.path.isfile(sys.argv[1])):
        print("input file not found.")
        sys.exit()
    S = np.empty([MAXLENGTH_A, MAXLENGTH_B], dtype = int)
    T = np.empty([MAXLENGTH_A, MAXLENGTH_B], dtype = str)
    with open(sys.argv[1], "r") as file:
        A = str(A.readline())[:-1]
        B = str(B.readline())[:-1]
        print("Sequence A:",A)
        print("Sequence B:",B)
        N = len(A)
        M = len(B)
        S[0][0] = 0
        T[0][0] = 'D'
        for i in range(0, N + 1):
            S[i][0] = GAP * i
            T[i][0] = 'U'
        for i in range(0, M + 1):
            S[0][i] = GAP * i
            T[0][i] = 'L'
        for i in range(1, N + 1):
            for j in range(1, M + 1):
                S[i][j] = max(S[i-1][j-1]+m(A[i-1],B[j-1]),S[i][j-1]+GAP,S[i-1][j]+GAP)
                T[i][j] = Tmax(S[i-1][j-1]+m(A[i-1],B[j-1]),S[i][j-1]+GAP,S[i-1][j]+GAP)
        print("The score of the alignment is :",S[N][M])
        i, j = N, M
        RA = RB = RM = ""
        while (i != 0 or j != 0):
            if (T[i][j]=='D'):
                RA = append(RA,A[i-1])
                RB = append(RB,B[j-1])
                if (A[i-1] == B[j-1]):
                    RM = append(RM,'|')
                else:
                    RM = append(RM,'*')
                i -= 1
                j -= 1
            elif (T[i][j]=='L'):
                RA = append(RA,'-')
                RB = append(RB,B[j-1])
                RM = append(RM,' ')
                j -= 1
            elif (T[i][j]=='U'):
                RA = append(RA,A[i-1])
                RB = append(RB,'-')
                RM = append(RM,' ')
                i -= 1
        print(RA)
        print(RM)
        print(RB)
1 Answers

This has nothing to do with python. The error message comes this line:

if (len(sys.argv) != 2):
    print("Usage: align <input file>")

The code expects to be called with exactly one argument, the input file:

align path/to/input/file

You provided a different number of arguments, probably zero.

Related