コード例 #1
0
def main(args):
    # Set revcomp parameter.
    if args.r != 1:
        args.r = False
    elif args.r == 1 and args.alphabet != 'DNA':
        print("Error, the -r parameter can only be used in DNA.")
    elif args.r == 1 and args.alphabet == 'DNA':
        args.r = True

    # Set alphabet parameter.
    if args.alphabet == 'DNA':
        args.alphabet = index_list.DNA
    elif args.alphabet == 'RNA':
        args.alphabet = index_list.RNA
    elif args.alphabet == 'Protein':
        args.alphabet = index_list.PROTEIN

    res = make_kmer_vector(k=args.k, alphabet=args.alphabet, filename=args.inputfile, revcomp=args.r)

    # Write correspond res file.
    if args.f == 'svm':
        from util import write_libsvm
        write_libsvm(res, [args.l] * len(res), args.outputfile)
    elif args.f == 'tab':
        from util import write_tab
        write_tab(res, args.outputfile)
    elif args.f == 'csv':
        from util import write_csv
        write_csv(res, args.outputfile)
コード例 #2
0
def main(args):
    # Set revcomp parameter.
    if args.r != 1:
        args.r = False
    elif args.r == 1 and args.alphabet != 'DNA':
        print("Error, the -r parameter can only be used in DNA.")
    elif args.r == 1 and args.alphabet == 'DNA':
        args.r = True

    # Set alphabet parameter.
    if args.alphabet == 'DNA':
        args.alphabet = index_list.DNA
    elif args.alphabet == 'RNA':
        args.alphabet = index_list.RNA
    elif args.alphabet == 'Protein':
        args.alphabet = index_list.PROTEIN

    res = make_kmer_vector(k=args.k, alphabet=args.alphabet, filename=args.inputfile, revcomp=args.r)

    # Write correspond res file.
    if args.f == 'svm':
        from util import write_libsvm
        write_libsvm(res, [args.l] * len(res), args.outputfile)
    elif args.f == 'tab':
        from util import write_tab
        write_tab(res, args.outputfile)
    elif args.f == 'csv':
        from util import write_csv
        write_csv(res, args.outputfile)
コード例 #3
0
ファイル: sc.py プロジェクト: lihaicheng7003/Pse-in-One-2.0
def main(args):
    #TODO:args.method will be finished
    #TODO:args.inputfile, name

    if args.alphabet == "RNA":

        if args.method.upper() == 'TRIPLET':
            res = get_triplet_matrix(args.inputfile)
        elif args.method.upper() == 'PSESSC':
            if args.k is None:
                print "parameters k is required. The default value of k is 2."
                args.k = 2
            if args.r is None:
                print "parameters r is required. The default value of r is 2."
                args.r = 2
            if args.w is None:
                print "parameters w is required. The default value of w is 0.1."
                args.w = 0.1
            res = get_psessc_matrix(args.inputfile, args.k, args.r, args.w)
        elif args.method.upper() == 'PSEDPC':
            if args.n is None:
                print "parameters n is required. The default value of d is 0."
                args.n = 0
            if args.r is None:
                print "parameters r is required. The default value of r is 2."
                args.r = 2
            if args.w is None:
                print "parameters w is required. The default value of w is 0.1."
                args.w = 0.1
            res = get_psedpc_matrix(args.inputfile, args.n, args.r, args.w)
        else:
            print("Method error!")
    else:
        print("sequence type error!")
    # Write correspond res file.

    if args.f == 'tab':
        from util import write_tab

        write_tab(res, args.outputfile)
    elif args.f == 'svm':
        if args.multi == 0 and args.l is None:
            args.l = '+1'
        elif args.multi == 0 and (args.l != '+1' and args.l != '-1'):
            print "For binary classification, the label should be either '+1' or '-1'."
            return False
        elif args.multi == 1 and args.l is None:
            args.l = '0'
        elif args.multi == 1 and args.l is not None:
            try:
                label = int(args.l)
            except ValueError:
                print 'The labels should be integer.'
                return False
        from util import write_libsvm
        write_libsvm(res, [args.l] * len(res), args.outputfile)
    elif args.f == 'csv':
        from util import write_csv
        write_csv(res, args.outputfile)
