コード例 #1
0
ファイル: saveAsH5.py プロジェクト: olavenua/do_x3dna
def main():
    parser, args = parseArguments()

    # Total number of base-pair
    firstBP = args.firstBP
    totalBP = None
    if args.totalBP is None:
        showErrorAndExit(parser, "No total number of BP!!!\n")
    else:
        totalBP = args.totalBP

    if args.inputFiles is None:
        showErrorAndExit(parser, "No input file...\n")
    else:
        for f in args.inputFiles:
            if not os.path.isfile(f):
                showErrorAndExit(parser, "File {0} not found...\n".format(f))

    # Determine file-extension type
    outputFileExtension = os.path.splitext(args.outputFile)[1]
    if outputFileExtension not in ['.h5', '.hdf5', '.hdf']:
        showErrorAndExit(parser, "File extension {0} is not recognized as an \
        acceptable HDF5 extension.\n Use '.h5', '.hdf5' \
        or '.hdf'.".format(outputFileExtension))

    # initialize DNA object
    dna = dnaMD.DNA(totalBP, filename=args.outputFile, startBP=firstBP)
    for f in args.inputFiles:
        dnaMD.setParametersFromFile(dna, f)
    del dna
コード例 #2
0
ファイル: vsTime.py プロジェクト: Daleang/do_x3dna
def main():
    parser, args = parseArguments()

    # Input file
    inputFile = None
    if args.inputFile is not None:
        inputFile = args.inputFile.name
        args.inputFile.close()
    else:
        showErrorAndExit(parser, "No Input File!!!\n")

    # Determine file-extension type
    fileType = 'text'
    inputFileExtension = os.path.splitext(inputFile)[1]
    if inputFileExtension in ['.h5', '.hdf5', 'hdf']:
        fileType = 'hdf5'

    # Total number of base-pair
    firstBP = args.firstBP
    totalBP = None
    if args.totalBP is None:
        showErrorAndExit(parser, "No total number of BP!!!\n")
    else:
        totalBP = args.totalBP

    # Check for input parameter
    if args.parameter is None:
        showErrorAndExit(parser, "No Parameter name!!!\n")

    if not ( (args.parameter in dnaMD.basePairTypeParameters) or \
            (args.parameter in dnaMD.baseStepTypeParameters) ):
        parser.print_help()
        print("\n===== ERROR =======")
        print('Unknown parameter name "{0}"!!!\n'.format(args.parameter))
        print("Accepted parameters are as follows:")
        count = 1
        for parameter in dnaMD.basePairTypeParameters:
            print('{0}. "{1}"'.format(count, parameter))
            count += 1
        for parameter in dnaMD.baseStepTypeParameters:
            print('{0}. "{1}"'.format(count, parameter))
            count += 1
        print("\n===================")
        sys.exit(-1)

    # Output file
    if args.outputFile is None:
        showErrorAndExit(parser, "No output File!!!\n")

    paramType = dnaMD.getParameterType(args.parameter)
    toMinusBP = 1
    if paramType == 'bps':
        toMinusBP = 2

    # Determine start and end-bp
    startBP = args.startBP
    endBP = None
    if args.endBP is not None:
        endBP = args.endBP

    # Check consistency of start bp
    if (startBP < firstBP) or (startBP > totalBP + firstBP - toMinusBP):
        msg = 'The requested start bp {0} is out side of {1}-{2} range.'.format(
            startBP, firstBP, totalBP + firstBP - toMinusBP)
        showErrorAndExit(parser, msg)

    # Check consistency of end-bp
    if endBP is not None:
        if startBP > endBP:
            msg = 'The requested end bp {0} is larger than requested start bp {1}!!!'.format(
                endBP, startBP)
            showErrorAndExit(parser, msg)

        if (endBP > totalBP + firstBP - toMinusBP) or (endBP < firstBP):
            msg = 'The requested end bp {0} is out side of {1}-{2} range.'.format(
                endBP, firstBP, totalBP + firstBP - toMinusBP)
            showErrorAndExit(parser, msg)

    # Check if merge is required
    if endBP is None:
        merge = False
    else:
        merge = True

    # Check if merge-method is given
    if merge and args.merge_method is None:
        msg = 'No merging method is provided!!!!'
        showErrorAndExit(parser, msg)

    # Store input file name
    filename = None
    if fileType == 'hdf5':
        filename = inputFile

    if endBP is not None:
        bp = [startBP, endBP]
    else:
        bp = [startBP]

    # initialize DNA object
    dna = dnaMD.DNA(totalBP, filename=filename, startBP=firstBP)

    # Check if mask is in object
    if dna.mask is not None:
        masked = True
    else:
        masked = False

    # Directly read the data from text file
    if fileType == 'text':
        # No support for smoothed axis, curvature and tangent
        if args.parameter in [
                'helical x-axis smooth', 'helical y-axis smooth',
                'helical z-axis smooth', 'helical axis curvature',
                'helical axis tangent'
        ]:
            print("\n===== ERROR =======")
            print(
                'Extraction of parameter "{0}" is only supported via input HDF5 file.'
                .format(args.parameter))
            print("\n===== ERROR =======")
            sys.exit(-1)

        # Read and load parameter from file
        dnaMD.setParametersFromFile(dna, inputFile, args.parameter, bp=bp)

    # Extract the input parameter for input DNA/RNA segment
    time, value = dna.time_vs_parameter(args.parameter,
                                        bp,
                                        merge=merge,
                                        merge_method=args.merge_method,
                                        masked=masked)

    # Write the extracted data in a text file
    fout = open(args.outputFile, 'w')
    fout.write('# Time \t "{0}"\n'.format(args.parameter))
    for i in range(len(time)):
        fout.write("{0}\t{1}\n".format(time[i], value[i]))
    fout.close()
