def RetrievePAINSPatterns(PAINSFilterMode): """Retrieve PAINS patterns for specified PAINS mode""" MayaChemToolsDataDir = MiscUtil.GetMayaChemToolsLibDataPath() PAINSFiltersFilePath = os.path.join(MayaChemToolsDataDir, "PAINSFilters.csv") MiscUtil.PrintInfo( "\nRetrieving PAINS SMARTS patterns for PAINS filter type, %s, from file %s" % (PAINSFilterMode, PAINSFiltersFilePath)) if not os.path.exists(PAINSFiltersFilePath): MiscUtil.PrintError("The PAINS filters file, %s, doesn't exist.\n" % (PAINSFiltersFilePath)) FilterFile = open(PAINSFiltersFilePath, "r") if FilterFile is None: MiscUtil.PrintError("Couldn't open PAINS filter file: %s.\n" % (PAINSFiltersFilePath)) # Collect all PAINS filter lines... HeaderLine = True FiltersLines = [] for Line in FilterFile: Line = Line.rstrip() # Ignore comments... if re.match("^#", Line, re.I): continue # Ignore header line... if HeaderLine: HeaderLine = False continue FiltersLines.append(Line) # Process PAINS filter lines using csv reader... SMARTSPatterns = [] FiltersReader = csv.reader(FiltersLines, delimiter=',', quotechar='"') for LineWords in FiltersReader: FilterType = LineWords[0] ID = LineWords[1] SMARTS = LineWords[2] if re.match("^All$", PAINSFilterMode, re.I) or FilterType.lower() == PAINSFilterMode.lower(): SMARTSPatterns.append(SMARTS) FilterFile.close() MiscUtil.PrintInfo("Total number of PAINS SMARTS patterns: %d" % (len(SMARTSPatterns))) return SMARTSPatterns
def RetrieveChEMBLFiltersInfo(): """Retrieve information for ChEMBL filters.""" MayaChemToolsDataDir = MiscUtil.GetMayaChemToolsLibDataPath() ChEMBLFiltersFilePath = os.path.join(MayaChemToolsDataDir, "ChEMBLFilters.csv") MiscUtil.PrintInfo( "\nRetrieving ChEMBL alerts SMARTS patterns from file %s" % (ChEMBLFiltersFilePath)) Delimiter = ',' QuoteChar = '"' IgnoreHeaderLine = True FilterLinesWords = MiscUtil.GetTextLinesWords(ChEMBLFiltersFilePath, Delimiter, QuoteChar, IgnoreHeaderLine) ChEMBLFiltersMap = {} ChEMBLFiltersMap["FilterTypes"] = [] ChEMBLFiltersMap["ID"] = {} ChEMBLFiltersMap["SMARTS"] = {} for LineWords in FilterLinesWords: FilterType = LineWords[0] ID = LineWords[1] SMARTS = LineWords[2] if not FilterType in ChEMBLFiltersMap["FilterTypes"]: ChEMBLFiltersMap["FilterTypes"].append(FilterType) ChEMBLFiltersMap["ID"][FilterType] = [] ChEMBLFiltersMap["SMARTS"][FilterType] = [] ChEMBLFiltersMap["ID"][FilterType].append(ID) ChEMBLFiltersMap["SMARTS"][FilterType].append(SMARTS) OptionsInfo["ChEMBLFiltersMap"] = ChEMBLFiltersMap MiscUtil.PrintInfo("\nTotal number alerts: %d" % len(FilterLinesWords)) MiscUtil.PrintInfo( "Number of filter family types: %d\nFilter familty types: %s\n" % (len(ChEMBLFiltersMap["FilterTypes"]), ", ".join( ChEMBLFiltersMap["FilterTypes"]))) for FilterType in ChEMBLFiltersMap["FilterTypes"]: MiscUtil.PrintInfo( "Filter family type: %s; Number of alerts: %d" % (FilterType, len(ChEMBLFiltersMap["ID"][FilterType]))) MiscUtil.PrintInfo("")
def RetrieveReactionNamesInfo(): """Retrieve reaction names information.""" RxnNamesFilePath = OptionsInfo["RxnNamesFile"] if RxnNamesFilePath is None: MayaChemToolsDataDir = MiscUtil.GetMayaChemToolsLibDataPath() RxnNamesFilePath = os.path.join(MayaChemToolsDataDir, "ReactionNamesAndSMIRKS.csv") MiscUtil.PrintInfo( "\nRetrieving reaction names and SMIRKS patterns from file %s" % (RxnNamesFilePath)) if not os.path.exists(RxnNamesFilePath): MiscUtil.PrintError("The reaction names file, %s, doesn't exist.\n" % (RxnNamesFilePath)) Delimiter = ',' QuoteChar = '"' IgnoreHeaderLine = True RxnLinesWords = MiscUtil.GetTextLinesWords(RxnNamesFilePath, Delimiter, QuoteChar, IgnoreHeaderLine) RxnNamesMap['Names'] = [] RxnNamesMap['SMIRKSPattern'] = {} for LineWords in RxnLinesWords: Name = LineWords[0] SMIRKSPattern = LineWords[1] if Name in RxnNamesMap['SMIRKSPattern']: MiscUtil.PrintWarning("Ignoring duplicate reaction name: %s..." % Name) else: RxnNamesMap['Names'].append(Name) RxnNamesMap['SMIRKSPattern'][Name] = SMIRKSPattern if not len(RxnNamesMap['Names']): MiscUtil.PrintError( "Failed to retrieve any reaction names and SMIRKS patterns...") MiscUtil.PrintInfo( "Total number of reactions present in reaction names and SMIRKS file: %d" % (len(RxnNamesMap['Names'])))
def InitializePlotTypesInfo(): """Initialize information for generating plots. """ PlotTypesInfo = {} PlotTypesInfo["Types"] = [] PlotTypesInfo["PhiPsiDensityFiles"] = {} PlotTypesInfo["PhiPsiDensityInfo"] = {} PlotTypesInfo["PhiPsiContourInfo"] = {} PlotTypesInfo["Titles"] = {} PlotTypesInfo["DrawXLabel"] = {} PlotTypesInfo["DrawYLabel"] = {} PlotTypesInfo["Limits"] = {} PlotTypesInfo["MajorTickPositions"] = {} PlotTypesInfo["MajorTickLabels"] = {} PlotTypesInfo["MinorTickPositions"] = {} PlotTypesInfo["Levels"] = {} PlotTypesInfo["Colors"] = {} PlotTypesInfo["Outfiles"] = {} PlotTypesInfo["PhiAngles"] = {} PlotTypesInfo["PsiAngles"] = {} MayaChemToolsDataDir = MiscUtil.GetMayaChemToolsLibDataPath() # Setup contour colors for supported default schemes... ContourColorSchemes = {} ContourColorSchemes["General"] = { "MuttedColorShades1": ["#FFFFFF", "#EBF1DE", "#C3D69B"], "MuttedColorShades2": ["#FFFFFF", "#EBF1DE", "#D7E4BD"], "BrightColorShades": ["#FFFFFF", "#B3E8FF", "#7FD9FF"] } ContourColorSchemes["Glycine"] = { "MuttedColorShades1": ["#FFFFFF", "#FDEADA", "#FAC090"], "MuttedColorShades2": ["#FFFFFF", "#FDEADA", "#FCD5B5"], "BrightColorShades": ["#FFFFFF", "#FFE8C5", "#FFCC7F"] } ContourColorSchemes["Proline"] = { "MuttedColorShades1": ["#FFFFFF", "#E6E0EC", "#B3A2C7"], "MuttedColorShades2": ["#FFFFFF", "#E6E0EC", "#CCC1DA"], "BrightColorShades": ["#FFFFFF", "#D0FFC5", "#7FFF8C"] } ContourColorSchemes["PreProline"] = { "MuttedColorShades1": ["#FFFFFF", "#DCE6F2", "#95B3D7"], "MuttedColorShades2": ["#FFFFFF", "#DCE6F2", "#B9CDE5"], "BrightColorShades": ["#FFFFFF", "#B3E8FF", "#7FD9FF"] } if re.match("^MuttedColorShades1$", OptionsInfo["LevelsAndColorsScheme"], re.I): DefaultColorScheme = "MuttedColorShades1" elif re.match("^MuttedColorShades2$", OptionsInfo["LevelsAndColorsScheme"], re.I): DefaultColorScheme = "MuttedColorShades2" elif re.match("^BrightColorShades$", OptionsInfo["LevelsAndColorsScheme"], re.I): DefaultColorScheme = "BrightColorShades" else: MiscUtil.PrintError( "The color scheme, %s, specified using \"--levelsAndColorsScheme\" option is not supported." % (OptionsInfo["LevelsAndColorsScheme"])) for Type in ["General", "Glycine", "Proline", "PreProline"]: PlotTypesInfo["Types"].append(Type) # Setup phi and psi density file... DensityFile = os.path.join(MayaChemToolsDataDir, "PhiPsiDensity%s.csv" % (Type)) if not os.path.exists(DensityFile): MiscUtil.PrintError( "The phi and psi density file file, %s, doesn't exist. This is required for generating contour plots.\n" % (DensityFile)) PlotTypesInfo["PhiPsiDensityFiles"][Type] = DensityFile # Setup plot title... Title = Type if re.match("^PreProline$", Type, re.I): Title = "pre-Proline" PlotTypesInfo["Titles"][Type] = Title # Setup flags for drawing axis labels... DrawXLabel, DrawYLabel = [True] * 2 if not OptionsInfo["MultipleOutFiles"]: # Turn off XLabel for plots in first row... DrawXLabel = False if re.match("^(General|Glycine)$", Type, re.I) else True # Turn off YLabel for plots in second column... DrawYLabel = False if re.match("^(Glycine|PreProline)$", Type, re.I) else True PlotTypesInfo["DrawXLabel"][Type] = DrawXLabel PlotTypesInfo["DrawYLabel"][Type] = DrawYLabel # Setup limits... (MinLimit, MaxLimit) = [-180, 180] PlotTypesInfo["Limits"][Type] = [MinLimit, MaxLimit] # Setup major tick labels and positions... MajorTickPositions = list( range(MinLimit, MaxLimit, OptionsInfo["TicksMajorInterval"])) MajorTickPositions.append(MaxLimit) MajorTickLabels = ["%s" % Position for Position in MajorTickPositions] PlotTypesInfo["MajorTickPositions"][Type] = MajorTickPositions PlotTypesInfo["MajorTickLabels"][Type] = MajorTickLabels # Setup minor tick positions without any labels... MinorTickPositions = list( range(MinLimit, MaxLimit, OptionsInfo["TicksMinorInterval"])) MinorTickPositions.append(MaxLimit) PlotTypesInfo["MinorTickPositions"][Type] = MinorTickPositions # Setup contour levels and colors... Levels = [] Colors = [] if re.match("^General$", Type, re.I): Levels = [0.0, 0.0005, 0.02, 1.0] Colors = ContourColorSchemes[Type][DefaultColorScheme] elif re.match("^Glycine$", Type, re.I): Levels = [0.0, 0.002, 0.02, 1.0] Colors = ContourColorSchemes[Type][DefaultColorScheme] elif re.match("^Proline$", Type, re.I): Levels = [0.0, 0.002, 0.02, 1.0] Colors = ContourColorSchemes[Type][DefaultColorScheme] elif re.match("^PreProline$", Type, re.I): Levels = [0.0, 0.002, 0.02, 1.0] Colors = ContourColorSchemes[Type][DefaultColorScheme] PlotTypesInfo["Levels"][Type] = Levels PlotTypesInfo["Colors"][Type] = Colors OptionsInfo["PlotTypesInfo"] = PlotTypesInfo