コード例 #4
0
ファイル: acc.py プロジェクト: zaheerkhancs/pDHS-SVM
def main(args):
    with open(args.inputfile) as f:
        k = read_k(args.alphabet, args.method, 0)

        # Get index_list.
        if args.i is not None:
            from pse import read_index
            ind_list = read_index(args.i)
        else:
            ind_list = []

        default_e = []
        # Set Pse default index_list.
        if args.alphabet == 'DNA':
            args.alphabet = index_list.DNA
            if k == 2:
                default_e = const.DI_INDS_6_DNA
            elif k == 3:
                default_e = const.TRI_INDS_DNA
        elif args.alphabet == 'RNA':
            args.alphabet = index_list.RNA
            default_e = const.DI_INDS_RNA
        elif args.alphabet == 'Protein':
            args.alphabet = index_list.PROTEIN
            default_e = const.INDS_3_PROTEIN

        theta_type = 1
        if args.method in const.METHODS_AC:
            theta_type = 1
        elif args.method in const.METHODS_CC:
            theta_type = 2
        elif args.method in const.METHODS_ACC:
            theta_type = 3
        else:
            print("Method error!")

        # ACC.
        if args.e is None and len(ind_list) == 0 and args.a is False:
            # Default Pse.
            res = acc(f, k, args.lag, default_e, args.alphabet,
                      extra_index_file=args.e, all_prop=args.a, theta_type=theta_type)
        else:
            res = acc(f, k, args.lag, ind_list, args.alphabet,
                      extra_index_file=args.e, all_prop=args.a, theta_type=theta_type)

    # Write correspond res file.
    if args.f == 'tab':
        from util import write_tab
        write_tab(res, args.outputfile)
    elif args.f == 'svm':
        from util import write_libsvm
        write_libsvm(res, [args.l] * len(res), args.outputfile)
    elif args.f == 'csv':
        from util import write_csv
        write_csv(res, args.outputfile)
コード例 #5
0
ファイル: sc.py プロジェクト: nackel/Pse-in-One
def main(args):
    #TODO:args.method will be finished
    #TODO:args.inputfile, name 
    
    
    
    if args.alphabet == "RNA":
        
        if args.method.upper() == 'TRIPLET':
            res = get_triplet_matrix(args.inputfile)
        elif args.method.upper() == 'PSESSC':
            if args.k is None:
                print "parameters k is required. The default value of k is 2."
                args.k = 2
            if args.r is None:
                print "parameters r is required. The default value of r is 2."
                args.r = 2
            if args.w is None:
                print "parameters w is required. The default value of w is 0.1."
                args.w = 0.1
            res = get_psessc_matrix(args.inputfile, args.k, args.r, args.w)
        elif args.method.upper() == 'PSEDPC':
            if args.n is None:
                print "parameters n is required. The default value of d is 0."
                args.n = 0
            if args.r is None:
                print "parameters r is required. The default value of r is 2."
                args.r = 2
            if args.w is None:
                print "parameters w is required. The default value of w is 0.1."
                args.w = 0.1
            res = get_psedpc_matrix(args.inputfile, args.n, args.r, args.w)
        else:
            print("Method error!")
    else:
        print("sequence type error!")
     # Write correspond res file.
    
    if args.f == 'tab':
        from util import write_tab

        write_tab(res, args.outputfile)
    elif args.f == 'svm':
        from util import write_libsvm
        write_libsvm(res, [args.l] * len(res), args.outputfile)
    elif args.f == 'csv':
        from util import write_csv
        write_csv(res, args.outputfile)  