コード例 #3
0
ファイル: localDeformation.py プロジェクト: rjdkmr/do_x3dna
def main():
    parser, args = parseArguments()

    # Input file
    probeInputFile = None
    if args.probeInputFile is not None:
        probeInputFile = args.probeInputFile.name
        args.probeInputFile.close()
    else:
        showErrorAndExit(parser, "No Probe DNA Input File!!!\n")
    refInputFile = None
    if args.refInputFile is not None:
        refInputFile = args.refInputFile.name
        args.refInputFile.close()
    else:
        showErrorAndExit(parser, "No reference DNA Input File!!!\n")

    # Determine file-extension type
    probeFileType = 'text'
    inputFileExtension = os.path.splitext(probeInputFile)[1]
    if inputFileExtension in ['.h5', '.hdf5', 'hdf']:
        probeFileType = 'hdf5'

    refFileType = 'text'
    inputFileExtension = os.path.splitext(refInputFile)[1]
    if inputFileExtension in ['.h5', '.hdf5', 'hdf']:
        refFileType = 'hdf5'

    # Total number of base-pair  --- probe
    probeFirstBP = args.probeFirstBP
    probeTotalBP = None
    if args.probeTotalBP is None:
        showErrorAndExit(parser, "No total number of BP for probe DNA!!!\n")
    else:
        probeTotalBP = args.probeTotalBP

    # Total number of base-pair  --- reference
    refFirstBP = args.probeFirstBP
    refTotalBP = None
    if args.refFirstBP is None:
        showErrorAndExit(parser, "No total number of BP for reference DNA!!!\n")
    else:
        refTotalBP = args.refTotalBP

    # Check for input parameter
    if args.parameter is None:
        showErrorAndExit(parser, "No Parameter name!!!\n")

    if not ( (args.parameter in dnaMD.basePairTypeParameters) or \
            (args.parameter in dnaMD.baseStepTypeParameters) ):
        parser.print_help()
        print("\n===== ERROR =======")
        print('Unknown parameter name "{0}"!!!\n'.format(args.parameter))
        print("Accepted parameters are as follows:")
        count = 1
        for parameter in dnaMD.basePairTypeParameters:
            print('{0}. "{1}"'.format(count, parameter))
            count += 1
        for parameter in dnaMD.baseStepTypeParameters:
            print('{0}. "{1}"'.format(count, parameter))
            count += 1
        print("\n===================")
        sys.exit(-1)

    # Output file
    if args.outputFile is None:
        showErrorAndExit(parser, "No output File!!!\n")

    paramType = dnaMD.getParameterType(args.parameter)
    toMinusBP = 1
    if paramType == 'bps':
        toMinusBP = 2

    # Determine start and end-bp ---- probe
    probeStartBP = args.probeStartBP
    if probeStartBP is None:
        probeStartBP = probeFirstBP

    probeEndBP = None
    if args.probeEndBP is not None:
        probeEndBP = args.probeEndBP
    else:
        probeEndBP = probeTotalBP - toMinusBP

    probeBP = [probeStartBP, probeEndBP]

    # Determine start and end-bp ---- reference
    refStartBP = args.refStartBP
    if refStartBP is None:
        refStartBP = refFirstBP

    refEndBP = None
    if args.refEndBP is not None:
        refEndBP = args.refEndBP
    else:
        refEndBP = refTotalBP - toMinusBP

    refBP = [refStartBP, refEndBP]

    # Check requested segment is equal in length
    if (refEndBP- refStartBP) != (probeEndBP - probeStartBP):
        msg='Length of requested segment is not equal in probe ({0}) and reference ({1}) DNA.'.format(probeBP, refBP)
        showErrorAndExit(parser, msg)


    # Check consistency of start bp --- probe
    if (probeStartBP < probeFirstBP) or (probeStartBP > probeTotalBP+probeFirstBP-toMinusBP):
        msg = 'The requested start bp {0} is out side of {1}-{2} range.'.format(probeStartBP, probeFirstBP, probeTotalBP+probeFirstBP-toMinusBP)
        showErrorAndExit(parser, msg)

    # Check consistency of start bp --- reference
    if (refStartBP < refFirstBP) or (refStartBP > refTotalBP+refFirstBP-toMinusBP):
        msg = 'The requested start bp {0} is out side of {1}-{2} range.'.format(refStartBP, refFirstBP, refTotalBP+refFirstBP-toMinusBP)
        showErrorAndExit(parser, msg)

    # Check consistency of end-bp  --- probe
    if probeStartBP > probeEndBP:
        msg = 'The requested end bp {0} is larger than requested start bp {1}!!!'.format(probeEndBP, probeStartBP)
        showErrorAndExit(parser, msg)
    if (probeEndBP > probeTotalBP+probeFirstBP-toMinusBP) or (probeEndBP < probeFirstBP):
        msg = 'The requested end bp {0} is out side of {1}-{2} range.'.format(probeEndBP, probeFirstBP, probeTotalBP+probeFirstBP-toMinusBP)
        showErrorAndExit(parser, msg)

    # Check consistency of end-bp  --- reference
    if refStartBP > refEndBP:
        msg = 'The requested end bp {0} is larger than requested start bp {1}!!!'.format(refEndBP, refStartBP)
        showErrorAndExit(parser, msg)
    if (refEndBP > refTotalBP+refFirstBP-toMinusBP) or (refEndBP < refFirstBP):
        msg = 'The requested end bp {0} is out side of {1}-{2} range.'.format(refEndBP, refFirstBP, refTotalBP+refFirstBP-toMinusBP)
        showErrorAndExit(parser, msg)

    # Check if merge-method is given
    if args.merge_method is None:
        msg = 'No merging method is provided!!!!'
        showErrorAndExit(parser, msg)

    # Store input file name
    probeFilename = None
    if probeFileType == 'hdf5':
        probeFilename = probeInputFile
    refFilename = None
    if refFileType == 'hdf5':
        refFilename = refInputFile

    # Check merge_bp
    if args.merge_bp > probeTotalBP or args.merge_bp > refTotalBP:
        msg = ' Number of bp/s to merge is larger than total number of bp.'
        showErrorAndExit(parser, msg)

    # check gromacs tools
    if 'analyze' not in args.tool:
        msg = '{0} might not be suitable for error calculation. \n Use Gromacs analyze tool g_analyze or "gmx analyze".'\
            .format(args.tool)
        showErrorAndExit(parser, msg)

    # initialize DNA object
    dnaProbe = dnaMD.DNA(probeTotalBP, filename=probeInputFile, startBP=probeFirstBP)
    dnaRef = dnaMD.DNA(refTotalBP, filename=refInputFile, startBP=refFirstBP)

    # Check if mask is in object
    if (dnaProbe.mask is not None) and (args.parameter in dnaMD.maskedParameters):
        masked = True
    else:
        masked = False

    # Directly read the data from text file  --- probe
    if probeFileType == 'text':
        # No support for smoothed axis, curvature and tangent
        if args.parameter in ['helical x-axis smooth', 'helical y-axis smooth', 'helical z-axis smooth', 'helical axis curvature', 'helical axis tangent']:
            print("\n===== ERROR =======")
            print('Extraction of parameter "{0}" is only supported via input HDF5 file.'.format(args.parameter))
            print("\n===== ERROR =======")
            sys.exit(-1)
        # Read and load parameter from file
        dnaMD.setParametersFromFile(dnaProbe, probeInputFile, args.parameter, bp=probeBP)

    # Directly read the data from text file  --- reference
    if refFileType == 'text':
        # No support for smoothed axis, curvature and tangent
        if args.parameter in ['helical x-axis smooth', 'helical y-axis smooth', 'helical z-axis smooth', 'helical axis curvature', 'helical axis tangent']:
            print("\n===== ERROR =======")
            print('Extraction of parameter "{0}" is only supported via input HDF5 file.'.format(args.parameter))
            print("\n===== ERROR =======")
            sys.exit(-1)
        # Read and load parameter from file
        dnaMD.setParametersFromFile(dnaRef, refInputFile, args.parameter, bp=refBP)

    # Main calculation here
    bpOutRef, bpOutProbe, deformation, error = dnaMD.localDeformationVsBPS(dnaRef, refBP, dnaProbe, probeBP,
                                                                           args.parameter,
                                                                           err_type=args.err_type,
                                                                           bp_range=True, merge_bp=args.merge_bp,
                                                                           merge_method=args.merge_method,
                                                                           masked=masked, tool=args.tool)

    # Write the extracted data in a text file
    fout = open(args.outputFile, 'w')
    fout.write('# bp(mid) \t {0}-avg \t {0}-error\n'.format(args.parameter))
    for i in range(len(deformation)):
        if args.xaxisBP == 'probe':
            fout.write("{0}\t".format(bpOutProbe[i]))
        else:
            fout.write("{0}\t\t".format(bpOutRef[i]))
        fout.write("{0:.6}\t{1:.6}\n".format(deformation[i], error[i]))
    fout.close()
