コード例 #1
0
def Byte_Fill(str0):
    str1 = convert_7D(str0)
    str2 = convert_7E(str1)
    str3 = convert_1X(str2)
    str4 = convert_0X(str3)
    return str4


if __name__ == "__main__":
    InfoString = ""
    ini_path = "./Byte_Fill_data.ini"
    if len(sys.argv) == 2:
        ini_path = sys.argv[1]

    InfoString = readConfigFile.readConfigFile(ini_path, "InfoString",
                                               InfoString)
    InfoString = InfoString[:16]
    print(len(InfoString))
    print("-------------字节填充之后的数据信息-------------")
    Fill_string = Byte_Fill(InfoString)
    print(Fill_string)
    print("-------------帧首部的四部分---------------------")
    print("帧起始标志:7E  ", "A:FF  ", "C:03  ", "协议:0021 或 C021 或 8021")
    print("-------------帧尾部的两部分---------------------")
    print("FCS:XX  ", "帧结束标志:7E")
    print("-------------字节填充后的发送帧为---------------")
    print("若为IP数据报:                " + "7E FF 03 0021", Fill_string, " XX",
          " 7E")
    print("若为ppp链路控制协议LCP的数据:", "7E FF 03 C021 ", Fill_string, " XX", " 7E")
    print("若为网络层的控制数据:        ", "7E FF 03 8021 ", Fill_string, " XX", " 7E")
    print("-------------字节删除后的接收帧为---------------")
コード例 #2
0
ファイル: process.py プロジェクト: dnil/FindSV
def restart(programDirectory, step, project, status):
    (working_dir, available_tools, account, exclude, modules, recursive) = readConfigFile.readConfigFile(
        programDirectory
    )
    statusFiles = ["timeout", "failed", "cancelled"]
    processes = {
        "caller": ["annotation", "filter", "database", "combine", "cleaning"],
        "combine": ["annotation", "filter", "database", "combine", "cleaning"],
        "db": ["annotation", "filter", "database", "cleaning"],
        "filter": ["annotation", "filter", "cleaning"],
        "annotation": ["annotation", "cleaning"],
    }
    default_working_dir = working_dir
    print ("Restarting:")
    projects = {}
    # all projects found in the project dictionary are being analysed
    for file in os.listdir(os.path.join(programDirectory, "projects")):
        if file.endswith(".txt") and not file.endswith("example.txt"):
            with open(os.path.join(programDirectory, "projects", file)) as ongoing_fd:
                projectID = file.split("/")[-1]
                projectID = file.replace(".txt", "")
                # if the user has selected a project manually, and it is not this one
                # then there is really nothing to do.
                if not (project and (project != projectID)):
                    projects[projectID] = {}
                    for line in ongoing_fd:
                        try:
                            if line[0] != "#":
                                info = line.strip()
                                info = info.split("\t")
                                projects[projectID][info[0]] = info[1:]
                        except:
                            # the pipeline should not crash if the user adds some newlines etc to the project file
                            pass

    # check if any status file is selected
    restartStatusFiles = []
    if status:
        if status == "all":
            restartStatusFiles = statusFiles
        elif status in statusFiles:
            restartStatusFiles = [status]
        else:
            print ("Invalid status file.")
            return 0

    # check which caller is selected
    callerToBeRestarted = []
    if "caller" in step:
        if step["caller"] == "all":
            print ("All callers are being restarted!")
            for tools in available_tools:
                callerToBeRestarted.append(tools)
        else:
            if step["caller"] in available_tools:
                callerToBeRestarted.append(step["caller"])
                print "Restarting caller {}.".format(step["caller"])

    # restart the callers by removing the status files
    for project in projects:
        if not projects[project]["output"]:
            working_dir = default_working_dir
        else:
            working_dir = projects[project]["output"][0]

        for caller in callerToBeRestarted:
            deletedProcess = os.path.join(working_dir, project, "process", caller)
            if os.path.exists(deletedProcess) and not restartStatusFiles:
                shutil.rmtree(deletedProcess)
            # if a certain statusfile is specified, restart only that file
            elif restartStatusFiles:
                for files in restartStatusFiles:
                    deletedStatusFile = os.path.join(deletedProcess, "calling", files)
                    if os.path.exists(deletedStatusFile):
                        os.remove(deletedStatusFile)

    # Check which steps will be restarted
    processToBeRestarted = []
    if "caller" in step:
        processToBeRestarted = processes["caller"]
    elif "combine" in step:
        processToBeRestarted = processes["combine"]
    elif "db" in step:
        processToBeRestarted = processes["db"]
    elif "filter" in step:
        processToBeRestarted = processes["filter"]
    elif "annotation" in step:
        processToBeRestarted = processes["annotation"]

    # Iterate through each project
    for project in projects:
        if not projects[project]["output"]:
            working_dir = default_working_dir
        else:
            working_dir = projects[project]["output"][0]
        print (project)
        for process in processToBeRestarted:
            print (process)
            deletedProcess = os.path.join(working_dir, project, "process", "FindSV", process)
            # If the entire step is to be restarted,
            # delete the folder containing the status files.
            if os.path.exists(deletedProcess) and not restartStatusFiles:
                shutil.rmtree(deletedProcess)
            # if a certain statusfile is specified, restart only that file
            elif restartStatusFiles:
                for files in restartStatusFiles:
                    deletedStatusFile = os.path.join(deletedProcess, files)
                    if os.path.exists(deletedStatusFile):
                        os.remove(deletedStatusFile)