コード例 #6
0
def main(args):
    with open(args.inputfile) as f:
        # Get index_list.
        if args.i is not None:
            ind_list = read_index(args.i)
        else:
            ind_list = []

        default_e = []
        # Set Pse default index_list.
        if args.alphabet == 'DNA':
            args.alphabet = index_list.DNA
            if args.k == 2:
                default_e = const.DI_INDS_6_DNA
            elif args.k == 3:
                default_e = const.TRI_INDS_DNA
        elif args.alphabet == 'RNA':
            args.alphabet = index_list.RNA
            default_e = const.DI_INDS_RNA
        elif args.alphabet == 'Protein':
            args.alphabet = index_list.PROTEIN
            default_e = const.INDS_3_PROTEIN

        theta_type = 1
        if args.method in const.THETA_1_METHODS:
            theta_type = 1
        elif args.method in const.THETA_2_METHODS:
            theta_type = 2
        elif args.method == 'PseKNC':
            theta_type = 3
        else:
            print("Method error!")

        # PseKNC.
        if args.method != 'PseKNC':
            if args.e is None and len(ind_list) == 0 and args.a is False:
                # Default Pse.
                res = pseknc(f, args.k, args.w, args.lamada, default_e, args.alphabet,
                             extra_index_file=args.e, all_prop=args.a, theta_type=theta_type)
            else:
                res = pseknc(f, args.k, args.w, args.lamada, ind_list, args.alphabet,
                             extra_index_file=args.e, all_prop=args.a, theta_type=theta_type)
        # iPseKNC.
        else:
            if args.e is None and len(ind_list) == 0 and args.a is False:
                # Default iPse.
                res = ipseknc(f, args.k, args.w, args.lamada, const.DI_INDS_6_DNA, args.alphabet,
                              extra_index_file=args.e, all_prop=args.a)
            else:
                res = ipseknc(f, args.k, args.w, args.lamada, ind_list, args.alphabet,
                              extra_index_file=args.e, all_prop=args.a)

    # Write correspond res file.
    if args.f == 'tab':
        from util import write_tab

        write_tab(res, args.outputfile)
    elif args.f == 'svm':
        from util import write_libsvm

        write_libsvm(res, [args.l] * len(res), args.outputfile)
    elif args.f == 'csv':
        from util import write_csv

        write_csv(res, args.outputfile)