コード例 #4
0
ファイル: vsTime.py プロジェクト: rjdkmr/do_x3dna
def main():
    parser, args = parseArguments()

    # Input file
    inputFile = None
    if args.inputFile is not None:
        inputFile = args.inputFile.name
        args.inputFile.close()
    else:
        showErrorAndExit(parser, "No Input File!!!\n")

    # Determine file-extension type
    fileType = 'text'
    inputFileExtension = os.path.splitext(inputFile)[1]
    if inputFileExtension in ['.h5', '.hdf5', 'hdf']:
        fileType = 'hdf5'

    # Total number of base-pair
    firstBP = args.firstBP
    totalBP = None
    if args.totalBP is None:
        showErrorAndExit(parser, "No total number of BP!!!\n")
    else:
        totalBP = args.totalBP

    # Check for input parameter
    if args.parameter is None:
        showErrorAndExit(parser, "No Parameter name!!!\n")

    if not ( (args.parameter in dnaMD.basePairTypeParameters) or \
            (args.parameter in dnaMD.baseStepTypeParameters) ):
        parser.print_help()
        print("\n===== ERROR =======")
        print('Unknown parameter name "{0}"!!!\n'.format(args.parameter))
        print("Accepted parameters are as follows:")
        count = 1
        for parameter in dnaMD.basePairTypeParameters:
            print('{0}. "{1}"'.format(count, parameter))
            count += 1
        for parameter in dnaMD.baseStepTypeParameters:
            print('{0}. "{1}"'.format(count, parameter))
            count += 1
        print("\n===================")
        sys.exit(-1)

    # Output file
    if args.outputFile is None:
        showErrorAndExit(parser, "No output File!!!\n")

    paramType = dnaMD.getParameterType(args.parameter)
    toMinusBP = 1
    if paramType == 'bps':
        toMinusBP = 2

    # Determine start and end-bp
    startBP = args.startBP
    if startBP is None:
        startBP = firstBP
    endBP = None
    if args.endBP is not None:
        endBP = args.endBP

    # Check consistency of start bp
    if (startBP < firstBP) or (startBP > totalBP+firstBP-toMinusBP):
        msg = 'The requested start bp {0} is out side of {1}-{2} range.'.format(startBP, firstBP, totalBP+firstBP-toMinusBP)
        showErrorAndExit(parser, msg)

    # Check consistency of end-bp
    if endBP is not None:
        if startBP > endBP:
            msg = 'The requested end bp {0} is larger than requested start bp {1}!!!'.format(endBP, startBP)
            showErrorAndExit(parser, msg)

        if (endBP > totalBP+firstBP-toMinusBP) or (endBP < firstBP):
            msg = 'The requested end bp {0} is out side of {1}-{2} range.'.format(endBP, firstBP, totalBP+firstBP-toMinusBP)
            showErrorAndExit(parser, msg)

    # Check if merge is required
    if endBP is None:
        merge = False
    else:
        merge = True

    # Check if merge-method is given
    if merge and args.merge_method is None:
        msg = 'No merging method is provided!!!!'
        showErrorAndExit(parser, msg)

    # Store input file name
    filename = None
    if fileType == 'hdf5':
        filename = inputFile

    if endBP is not None:
        bp = [startBP, endBP]
    else:
        bp = [startBP]

    # initialize DNA object
    dna = dnaMD.DNA(totalBP, filename=filename, startBP=firstBP)

    # Check if mask is in object
    if dna.mask is not None:
        masked = True
    else:
        masked = False

    # Directly read the data from text file
    if fileType == 'text':
        # No support for smoothed axis, curvature and tangent
        if args.parameter in ['helical x-axis smooth', 'helical y-axis smooth', 'helical z-axis smooth', 'helical axis curvature', 'helical axis tangent']:
            print("\n===== ERROR =======")
            print('Extraction of parameter "{0}" is only supported via input HDF5 file.'.format(args.parameter))
            print("\n===== ERROR =======")
            sys.exit(-1)

        # Read and load parameter from file
        dnaMD.setParametersFromFile(dna, inputFile, args.parameter, bp=bp)

    # Extract the input parameter for input DNA/RNA segment
    time, value = dna.time_vs_parameter(args.parameter, bp, merge=merge, merge_method=args.merge_method, masked=masked)

    # Write the extracted data in a text file
    fout = open(args.outputFile, 'w')
    fout.write('# Time \t "{0}"\n'.format(args.parameter))
    for i in range(len(time)):
        fout.write("{0}\t{1}\n".format(time[i], value[i]))
    fout.close()
