comparison calculate_pore_diameter_aqp.py @ 12:066606280457 draft

"planemo upload for repository https://github.com/mesocentre-clermont-auvergne/aubi_piaf commit 39e6c57933401793343e38ebe55ad3cc52a3112d"
author agpetit
date Tue, 21 Jun 2022 13:39:23 +0000
parents a4097272ade0
children f5064c93f7ab
comparison
equal deleted inserted replaced
11:a4097272ade0 12:066606280457
69 "--verbose", 69 "--verbose",
70 action="store_true", 70 action="store_true",
71 help="""Information messages to stderr""", 71 help="""Information messages to stderr""",
72 ) 72 )
73 parser.add_argument( 73 parser.add_argument(
74 "-gro", "--gro_file", type=str, nargs=1, help="""My input .gro file""" 74 "-gro", "--gro_file", type=str, help="""My input .gro file"""
75 ) 75 )
76 parser.add_argument( 76 parser.add_argument(
77 "-xtc", "--xtc_file", type=str, nargs=1, help="""My input .xtc file""" 77 "-xtc", "--xtc_file", type=str, help="""My input .xtc file"""
78 ) 78 )
79 parser.add_argument( 79 parser.add_argument(
80 "--gro_file_ext", type=str, nargs=1, help="""My input .gro file""" 80 "--gro_file_ext", type=str, help="""My input .gro file"""
81 ) 81 )
82 parser.add_argument( 82 parser.add_argument(
83 "--xtc_file_ext", type=str, nargs=1, help="""My input .xtc file""" 83 "--xtc_file_ext", type=str, help="""My input .xtc file"""
84 ) 84 )
85 parser.add_argument( 85 parser.add_argument(
86 "-w", "--work_directory", type=str, default="./", 86 "-w", "--work_directory", type=str, default="./",
87 help="""It's work Directory""" 87 help="""It's work Directory"""
88 ) 88 )
89 parser.add_argument( 89 parser.add_argument(
90 "-od", 90 "-od",
91 "--output_directory", 91 "--output_directory",
92 default="stdout", 92 default="out/",
93 type=str, 93 type=str,
94 nargs=1, 94 nargs=1,
95 help="""It's output Directory""", 95 help="""It's output Directory""",
96 ) 96 )
97 parser.add_argument( 97 parser.add_argument(
123 default="", 123 default="",
124 nargs=1, 124 nargs=1,
125 help="""3-letter pattern of the 4 amino acids of second ArR on HE""", 125 help="""3-letter pattern of the 4 amino acids of second ArR on HE""",
126 ) 126 )
127 parser.add_argument("-o", "--output", help="""Output for files""") 127 parser.add_argument("-o", "--output", help="""Output for files""")
128 parser.add_argument("-log", "--log_output", help="""Output for files""") 128 parser.add_argument("-log", "--log_output",
129 default="log/calculate_pore_diameter_aqp.log",
130 help="""Output for files""")
129 return parser.parse_args() 131 return parser.parse_args()
130 132
131 133
132 def search_amino_acids_pattern(list_pattern, uni): 134 def search_amino_acids_pattern(list_pattern, uni):
133 """ 135 """
980 # Class 982 # Class
981 983
982 984
983 if __name__ == "__main__": 985 if __name__ == "__main__":
984 args = parse_arguments() 986 args = parse_arguments()
985 out_file_name = "test" 987 if args.verbose:
986 file_name_log = out_file_name + ".log" 988 if len(os.path.dirname(args.log_output)) > 1:
987 if args.verbose: 989 log_dir = os.path.dirname(args.log_output)
988 if args.log_output:
989 if os.path.isfile(args.log_output):
990 os.remove(args.log_output)
991 logging.basicConfig(
992 filename=args.log_output,
993 format="%(levelname)s - %(message)s",
994 level=logging.INFO,
995 )
996 else: 990 else:
997 if os.path.isfile(file_name_log): 991 log_dir = "log/"
998 os.remove(file_name_log) 992 try:
999 logging.basicConfig( 993 os.makedirs(log_dir, exist_ok=True)
1000 filename=file_name_log, 994 except OSError:
1001 format="%(levelname)s - %(message)s", 995 print("Directory '%s' can not be created")
1002 level=logging.INFO, 996 if os.path.isfile(args.log_output):
1003 ) 997 os.remove(args.log_output)
998 logging.basicConfig(
999 filename=args.log_output,
1000 format="%(levelname)s - %(message)s",
1001 level=logging.INFO,
1002 )
1004 logging.info("verbose mode on") 1003 logging.info("verbose mode on")
1005 gro_file = '' 1004 gro_file = ''
1006 xtc_file = '' 1005 xtc_file = ''
1007 if args.gro_file: 1006 if args.gro_file:
1008 gro_file = os.path.basename(args.gro_file[0]) 1007 gro_file = os.path.basename(args.gro_file)
1008 if ".gro" not in gro_file:
1009 if args.verbose:
1010 logging.critical("-gro error: input is not .gro file")
1011 print("-gro error: input is not .gro file")
1012 sys.exit(1)
1009 else: 1013 else:
1010 logging.critical("A .gro file must be provided") 1014 if args.verbose:
1015 logging.critical("A .gro file must be provided")
1016 print("A .gro file must be provided")
1017 sys.exit(1)
1011 if args.xtc_file: 1018 if args.xtc_file:
1012 xtc_file = os.path.basename(args.xtc_file[0]) 1019 xtc_file = os.path.basename(args.xtc_file)
1020 if ".xtc" not in xtc_file:
1021 if args.xtc_file_ext == "xtc":
1022 xtc_file = xtc_file + ".xtc"
1023 else:
1024 if args.verbose:
1025 logging.critical("-xtc error: input is not .xtc file")
1026 print("-xtc error: input is not .xtc file")
1027 sys.exit(1)
1013 else: 1028 else:
1014 logging.critical("A .xtc file must be provided") 1029 if args.verbose:
1015 if args.work_directory: 1030 logging.critical("A .xtc file must be provided")
1016 work_directory = args.work_directory[0] 1031 print("A .xtc file must be provided")
1032 sys.exit(1)
1033 if len(os.path.dirname(args.gro_file)) > 1:
1034 work_directory = os.path.dirname(args.gro_file)
1017 else: 1035 else:
1018 work_directory = os.path.dirname(args.gro_file[0]) 1036 work_directory = args.work_directory
1019 if not work_directory.endswith("/"): 1037 if not work_directory.endswith("/"):
1020 work_directory += "/" 1038 work_directory += "/"
1021 output_directory = args.output_directory[0] 1039 output_directory = args.output_directory
1022 if args.output: 1040 if args.output:
1023 output = args.output 1041 output = args.output
1024 else: 1042 else:
1025 output = "" 1043 output = ""
1026 os.chdir(work_directory) 1044 os.chdir(work_directory)
1027 if args.gro_file_ext and args.xtc_file_ext: 1045 if args.gro_file_ext and args.xtc_file_ext:
1028 u = Mda.Universe( 1046 u = Mda.Universe(
1029 args.gro_file[0], 1047 args.gro_file,
1030 args.xtc_file[0], 1048 args.xtc_file,
1031 topology_format=args.gro_file_ext[0], 1049 topology_format=args.gro_file_ext,
1032 format=args.xtc_file_ext[0], 1050 format=args.xtc_file_ext,
1033 ) 1051 )
1034 else: 1052 else:
1035 u = Mda.Universe(args.gro_file[0], args.xtc_file[0]) 1053 u = Mda.Universe(args.gro_file, args.xtc_file)
1036 if args.verbose: 1054 if args.verbose:
1037 logging.info("Load universe : " + str(u)) 1055 logging.info("Load universe : " + str(u))
1056 resid_npa1 = None
1057 resid_npa2 = None
1058 resid_arr1 = None
1059 resid_arr2 = None
1038 if args.npa_one: 1060 if args.npa_one:
1039 resid_npa1 = args.npa_one[0].split() 1061 resid_npa1 = args.npa_one[0].split()
1040 else:
1041 resid_npa1 = args.npa_one
1042 if args.npa_second: 1062 if args.npa_second:
1043 resid_npa2 = args.npa_second[0].split() 1063 resid_npa2 = args.npa_second[0].split()
1044 else:
1045 resid_npa2 = args.npa_second
1046 if args.arr_one: 1064 if args.arr_one:
1047 resid_arr1 = args.arr_one[0].split() 1065 resid_arr1 = args.arr_one[0].split()
1048 else:
1049 resid_arr1 = args.arr_one
1050 if args.arr_second: 1066 if args.arr_second:
1051 resid_arr2 = args.arr_second[0].split() 1067 resid_arr2 = args.arr_second[0].split()
1052 else:
1053 resid_arr2 = args.arr_second
1054 df_final = create_final_dataframe(resid_arr1, resid_arr2, 1068 df_final = create_final_dataframe(resid_arr1, resid_arr2,
1055 resid_npa1, resid_npa2, u) 1069 resid_npa1, resid_npa2, u)
1056 if len(output_directory) > 2: 1070 if len(output_directory) > 2:
1057 try: 1071 try:
1058 os.makedirs(output_directory, exist_ok=True) 1072 os.makedirs(output_directory, exist_ok=True)
1060 print("Directory '%s' can not be created") 1074 print("Directory '%s' can not be created")
1061 os.chdir(output_directory) 1075 os.chdir(output_directory)
1062 if len(output) > 2: 1076 if len(output) > 2:
1063 df_final.to_csv(output, sep="\t", index=False) 1077 df_final.to_csv(output, sep="\t", index=False)
1064 else: 1078 else:
1065 file_name_tabular = out_file_name + "PairDist.tabular" 1079 file_name_tabular = "Calculate_pair_dist_aqp.tabular"
1066 df_final.to_csv(file_name_tabular, sep="\t", index=False) 1080 df_final.to_csv(file_name_tabular, sep="\t", index=False)