コード例 #3
0
ファイル: FindSV.py プロジェクト: dnil/FindSV
def main(args):
    programDirectory = os.path.dirname(os.path.abspath(__file__))
    #read the project file
    projects = {}

    for file in os.listdir(os.path.join(programDirectory,"projects")):
        if file.endswith(".txt") and not file.endswith("example.txt"):
            with open(os.path.join(programDirectory,"projects" ,file)) as ongoing_fd:
                projectID=file.split("/")[-1]
                projectID=file.replace(".txt","")
                #the user has selected a project manually, and it is not this one
                #then there is really nothing to do.

                if not (args.project and (args.project != projectID)):
                    projects[projectID]={};
                    for line in ongoing_fd:
                        try:
                            if line[0] != "#":
                                info=line.strip();
                                info = info.split("\t")
                                projects[projectID][info[0]]=info[1:]
                        except:
                        #the pipeline should not crash if the user adds some newlines etc to the project file
                            pass

    # Read the config file
    (working_dir, available_tools, account, exclude,modules,recursive) = readConfigFile.readConfigFile(programDirectory)
    path_to_bam=""
    default_working_dir=working_dir
    for project in projects:
        #initiate the project parameters based on the project dictionary
        project_path = projects[project]["bam"]
        projectName = project
        #set the output,genmod and frequency db path
        if not projects[project]["output"]:
            working_dir = default_working_dir
        else:
            working_dir= projects[project]["output"][0]
            
        if not projects[project]["genmod"]:
            genmod_file = os.path.join(programDirectory,"genmod")
        else:
            genmod_file=projects[project]["genmod"][0]
        if not projects[project]["db"]:
            frequency_db=os.path.join(working_dir, project,"FindSV","database")
        else:
            frequency_db=projects[project]["db"][0]
        processFilesPath = os.path.join(working_dir, project,"process")
        
        #create a directory to keep track of the analysed files
        if not (os.path.exists(processFilesPath)):
            os.makedirs(processFilesPath)

        #initate the processFiles
        processFiles = initiateProcessFile(available_tools, processFilesPath)

        #search for the projects bam files
        bamfiles=detect_bam_files(project_path, projectName,path_to_bam,recursive)
        #function used to find variants
        processFiles= calling.variantCalling(
            programDirectory, project_path, projectName, working_dir, 
            path_to_bam, available_tools, account, modules,bamfiles, exclude, processFiles,
            processFilesPath)

        #combine the results o the variant calling
        processFiles = combine.combine(programDirectory, processFiles, 
                                             processFilesPath, account,bamfiles)

        #a function used to build databases from vcf files
        processFiles = database.buildDatabase(programDirectory, processFiles,
                                              processFilesPath, account)
        

        # Function that filters the variant files and finds genomic features of 
        # the variants
        processFiles = filter.applyFilter(programDirectory, processFiles, 
                                          processFilesPath, account,frequency_db)

        #function used to annotate the samples
        processFiles = annotation.annotation(programDirectory, processFiles, 
                                             processFilesPath, account,genmod_file)

        #the funciton used for cleaning the vcf file, this is the final step of the pipeline
        processFiles = cleaning.cleaning(programDirectory, processFiles, 
                                             processFilesPath, account)
    return