コード例 #7
0
ファイル: nac.py プロジェクト: lihaicheng7003/Pse-in-One-2.0
def main(args):
    # Set revcomp parameter.
    if args.r != 1:
        args.r = False
    elif args.r == 1 and args.alphabet != 'DNA':
        print("Error, the -r parameter can only be used in DNA.")
    elif args.r == 1 and args.alphabet == 'DNA':
        args.r = True

    # Set alphabet parameter.
    if args.alphabet == 'DNA':
        args.alphabet = index_list.DNA
    elif args.alphabet == 'RNA':
        args.alphabet = index_list.RNA
    elif args.alphabet == 'Protein':
        args.alphabet = index_list.PROTEIN

    if args.method.upper() == 'KMER':
        if args.k is None:
            print "parameters k is required. The default value of k is 2."
            args.k = 2
        if args.r is None:
            print "parameters r is required. The default value of r is 0."
            args.r = 0
        res = make_kmer_vector(k=args.k, alphabet=args.alphabet, filename=args.inputfile, revcomp=args.r)
    elif args.method.upper() == 'IDKMER':
        if args.k is None:
            print "parameters k is required. The default value of k is 6."
            args.k = 6
        if args.ps is None or args.ns is None:
            print 'The positive  and the negative source files are required.'
            return False
        res = idkmer(k=args.k, filename=args.inputfile, pos_src_name=args.ps, neg_src_name=args.ns)
    elif args.method.upper() == "MISMATCH":
        if args.k is None:
            print "parameters k is required. The default value of k is 3."
            args.k = 3
        if args.m is None:
            print "parameters m is required. The default value of m is 1."
            args.m = 1
        if args.m >= args.k:
            print "parameters m should be less than parameter k."
        else:
            res = getMismatchProfileMatrix(args.inputfile, args.alphabet, args.k, args.m)
    elif args.method.upper() == "SUBSEQUENCE":
        if args.delta is None:
            print "parameters delta is required. The default value of delta is 1."
            args.delta = 1
        elif args.delta > 1 or args.delta < 0:
            print "delta should be greater than or equal to 0 and less than or equal to 1."
        if args.k is None:
            print "parameters k is required. The default value of k is 3."
            args.k = 3
        res = getSubsequenceProfileByParallel(filename=args.inputfile, alphabet=args.alphabet, k=args.k, delta=args.delta)
    elif args.method.upper() == 'DR':
        if args.alphabet != index_list.PROTEIN:
            print 'DR method is only available for Protein.'
            return False
        elif args.max_dis < 0 or args.max_dis > 10:
            print 'The max distance can not be negative integer and should be smaller than 11.'
            return False
        else:
            res = dr_method(inputfile=args.inputfile, max_dis=args.max_dis)
            print res
    elif args.method.upper() == 'DP':
        if args.alphabet != index_list.PROTEIN:
            print 'Distance Pair method is only available for Protein.'
            return False
        elif args.max_dis < 0 or args.max_dis > 10:
            print 'The max distance can not be negative integer and should be smaller than 11.'
            return False
        else:
            if args.cp == 'cp_13':
                reduce_alphabet_scheme = const.cp_13
            elif args.cp == 'cp_14':
                reduce_alphabet_scheme = const.cp_14
            elif args.cp == 'cp_19':
                reduce_alphabet_scheme = const.cp_19
            elif args.cp == 'cp_20':
                reduce_alphabet_scheme = const.cp_20
            res = get_pseaacdis_matrix(filename=args.inputfile, reduce_alphabet_scheme=reduce_alphabet_scheme, 
                max_distance=args.max_dis, alphabet=args.alphabet)

    else:
        print("Method error!")

    # Write correspond res file.
    if args.f == 'svm':
        if args.multi == 0 and args.l is None:
            args.l = '+1'
        elif args.multi == 0 and (args.l != '+1' and args.l != '-1'):
            print "For binary classification, the label should be either '+1' or '-1'."
            return False
        elif args.multi == 1 and args.l is None:
            args.l = '0'
        elif args.multi == 1 and args.l is not None:
            try:
                label = int(args.l)
            except ValueError:
                print 'The labels should be integer.'
                return False
        from util import write_libsvm
        write_libsvm(res, [args.l] * len(res), args.outputfile)
    elif args.f == 'tab':
        from util import write_tab
        write_tab(res, args.outputfile)
    elif args.f == 'csv':
        from util import write_csv
        write_csv(res, args.outputfile)
コード例 #8
0
def main(args):
    with open(args.inputfile) as f:
        k = read_k(args.alphabet, args.method, 0)

        # Get index_list.
        if args.i is not None:
            from pse import read_index

            ind_list = read_index(args.i)
        else:
            ind_list = []

        default_e = []
        # Set Pse default index_list.
        if args.alphabet == "DNA":
            args.alphabet = index_list.DNA
            if k == 2:
                default_e = const.DI_INDS_6_DNA
            elif k == 3:
                default_e = const.TRI_INDS_DNA
        elif args.alphabet == "RNA":
            args.alphabet = index_list.RNA
            default_e = const.DI_INDS_RNA
        elif args.alphabet == "Protein":
            args.alphabet = index_list.PROTEIN
            default_e = const.INDS_3_PROTEIN

        theta_type = 1
        if args.method in const.METHODS_AC:
            theta_type = 1
        elif args.method in const.METHODS_CC:
            theta_type = 2
        elif args.method in const.METHODS_ACC:
            theta_type = 3
        else:
            print("Method error!")

        # ACC.
        if args.e is None and len(ind_list) == 0 and args.a is False:
            # Default Pse.
            res = acc(
                f,
                k,
                args.lag,
                default_e,
                args.alphabet,
                extra_index_file=args.e,
                all_prop=args.a,
                theta_type=theta_type,
            )
        else:
            res = acc(
                f, k, args.lag, ind_list, args.alphabet, extra_index_file=args.e, all_prop=args.a, theta_type=theta_type
            )

    # Write correspond res file.
    if args.f == "tab":
        from util import write_tab

        write_tab(res, args.outputfile)
    elif args.f == "svm":
        from util import write_libsvm

        write_libsvm(res, [args.l] * len(res), args.outputfile)
    elif args.f == "csv":
        from util import write_csv

        write_csv(res, args.outputfile)
