Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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

    toMinusBP=2   # Base-step
    # Determine start and end-bp
    startBP = None
    if args.startBP is None:
        startBP = args.firstBP
    else:
        startBP = args.startBP

    endBP = None
    if  args.endBP is None:
        endBP = totalBP+firstBP-toMinusBP
    else:
        endBP = args.endBP

    # Determine step_range and step
    step_range = False
    step = None
    if not (startBP == args.firstBP and endBP == totalBP+firstBP-toMinusBP):
        # 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 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)

        step_range = True
        step = [startBP, endBP]

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

    # initialize DNA object
    dna = dnaMD.DNA(totalBP, filename=args.ioFile, startBP=firstBP)
    dna.calculate_curvature_tangent(step_range=step_range, step=step,
                                    store_tangent=True)
Ejemplo n.º 3
0
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[:])
Ejemplo n.º 4
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 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()
Ejemplo n.º 5
0
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

    toMinusBP=2   # Base-step
    # Determine start and end-bp
    startBP = None
    if args.startBP is None:
        startBP = args.firstBP
    else:
        startBP = args.startBP

    endBP = None
    if  args.endBP is None:
        endBP = totalBP+firstBP-toMinusBP
    else:
        endBP = args.endBP

    # Determine step_range and step
    step_range = False
    step = None
    if not (startBP == args.firstBP and endBP == totalBP+firstBP-toMinusBP):
        # 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 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)

        step_range = True
        step = [startBP, endBP]

    # Determine file-extension type
    fileType = 'hdf5'
    outputFileExtension = os.path.splitext(args.ioFile)[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.ioFile, startBP=firstBP)
    dna.generate_smooth_axis(step_range=step_range, step=step,
                            smooth=args.smooth,
                            spline=args.spline, fill_point=args.fill_point,
                            cut_off_angle=args.cut_off_angle)

    if args.curvTangent:
        print(" ... Calculating curvature and tangents ")
        dna.calculate_curvature_tangent(step_range=step_range, step=step,
                                        store_tangent=True)
        print("                              ... Finished")

    if args.pdbFile is not None:

        if args.pdbAxisOption == 'both':
            write_smooth_axis = True
            write_orig_axis = True
        elif pdbAxisOption == 'global':
            write_smooth_axis = True
            write_orig_axis = False
        elif pdbAxisOption == 'local':
            write_smooth_axis = False
            write_orig_axis = True
        else:
            write_smooth_axis = True
            write_orig_axis = False

        if args.scaleCurvPdb is None:
            write_curv = False
            args.scaleCurvPdb = 1
        else:
            write_curv = True

        dna.write_haxis_pdb(filename=args.pdbFile,
                            step_range=step_range,
                            step=step, write_smooth_axis=write_smooth_axis,
                            write_orig_axis=write_orig_axis,
                            write_curv=write_curv,
                            scale_curv=args.scaleCurvPdb)
Ejemplo n.º 6
0
def main():
    parser, args = parseArguments()

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

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

    # Determine file-extension type
    inputFileExtension = os.path.splitext(inputRefFile)[1]
    if inputFileExtension not in ['.h5', '.hdf5', '.hdf']:
        showErrorAndExit(
            parser,
            "Input file for Reference DNA should be in HDF5 (h5, hdf5 or hdf extension) format.\n"
        )
    inputFileExtension = os.path.splitext(inputProbeFile)[1]
    if inputFileExtension not in ['.h5', '.hdf5', '.hdf']:
        showErrorAndExit(
            parser,
            "Input file for probe DNA should be in HDF5 (h5, hdf5 or hdf extension) format.\n"
        )

    # 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

    # Determine start and end-bp
    toMinusBP = 2
    startBP = args.startBP
    if startBP is None:
        startBP = firstBP
    endBP = args.endBP
    if endBP is None:
        endBP = firstBP + totalBP - toMinusBP

    # 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)

    # Define DNA segement here
    bp = [startBP, endBP]

    if args.esType == 'BST' and args.paxis is None:
        showErrorAndExit(
            parser,
            'To calculate bending, principal axis parallel to helical axis is required.'
        )

    # Check energy terms and make a list
    outEnergyTerms = checkEnergyTerms(args)

    # initialize DNA object
    dna = dnaMD.dnaEY(totalBP,
                      esType=args.esType,
                      filename=inputRefFile,
                      startBP=firstBP)
    complexDna = dnaMD.DNA(totalBP, filename=inputProbeFile, startBP=firstBP)

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

    time, energy = dna.getGlobalDeformationEnergy(bp,
                                                  complexDna,
                                                  paxis=args.paxis,
                                                  which=outEnergyTerms,
                                                  masked=masked,
                                                  outFile=args.outputFile)

    if args.err_type is not None:
        error = dnaMD.get_error(time,
                                list(energy.values()),
                                len(outEnergyTerms),
                                err_type=args.err_type,
                                tool=args.tool)

        sys.stdout.write("==============================================\n")
        sys.stdout.write('{0:<16}{1:>14}{2:>14}\n'.format(
            'Energy(kJ/mol)', 'Average', 'Error'))
        sys.stdout.write("----------------------------------------------\n")
        for i in range(len(outEnergyTerms)):
            sys.stdout.write('{0:<16}{1:>14.3f}{2:>14.3f}\n'.format(
                outEnergyTerms[i], np.mean(energy[outEnergyTerms[i]]),
                error[i]))
        sys.stdout.write("==============================================\n\n")
Ejemplo n.º 7
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()
Ejemplo n.º 8
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()