コード例 #5
0
ファイル: saveAsH5.py プロジェクト: Daleang/do_x3dna
def main():
    parser, args = parseArguments()

    # Total number of base-pair
    firstBP = args.firstBP
    totalBP = None
    if args.totalBP is None:
        showErrorAndExit(parser, "No total number of BP!!!\n")
    else:
        totalBP = args.totalBP

    inputFilesDict = checkForInputFile(args, parser)

    # Determine file-extension type
    fileType = 'hdf5'
    outputFileExtension = os.path.splitext(args.outputFile)[1]
    if outputFileExtension not in ['.h5', '.hdf5', 'hdf']:
        showErrorAndExit(
            parser, "File extension {0} is not recognized as an \
        acceptable HDF5 extension.\n Use '.h5', '.hdf5' \
        or '.hdf'.".format(outputFileExtension))

    # initialize DNA object
    dna = dnaMD.DNA(totalBP, filename=args.outputFile, startBP=firstBP)

    if 'bp' in inputFilesDict:
        dnaMD.setParametersFromFile(dna, inputFilesDict['bp'],
                                    dnaMD.basePairParameters[:])
    if 'bps' in inputFilesDict:
        dnaMD.setParametersFromFile(dna, inputFilesDict['bps'],
                                    dnaMD.baseStepParameters[:])
    if 'bph' in inputFilesDict:
        dnaMD.setParametersFromFile(dna, inputFilesDict['bph'],
                                    dnaMD.helicalBaseStepParameters[:])
    if 'bbdih' in inputFilesDict:
        dnaMD.setParametersFromFile(dna, inputFilesDict['bbdih'],
                                    dnaMD.backboneDihedrals[:])
    if 'grooves' in inputFilesDict:
        dnaMD.setParametersFromFile(dna, inputFilesDict['grooves'],
                                    dnaMD.groovesParameters[:])
    if 'haxis' in inputFilesDict:
        dnaMD.setParametersFromFile(dna, inputFilesDict['haxis'],
                                    dnaMD.helicalAxisParameters[:])
    if 'hrad' in inputFilesDict:
        dnaMD.setParametersFromFile(dna, inputFilesDict['hrad'],
                                    dnaMD.helicalRadiusParameters[:])