コード例 #9
0
def main(args):
    with open(args.inputfile) as f:
        if args.method.upper() not in ['MAC', 'GAC', 'NMBAC']:
            k = read_k(args.alphabet, args.method, 0)

            # Get index_list.
            if args.i is not None:
                from .pse import read_index
                ind_list = read_index(args.i)
            else:
                ind_list = []

            default_e = []
            # Set Pse default index_list.
            if args.alphabet == 'DNA':
                args.alphabet = index_list.DNA
                if k == 2:
                    default_e = const.DI_INDS_6_DNA
                elif k == 3:
                    default_e = const.TRI_INDS_DNA
            elif args.alphabet == 'RNA':
                args.alphabet = index_list.RNA
                default_e = const.DI_INDS_RNA
            elif args.alphabet == 'Protein':
                args.alphabet = index_list.PROTEIN
                default_e = const.INDS_3_PROTEIN

            theta_type = 1
            if args.method in const.METHODS_AC:
                theta_type = 1
            elif args.method in const.METHODS_CC:
                theta_type = 2
            elif args.method in const.METHODS_ACC:
                theta_type = 3
            else:
                print("Method error!")

        # ACC.

            if args.e is None and len(ind_list) == 0 and args.a is False:
                # Default Pse.
                res = acc(f,
                          k,
                          args.lag,
                          default_e,
                          args.alphabet,
                          extra_index_file=args.e,
                          all_prop=args.a,
                          theta_type=theta_type)
            else:
                res = acc(f,
                          k,
                          args.lag,
                          ind_list,
                          args.alphabet,
                          extra_index_file=args.e,
                          all_prop=args.a,
                          theta_type=theta_type)

    if args.method.upper() in ['MAC', 'GAC', 'NMBAC']:
        if args.lamada < 0 or args.lamada > 10:
            print(
                'The value of lamada should be larger than 0 and smaller than 10.'
            )
            return False
        if args.a is None:
            args.a == False
        elif args.alphabet == 'DNA':
            args.alphabet = index_list.DNA
            if args.oli == 0:
                if args.a == True:
                    res = autocorrelation(autoc=args.method,
                                          inputfile=args.inputfile,
                                          props=const.ALL_DI_DNA_IND,
                                          k=2,
                                          l=args.lamada,
                                          alphabet=args.alphabet)
                elif args.a == False:
                    res = autocorrelation(autoc=args.method,
                                          inputfile=args.inputfile,
                                          props=const.DEFAULT_DI_DNA_IND,
                                          k=2,
                                          l=args.lamada,
                                          alphabet=args.alphabet)
            if args.oli == 1:
                if args.a == True:
                    res = autocorrelation(autoc=args.method,
                                          inputfile=args.inputfile,
                                          props=const.ALL_TRI_DNA_IND,
                                          k=3,
                                          l=args.lamada,
                                          alphabet=args.alphabet)
                elif args.a == False:
                    res = autocorrelation(autoc=args.method,
                                          inputfile=args.inputfile,
                                          props=const.DEFAULT_TRI_DNA_IND,
                                          k=3,
                                          l=args.lamada,
                                          alphabet=args.alphabet)
        elif args.alphabet == 'RNA':
            args.alphabet = index_list.RNA
            if args.a == True:
                res = autocorrelation(autoc=args.method,
                                      inputfile=args.inputfile,
                                      props=const.ALL_RNA_IND,
                                      k=2,
                                      l=args.lamada,
                                      alphabet=args.alphabet)
            elif args.a == False:
                res = autocorrelation(autoc=args.method,
                                      inputfile=args.inputfile,
                                      props=const.DEFAULT_RNA_IND,
                                      k=2,
                                      l=args.lamada,
                                      alphabet=args.alphabet)
        #print res

    # Write correspond res file.
    if args.f == 'tab':
        from util import write_tab
        write_tab(res, args.outputfile)
    elif args.f == 'svm':
        if args.multi == 0 and args.l is None:
            args.l = '+1'
        elif args.multi == 0 and (args.l != '+1' and args.l != '-1'):
            print(
                "For binary classification, the label should be either '+1' or '-1'."
            )
            return False
        elif args.multi == 1 and args.l is None:
            args.l = '0'
        elif args.multi == 1 and args.l is not None:
            try:
                label = int(args.l)
            except ValueError:
                print('The labels should be integer.')
                return False
        from util import write_libsvm
        write_libsvm(res, [args.l] * len(res), args.outputfile)
    elif args.f == 'csv':
        from util import write_csv
        write_csv(res, args.outputfile)
コード例 #10
0
def main(args):
    with open(args.inputfile) as f:
        # Get index_list.
        if args.i is not None:
            ind_list = read_index(args.i)
        else:
            ind_list = []

        default_e = []
        # Set Pse default index_list.
        if args.alphabet == 'DNA':
            args.alphabet = index_list.DNA
            if args.k == 2:
                default_e = const.DI_INDS_6_DNA
            elif args.k == 3:
                default_e = const.TRI_INDS_DNA
        elif args.alphabet == 'RNA':
            args.alphabet = index_list.RNA
            default_e = const.DI_INDS_RNA
        elif args.alphabet == 'Protein':
            args.alphabet = index_list.PROTEIN
            default_e = const.INDS_3_PROTEIN

        theta_type = 1
        if args.method in const.THETA_1_METHODS:
            theta_type = 1
        elif args.method in const.THETA_2_METHODS:
            theta_type = 2
        elif args.method == 'PseKNC':
            theta_type = 3
        else:
            print("Method error!")

        # PseKNC.
        if args.method != 'PseKNC':
            if args.e is None and len(ind_list) == 0 and args.a is False:
                # Default Pse.
                res = pseknc(f,
                             args.k,
                             args.w,
                             args.lamada,
                             default_e,
                             args.alphabet,
                             extra_index_file=args.e,
                             all_prop=args.a,
                             theta_type=theta_type)
            else:
                res = pseknc(f,
                             args.k,
                             args.w,
                             args.lamada,
                             ind_list,
                             args.alphabet,
                             extra_index_file=args.e,
                             all_prop=args.a,
                             theta_type=theta_type)
        # iPseKNC.
        else:
            if args.e is None and len(ind_list) == 0 and args.a is False:
                # Default iPse.
                res = ipseknc(f,
                              args.k,
                              args.w,
                              args.lamada,
                              const.DI_INDS_6_DNA,
                              args.alphabet,
                              extra_index_file=args.e,
                              all_prop=args.a)
            else:
                res = ipseknc(f,
                              args.k,
                              args.w,
                              args.lamada,
                              ind_list,
                              args.alphabet,
                              extra_index_file=args.e,
                              all_prop=args.a)

    # Write correspond res file.
    if args.f == 'tab':
        from util import write_tab

        write_tab(res, args.outputfile)
    elif args.f == 'svm':
        from util import write_libsvm

        write_libsvm(res, [args.l] * len(res), args.outputfile)
    elif args.f == 'csv':
        from util import write_csv

        write_csv(res, args.outputfile)