コード例 #6
0
def main():
    parser, args = parseArguments()

    # Input file
    probeInputFile = None
    if args.probeInputFile is not None:
        probeInputFile = args.probeInputFile.name
        args.probeInputFile.close()
    else:
        showErrorAndExit(parser, "No Probe DNA Input File!!!\n")
    refInputFile = None
    if args.refInputFile is not None:
        refInputFile = args.refInputFile.name
        args.refInputFile.close()
    else:
        showErrorAndExit(parser, "No reference DNA Input File!!!\n")

    # Determine file-extension type
    probeFileType = 'text'
    inputFileExtension = os.path.splitext(probeInputFile)[1]
    if inputFileExtension in ['.h5', '.hdf5', 'hdf']:
        probeFileType = 'hdf5'

    refFileType = 'text'
    inputFileExtension = os.path.splitext(refInputFile)[1]
    if inputFileExtension in ['.h5', '.hdf5', 'hdf']:
        refFileType = 'hdf5'

    # Total number of base-pair  --- probe
    probeFirstBP = args.probeFirstBP
    probeTotalBP = None
    if args.probeTotalBP is None:
        showErrorAndExit(parser, "No total number of BP for probe DNA!!!\n")
    else:
        probeTotalBP = args.probeTotalBP

    # Total number of base-pair  --- reference
    refFirstBP = args.probeFirstBP
    refTotalBP = None
    if args.refFirstBP is None:
        showErrorAndExit(parser,
                         "No total number of BP for reference DNA!!!\n")
    else:
        refTotalBP = args.refTotalBP

    # Check for input parameter
    if args.parameter is None:
        showErrorAndExit(parser, "No Parameter name!!!\n")

    if not ( (args.parameter in dnaMD.basePairTypeParameters) or \
            (args.parameter in dnaMD.baseStepTypeParameters) ):
        parser.print_help()
        print("\n===== ERROR =======")
        print('Unknown parameter name "{0}"!!!\n'.format(args.parameter))
        print("Accepted parameters are as follows:")
        count = 1
        for parameter in dnaMD.basePairTypeParameters:
            print('{0}. "{1}"'.format(count, parameter))
            count += 1
        for parameter in dnaMD.baseStepTypeParameters:
            print('{0}. "{1}"'.format(count, parameter))
            count += 1
        print("\n===================")
        sys.exit(-1)

    # Output file
    if args.outputFile is None:
        showErrorAndExit(parser, "No output File!!!\n")

    paramType = dnaMD.getParameterType(args.parameter)
    toMinusBP = 1
    if paramType == 'bps':
        toMinusBP = 2

    # Determine start and end-bp ---- probe
    probeStartBP = args.probeStartBP
    if probeStartBP is None:
        probeStartBP = probeFirstBP

    probeEndBP = None
    if args.probeEndBP is not None:
        probeEndBP = args.probeEndBP
    else:
        probeEndBP = probeTotalBP - toMinusBP

    probeBP = [probeStartBP, probeEndBP]

    # Determine start and end-bp ---- reference
    refStartBP = args.refStartBP
    if refStartBP is None:
        refStartBP = refFirstBP

    refEndBP = None
    if args.refEndBP is not None:
        refEndBP = args.refEndBP
    else:
        refEndBP = refTotalBP - toMinusBP

    refBP = [refStartBP, refEndBP]

    # Check requested segment is equal in length
    if (refEndBP - refStartBP) != (probeEndBP - probeStartBP):
        msg = 'Length of requested segment is not equal in probe ({0}) and reference ({1}) DNA.'.format(
            probeBP, refBP)
        showErrorAndExit(parser, msg)

    # Check consistency of start bp --- probe
    if (probeStartBP < probeFirstBP) or (
            probeStartBP > probeTotalBP + probeFirstBP - toMinusBP):
        msg = 'The requested start bp {0} is out side of {1}-{2} range.'.format(
            probeStartBP, probeFirstBP,
            probeTotalBP + probeFirstBP - toMinusBP)
        showErrorAndExit(parser, msg)

    # Check consistency of start bp --- reference
    if (refStartBP < refFirstBP) or (refStartBP >
                                     refTotalBP + refFirstBP - toMinusBP):
        msg = 'The requested start bp {0} is out side of {1}-{2} range.'.format(
            refStartBP, refFirstBP, refTotalBP + refFirstBP - toMinusBP)
        showErrorAndExit(parser, msg)

    # Check consistency of end-bp  --- probe
    if probeStartBP > probeEndBP:
        msg = 'The requested end bp {0} is larger than requested start bp {1}!!!'.format(
            probeEndBP, probeStartBP)
        showErrorAndExit(parser, msg)
    if (probeEndBP > probeTotalBP + probeFirstBP - toMinusBP) or (
            probeEndBP < probeFirstBP):
        msg = 'The requested end bp {0} is out side of {1}-{2} range.'.format(
            probeEndBP, probeFirstBP, probeTotalBP + probeFirstBP - toMinusBP)
        showErrorAndExit(parser, msg)

    # Check consistency of end-bp  --- reference
    if refStartBP > refEndBP:
        msg = 'The requested end bp {0} is larger than requested start bp {1}!!!'.format(
            refEndBP, refStartBP)
        showErrorAndExit(parser, msg)
    if (refEndBP > refTotalBP + refFirstBP - toMinusBP) or (refEndBP <
                                                            refFirstBP):
        msg = 'The requested end bp {0} is out side of {1}-{2} range.'.format(
            refEndBP, refFirstBP, refTotalBP + refFirstBP - toMinusBP)
        showErrorAndExit(parser, msg)

    # Check if merge-method is given
    if args.merge_method is None:
        msg = 'No merging method is provided!!!!'
        showErrorAndExit(parser, msg)

    # Store input file name
    probeFilename = None
    if probeFileType == 'hdf5':
        probeFilename = probeInputFile
    refFilename = None
    if refFileType == 'hdf5':
        refFilename = refInputFile

    # Check merge_bp
    if args.merge_bp > probeTotalBP or args.merge_bp > refTotalBP:
        msg = ' Number of bp/s to merge is larger than total number of bp.'
        showErrorAndExit(parser, msg)

    # check gromacs tools
    if 'analyze' not in args.tool:
        msg = '{0} might not be suitable for error calculation. \n Use Gromacs analyze tool g_analyze or "gmx analyze".'\
            .format(args.tool)
        showErrorAndExit(parser, msg)

    # initialize DNA object
    dnaProbe = dnaMD.DNA(probeTotalBP,
                         filename=probeInputFile,
                         startBP=probeFirstBP)
    dnaRef = dnaMD.DNA(refTotalBP, filename=refInputFile, startBP=refFirstBP)

    # Check if mask is in object
    if (dnaProbe.mask is not None) and (args.parameter
                                        in dnaMD.maskedParameters):
        masked = True
    else:
        masked = False

    # Directly read the data from text file  --- probe
    if probeFileType == 'text':
        # No support for smoothed axis, curvature and tangent
        if args.parameter in [
                'helical x-axis smooth', 'helical y-axis smooth',
                'helical z-axis smooth', 'helical axis curvature',
                'helical axis tangent'
        ]:
            print("\n===== ERROR =======")
            print(
                'Extraction of parameter "{0}" is only supported via input HDF5 file.'
                .format(args.parameter))
            print("\n===== ERROR =======")
            sys.exit(-1)
        # Read and load parameter from file
        dnaMD.setParametersFromFile(dnaProbe,
                                    probeInputFile,
                                    args.parameter,
                                    bp=probeBP)

    # Directly read the data from text file  --- reference
    if refFileType == 'text':
        # No support for smoothed axis, curvature and tangent
        if args.parameter in [
                'helical x-axis smooth', 'helical y-axis smooth',
                'helical z-axis smooth', 'helical axis curvature',
                'helical axis tangent'
        ]:
            print("\n===== ERROR =======")
            print(
                'Extraction of parameter "{0}" is only supported via input HDF5 file.'
                .format(args.parameter))
            print("\n===== ERROR =======")
            sys.exit(-1)
        # Read and load parameter from file
        dnaMD.setParametersFromFile(dnaRef,
                                    refInputFile,
                                    args.parameter,
                                    bp=refBP)

    # Main calculation here
    bpOutRef, bpOutProbe, deformation, error = dnaMD.localDeformationVsBPS(
        dnaRef,
        refBP,
        dnaProbe,
        probeBP,
        args.parameter,
        err_type=args.err_type,
        bp_range=True,
        merge_bp=args.merge_bp,
        merge_method=args.merge_method,
        masked=masked,
        tool=args.tool)

    # Write the extracted data in a text file
    fout = open(args.outputFile, 'w')
    fout.write('# bp(mid) \t {0}-avg \t {0}-error\n'.format(args.parameter))
    for i in range(len(deformation)):
        if args.xaxisBP == 'probe':
            fout.write("{0}\t".format(bpOutProbe[i]))
        else:
            fout.write("{0}\t\t".format(bpOutRef[i]))
        fout.write("{0:.6}\t{1:.6}\n".format(deformation[i], error[i]))
    fout.close()