コード例 #11
0
def main(args):
    with open(args.inputfile) as f:
        # Get index_list.
        if args.i is not None:
            ind_list = read_index(args.i)
        else:
            ind_list = []

        default_e = []
        # Set Pse default index_list.
        if args.alphabet == 'DNA':
            args.alphabet = index_list.DNA
            if args.k == 2:
                default_e = const.DI_INDS_6_DNA
            elif args.k == 3:
                default_e = const.TRI_INDS_DNA
        elif args.alphabet == 'RNA':
            args.alphabet = index_list.RNA
            default_e = const.DI_INDS_RNA
        elif args.alphabet == 'Protein':
            args.alphabet = index_list.PROTEIN
            default_e = const.INDS_3_PROTEIN

        theta_type = 1
        if args.method in const.THETA_1_METHODS:
            theta_type = 1
        elif args.method in const.THETA_2_METHODS:
            theta_type = 2
        elif args.method == 'PseKNC':
            theta_type = 3
        else:
            print("Method error!")

        # PseKNC.
        if args.method != 'PseKNC':
            if args.e is None and len(ind_list) == 0 and args.a is False:
                # Default Pse.
                res = pseknc(f,
                             args.k,
                             args.w,
                             args.lamada,
                             default_e,
                             args.alphabet,
                             extra_index_file=args.e,
                             all_prop=args.a,
                             theta_type=theta_type)
            else:
                res = pseknc(f,
                             args.k,
                             args.w,
                             args.lamada,
                             ind_list,
                             args.alphabet,
                             extra_index_file=args.e,
                             all_prop=args.a,
                             theta_type=theta_type)
        # iPseKNC.
        else:
            if args.e is None and len(ind_list) == 0 and args.a is False:
                # Default iPse.
                res = ipseknc(f,
                              args.k,
                              args.w,
                              args.lamada,
                              const.DI_INDS_6_DNA,
                              args.alphabet,
                              extra_index_file=args.e,
                              all_prop=args.a)
            else:
                res = ipseknc(f,
                              args.k,
                              args.w,
                              args.lamada,
                              ind_list,
                              args.alphabet,
                              extra_index_file=args.e,
                              all_prop=args.a)

    # Write correspond res file.
    if args.f == 'tab':
        from util import write_tab

        write_tab(res, args.outputfile)
    elif args.f == 'svm':
        if args.multi == 0 and args.l is None:
            args.l = '+1'
        elif args.multi == 0 and (args.l != '+1' and args.l != '-1'):
            print "For binary classification, the label should be either '+1' or '-1'."
            return False
        elif args.multi == 1 and args.l is None:
            args.l = '0'
        elif args.multi == 1 and args.l is not None:
            try:
                label = int(args.l)
            except ValueError:
                print 'The labels should be integer.'
                return False
        from util import write_libsvm

        write_libsvm(res, [args.l] * len(res), args.outputfile)
    elif args.f == 'csv':
        from util import write_csv

        write_csv(res, args.outputfile)
コード例 #12
0
ファイル: nac.py プロジェクト: nackel/Pse-in-One
def main(args):
    # Set revcomp parameter.
    if args.r != 1:
        args.r = False
    elif args.r == 1 and args.alphabet != 'DNA':
        print("Error, the -r parameter can only be used in DNA.")
    elif args.r == 1 and args.alphabet == 'DNA':
        args.r = True

    # Set alphabet parameter.
    if args.alphabet == 'DNA':
        args.alphabet = index_list.DNA
    elif args.alphabet == 'RNA':
        args.alphabet = index_list.RNA
    elif args.alphabet == 'Protein':
        args.alphabet = index_list.PROTEIN
        
    if args.method.upper() == 'KMER': 
        if args.k is None:
            print "parameters k is required. The default value of k is 2."
            args.k = 2
        if args.r is None:
            print "parameters r is required. The default value of r is 0."
            args.r = 0
        res = make_kmer_vector(k=args.k, alphabet=args.alphabet, filename=args.inputfile, revcomp=args.r)
    elif args.method.upper() == "MISMATCH":
        if args.k is None:
            print "parameters k is required. The default value of k is 3."
            args.k = 3
        if args.m is None:
            print "parameters m is required. The default value of m is 1."
            args.m = 1
        if args.m >= args.k:
            print "parameters m should be less than parameter k."
        else:
            res = getMismatchProfileMatrix(args.inputfile, args.alphabet, args.k, args.m)
    elif args.method.upper() == "SUBSEQUENCE":
        if args.delta is None:
            print "parameters delta is required. The default value of delta is 1."
            args.delta = 1
        elif args.delta > 1 or args.delta < 0:
            print "delta should be greater than or equal to 0 and less than or equal to 1."
        
        if args.k is None:
            print "parameters k is required. The default value of k is 3."
            args.k = 3 
        res = getSubsequenceProfileByParallel(filename=args.inputfile, alphabet=args.alphabet, k=args.k, delta=args.delta)
            
    else:
            print("Method error!")

    # Write correspond res file.
    if args.f == 'svm':
        from util import write_libsvm
        write_libsvm(res, [args.l] * len(res), args.outputfile)
    elif args.f == 'tab':
        from util import write_tab
        write_tab(res, args.outputfile)
    elif args.f == 'csv':
        from util import write_csv
        write_csv(res, args.outputfile)