コード例 #7
0
def main():
    parser, args = parseArguments()

    # Input file
    inputFile = None
    if args.inputFile is not None:
        inputFile = args.inputFile.name
        args.inputFile.close()
    else:
        showErrorAndExit(parser, "No Input File!!!\n")

    # Determine file-extension type
    fileType = 'text'
    inputFileExtension = os.path.splitext(inputFile)[1]
    if inputFileExtension in ['.h5', '.hdf5', 'hdf']:
        fileType = 'hdf5'

    # Total number of base-pair
    firstBP = args.firstBP
    totalBP = None
    if args.totalBP is None:
        showErrorAndExit(parser, "No total number of BP!!!\n")
    else:
        totalBP = args.totalBP

    # Check for input parameter
    if args.parameter is None:
        showErrorAndExit(parser, "No Parameter name!!!\n")

    if not ( (args.parameter in dnaMD.basePairTypeParameters) or \
            (args.parameter in dnaMD.baseStepTypeParameters) ):
        parser.print_help()
        print("\n===== ERROR =======")
        print('Unknown parameter name "{0}"!!!\n'.format(args.parameter))
        print("Accepted parameters are as follows:")
        count = 1
        for parameter in dnaMD.basePairTypeParameters:
            print('{0}. "{1}"'.format(count, parameter))
            count += 1
        for parameter in dnaMD.baseStepTypeParameters:
            print('{0}. "{1}"'.format(count, parameter))
            count += 1
        print("\n===================")
        sys.exit(-1)

    # Output file
    if args.outputFile is None:
        showErrorAndExit(parser, "No output File!!!\n")

    paramType = dnaMD.getParameterType(args.parameter)
    toMinusBP = 1
    if paramType == 'bps':
        toMinusBP = 2

    # Determine start and end-bp
    startBP = args.startBP
    endBP = None
    if startBP is None:
        startBP = firstBP
    if args.endBP is not None:
        endBP = args.endBP
    else:
        endBP = totalBP - toMinusBP
    bp = [startBP, endBP]

    # Check consistency of start bp
    if (startBP < firstBP) or (startBP > totalBP+firstBP-toMinusBP):
        msg = 'The requested start bp {0} is out side of {1}-{2} range.'.format(startBP, firstBP, totalBP+firstBP-toMinusBP)
        showErrorAndExit(parser, msg)

    # Check consistency of end-bp
    if endBP is not None:
        if startBP > endBP:
            msg = 'The requested end bp {0} is larger than requested start bp {1}!!!'.format(endBP, startBP)
            showErrorAndExit(parser, msg)

        if (endBP > totalBP+firstBP-toMinusBP) or (endBP < firstBP):
            msg = 'The requested end bp {0} is out side of {1}-{2} range.'.format(endBP, firstBP, totalBP+firstBP-toMinusBP)
            showErrorAndExit(parser, msg)

    # Check if merge-method is given
    if args.merge_method is None:
        msg = 'No merging method is provided!!!!'
        showErrorAndExit(parser, msg)

    # Store input file name
    filename = None
    if fileType == 'hdf5':
        filename = inputFile

    # Check merge_bp
    if args.merge_bp > totalBP:
        msg = ' Number of bp/s to merge is larger than total number of bp.'
        showErrorAndExit(parser, msg)

    # check gromacs tools
    if 'analyze' not in args.tool:
        msg = '{0} might not be suitable for error calculation. \n Use Gromacs analyze tool g_analyze or "gmx analyze".'\
            .format(args.tool)
        showErrorAndExit(parser, msg)

    # initialize DNA object
    dna = dnaMD.DNA(totalBP, filename=filename, startBP=firstBP)

    # Check if mask is in object
    if dna.mask is not None:
        masked = True
    else:
        masked = False

    # Directly read the data from text file
    if fileType == 'text':
        # No support for smoothed axis, curvature and tangent
        if args.parameter in ['helical x-axis smooth', 'helical y-axis smooth', 'helical z-axis smooth', 'helical axis curvature', 'helical axis tangent']:
            print("\n===== ERROR =======")
            print('Extraction of parameter "{0}" is only supported via input HDF5 file.'.format(args.parameter))
            print("\n===== ERROR =======")
            sys.exit(-1)

        # Read and load parameter from file
        dnaMD.setParametersFromFile(dna, inputFile, args.parameter, bp=bp)

    bp_center, avg, error = dna.get_mean_error(bp, args.parameter, err_type=args.err_type, bp_range=True,
                                               merge_bp=args.merge_bp, merge_method=args.merge_method,
                                               masked=masked, tool=args.tool)

    # Write the extracted data in a text file
    fout = open(args.outputFile, 'w')
    fout.write('# bp(mid) \t {0}-avg \t {0}-error\n'.format(args.parameter))
    for i in range(len(bp_center)):
        fout.write("{0} \t\t {1:.6} \t {2:.6}\n".format(bp_center[i], avg[i], error[i]))
    fout.close()