コード例 #13
0
ファイル: pDHSSVM.py プロジェクト: zaheerkhancs/pDHS-SVM
def main(args):
	
    names=[]
    with open(args.inputfile) as af:
        seq_list=read_fasta(af)
        for e in seq_list:
            names.append(e.name)
    #kmer.py -f tab -l +1 -r 1 -k ',num2str(k),' TAIR10_DHSs.fas TAIR10_DHSs_reckmer_',num2str(k),'.txt DNA'
    res_kmer = make_kmer_vector(k=2, alphabet=index_list.DNA, filename=args.inputfile, revcomp=True)  
    #acc.py -e user_indices.txt -f svm -l +1 -lag ',num2str(lag),' TAIR10_DHSs.fas TAIR10_DHSs_dac_',num2str(lag),'.txt DNA DAC'
        if args.s==0:
        model_file='pDHSdata_TAIR_model.txt'
        lag=3
    else:
        model_file='pDHSdata_TIGR_model.txt'
        lag=8
    with open(args.inputfile) as f:
        k = read_k('DNA', 'DAC', 0)
        ind_list=[]
        res_acc = acc(f, k, lag, ind_list, index_list.DNA, extra_index_file='user_indices.txt', all_prop=False, theta_type=1)
    # features= revckmer+dac,formed by add each row
    res=[]
    for i in range(len(res_kmer)):
        res.append(res_kmer[i]+res_acc[i])
    featuresfile=args.inputfile+'_tmp_features.txt'
    # Write correspond res file.
    from util import write_libsvm
    write_libsvm(res, ['+1'] * len(res), featuresfile)

    #predict the result
    tmp_predict_result_file=args.inputfile+'_tmp_result.txt'
    if sys.platform == 'win32':
        options='svm-predict -b 1 -q '+featuresfile+' '+model_file+' '+ tmp_predict_result_file
    else:
        options='./svm-predict -b 1 -q '+featuresfile+' '+model_file+' '+ tmp_predict_result_file
    os.system(options)
    pf=open(args.outputfile,'w')
    with open(tmp_predict_result_file) as nf:
            label, TrueProb, FalseProb= '', '',''
            count = 0
            while True:
                line = nf.readline().strip()
                if not line:
                    break
                if count>len(names):
                    break
                if 0==count:
                     pf.write('ID\t\tLabel\t\tProb\n')
                     count+=1
                     continue
                label=int(line.split()[0])
                TrueProb=line.split()[1]
                FalseProb=line.split()[2]
                if label==-1:
                    pf.write(names[count-1]+'\t\t'+'Non DHS'+'\t\t'+str(FalseProb)+'\n')
                else:                
                    pf.write(names[count-1]+'\t\t'+'DHS'+'\t\t'+str(TrueProb)+'\n')
                count+=1
    pf.close()
    cwd = os.getcwd()
    files = [x for x in os.listdir(os.getcwd()) if os.path.isfile(os.path.join(cwd,x))]
    #print files 
    for file in files:
        if -1 != file.find('tmp'):
            os.remove(file)