# Contains rules for well defined clusters, containing all expected functional parts

# Cutoffs and neighbourhoods are given in kilobases

DEFINE ANY_KS AS (PKS_KS or ene_KS or mod_KS or hyb_KS or itr_KS or tra_KS)

RULE T1PKS
    CATEGORY PKS
    COMMENT Type-I PKS
    CUTOFF 20
    NEIGHBOURHOOD 20
    CONDITIONS cds(PKS_AT and ANY_KS)

RULE T2PKS
    CATEGORY PKS
    COMMENT Type-II PKS
    RELATED t2pks2, ksIII
    CUTOFF 20
    NEIGHBOURHOOD 35  # lysolipin (AM492533) has a range of ~33kb
    CONDITIONS t2ks and t2clf

RULE T3PKS
    CATEGORY PKS
    COMMENT Type-III PKS
    CUTOFF 20
    NEIGHBOURHOOD 20
    CONDITIONS Chal_sti_synt_C or Chal_sti_synt_N

RULE transAT-PKS
    CATEGORY PKS
    CUTOFF 45  # kirromycin (CP006259) has a range of ~42kb
    NEIGHBOURHOOD 20
    CONDITIONS cds(PKS_AT and not ANY_KS)
               and (
                cds(ATd and ANY_KS)
                # handle CP001511 5k-30k as per https://doi.org/10.1002/ange.201709056
                or cds(tra_KS and PP-binding)
               )

RULE hglE-KS
    CATEGORY PKS
    COMMENT heterocyst glycolipid synthase like PKS such as KC489223
    CUTOFF 20
    NEIGHBOURHOOD 20
    CONDITIONS hglE or hglD

RULE prodigiosin
    CATEGORY PKS
    COMMENT Serratia-type nontraditional PKS prodigiosin biosynthesis pathway
            like BGC0000258 and BGC0000259
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS PPDK_N and AMP-binding and PP-binding and PKS_KS

RULE arylpolyene
    CATEGORY other
    CUTOFF 20
    NEIGHBOURHOOD 20
    CONDITIONS APE_KS1 or APE_KS2

RULE resorcinol
    CATEGORY other
    CUTOFF 20
    NEIGHBOURHOOD 20
    CONDITIONS DarB

RULE ladderane
    CATEGORY other
    CUTOFF 20
    NEIGHBOURHOOD 20
    CONDITIONS ladderane

RULE PUFA
    CATEGORY other
    COMMENT PolyUnsaturated Fatty Acid
    CUTOFF 20
    NEIGHBOURHOOD 20
    CONDITIONS PUFA_KS

RULE NRPS
    CATEGORY NRPS
    COMMENT non-ribosomal peptide synthase
    CUTOFF 20
    NEIGHBOURHOOD 20
    CONDITIONS cds(Condensation and (AMP-binding or A-OX))

RULE CDPS
    CATEGORY NRPS
    COMMENT tRNA-dependent cyclodipeptide synthases like BGC0001468 aka
            bicyclomycin
    RELATED Flavoprotein, 2OG-FeII_Oxy, p450
    CUTOFF 5
    NEIGHBOURHOOD 10
    CONDITIONS CDPS or cycdipepsynth

RULE thioamide-NRP
    CATEGORY NRPS
    COMMENT thioamide-containing non-ribosomal peptides (https://doi.org/10.1002/anie.201807970)
    RELATED Chor_lyase
    CUTOFF 20
    NEIGHBOURHOOD 20
    CONDITIONS ATP-grasp and AMP-binding and PP-binding and
                (DUF98 or Orn_Arg_deC_N or Orn_DAP_Arg_deC)

RULE NAPAA
    CATEGORY NRPS
    COMMENT non-alpha poly-amino acids like e-Polylysin
            (https://doi.org/10.1101/2020.07.24.220772)
    CUTOFF 5
    NEIGHBOURHOOD 15
    CONDITIONS AMP-binding and PP-binding and TIGR02353

RULE terpene
    CATEGORY terpene
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS Terpene_synth or Terpene_synth_C or phytoene_synt or Lycopene_cycl
               or terpene_cyclase or NapT7 or fung_ggpps or fung_ggpps2
               or trichodiene_synth or TRI5

RULE lanthipeptide-class-i
    CATEGORY RiPP
    COMMENT Class I lanthipeptide clusters like nisin (HM219853)
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS (LANC_like and (Lant_dehydr_N or Lant_dehydr_C))
               and not (YcaO or TIGR03882) # because then it'd be a thiopeptide

RULE lanthipeptide-class-ii
    CATEGORY RiPP
    COMMENT Clas II lanthipeptide clusters like mutacin II (U40620)
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS cds(LANC_like and DUF4135)

RULE lanthipeptide-class-iii
    CATEGORY RiPP
    COMMENT Clas III lanthipeptide clusters like labyrinthopeptin (FN178622)
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS micKC
               and not PKS_KS  # that'd be a lipolanthine

RULE lanthipeptide-class-iv
    CATEGORY RiPP
    COMMENT Class IV lanthipeptide clusters like venezuelin (HQ328852)
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS cds(LANC_like and Pkinase)
               and not micKC  # that'd be a class III

RULE lanthipeptide-class-v
    CATEGORY RiPP
    COMMENT Glycosylated lanthipeptide/linaridin hybrids like MT210103
    RELATED Flavoprotein, Glycos_transf_1, Glycos_transf_2
    CUTOFF 20
    NEIGHBOURHOOD 20
    CONDITIONS APH and HopA1

RULE lipolanthine
    CATEGORY RiPP
    COMMENT Lanthipeptide class containing N-terminal fatty acids such as MG673929
            See https://doi.org/10.1038/s41589-018-0068-6
    RELATED PKS_KS, AMP-binding, PP-binding
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS micKC and Flavoprotein

RULE RiPP-like
    CATEGORY RiPP
    CUTOFF 20
    NEIGHBOURHOOD 5
    CONDITIONS strepbact or Antimicrobial14 or Bacteriocin_IId or BacteriocIIc_cy
               or Bacteriocin_II or Bacteriocin_IIi or Lactococcin
               or Antimicrobial17 or Lactococcin_972 or Bacteriocin_IIc
               or LcnG-beta or Cloacin or Linocin_M18
               or TIGR03651 or TIGR03693
               or TIGR03601 or TIGR03795
               or TIGR03975 or DUF692 or TIGR01193

RULE thiopeptide
    CATEGORY RiPP
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS (YcaO or TIGR03882)
               and ((thio_amide and (PF06968 or PF04055 or PF07366))
                         or Lant_dehydr_C or Lant_dehydr_N
                         or PF07366 or PF06968 or PF04055)
               or thiostrepton

RULE thioamitides
    CATEGORY RiPP
    COMMENT Thioamitide RiPPs as described in https://doi.org/10.1093/nar/gkz192
            and found on JOBF01000011
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS (YcaO or TIGR03882)
               and TfuA

RULE linaridin
    CATEGORY RiPP
    COMMENT Linear arid peptides like cypemycin (HQ148718) and salinipeptin (MG788286)
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS cypemycin or cypI

RULE cyanobactin
    CATEGORY RiPP
    COMMENT Cyanobactins like patellamide (AY986476)
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS cyanobactin_synth or TIGR03678

RULE glycocin
    CATEGORY RiPP
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS glycocin or sublancin

RULE LAP
    CATEGORY RiPP
    COMMENT Linear azol(in)e-containing peptides like goadsporin (AB205012) or
            microcin B17 (FM877811)
    RELATED TIGR04424, TIGR01408
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS (((goadsporin_like or PF00881 or TIGR03605)
               and (YcaO or TIGR03882 or TIGR03604))
               or TIGR03603   # peptide maturase
               or TIGR03602)  # precursor
               and not cyanobactin_synth

RULE lassopeptide
    CATEGORY RiPP
    CUTOFF 10
    NEIGHBOURHOOD 10
    CONDITIONS PF13471 and Asn_synthase or micJ25 or mcjC

RULE sactipeptide
    CATEGORY RiPP
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS subtilosin or thuricin or TIGR04404 or
               Subtilosin_A or skfc

RULE bottromycin
    CATEGORY RiPP
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS botH

RULE microviridin
    CATEGORY RiPP
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS mvd or mvnA

RULE proteusin
    CATEGORY RiPP
    COMMENT Highly modified large leader peptide RiPP class containing
            polytheonamide (JX456532.1) and landornamide (NZ_KB235904.1:469950-493649)
            Unfortunately, there is no real class-defining enzyme, but all
            known precursors are similar to a nitrile hydratase
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS PoyD          # polytheonamide-like rSAM
               or TIGR03793  # nitrile hydratase-like leader peptide

DEFINE rSAM_with_SPASM AS cds(PF04055 and (TIGR04085 or SPASM))

DEFINE ANY_RRE AS minimum(1,
   [Lanthipeptide_LanB_RRE, Stand_Alone_Lasso_RRE, Lasso_Fused_RRE, Thiopeptide_F_RRE, PqqD_RRE,
    Cyanobactin_D_RRE, Bottromycin_Methyltransferase_RRE, Proteusin_Methyltransferase_RRE,
    Proteusin_Epimerase_RRE, Heterocycloanthracin_C_RRE, Plantazolicin_C_RRE,
    Goadsporin_CD_RRE, Cytolysin_C_RRE, NHLP_CD_RRE, Mycofactocin_RRE,
    Pantocin_Microcin_RRE, Subtilosin_rSAM_RRE,Thurincin_rSAM_RRE, Thuricin_rSAM_RRE,
    Other_Sactipeptide_rSAM_RRE, Streptide_RRE, Quinohemoprotein_rSAM_RRE,
    Ranthipeptide_rSAM_RRE, Trifolitoxin_RRE, Thiaglutamate_G_RRE,
    Thiaglutamate_I_RRE, Thiaglutamate_B_RRE, PlpY_RRE
   ])

RULE ranthipeptide
    CATEGORY RiPP
    COMMENT Cys-rich peptides (aka. SCIFF: six Cys in fourty-five) like in CP001581:3481278-3502939
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS TIGR03973 or SCIFF or  # precursors
               (
                rSAM_with_SPASM and ANY_RRE
                and not (TIGR01716 or              # avoid co-detecting RaS-RiPPs
                         subtilosin or             # avoid co-detecting sactipeptides
                         TIGR02111 or TIGR03966 or # avoid co-detecting redox-cofactor clusers
                         TIGR04103 or              # avoid co-detecting spliceotides
                         YcaO or TIGR03882)        # avoid co-detecting thiopeptides
               )

RULE redox-cofactor
    CATEGORY RiPP
    COMMENT Redox-cofactors such as PQQ (NC_021985:1458906-1494876)
            and mycofactocin (NC_000962:781831-803332)
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS rSAM_with_SPASM and (TIGR02111 or TIGR03966) and ANY_RRE

RULE epipeptide
    CATEGORY RiPP
    COMMENT D-amino-acid containing RiPPs such as yydF (D78193)
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS TIGR04078 and yydH

RULE cyclic-lactone-autoinducer
    CATEGORY RiPP
    COMMENT agrD-like cyclic lactone autoinducer peptides (AF001782)
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS TIGR04223 or AgrB

RULE spliceotide
    CATEGORY RiPP
    COMMENT RiPPs containing plpX type spliceases (NZ_KB235920:17899-42115)
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS TIGR04103 and TIGR03798

RULE blactam
    CATEGORY other
    COMMENT beta-lactam
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS BLS or CAS or tabtoxin

RULE amglyccycl
    CATEGORY other
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS strH or strK1 or strK2 or NeoL or DOIS or ValA or SpcFG
               or SpcDK_glyc or salQ

RULE aminocoumarin
    CATEGORY other
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS novK or novJ or novI or novH or SpcDK_cou

RULE siderophore
    CATEGORY other
    CUTOFF 20
    NEIGHBOURHOOD 5
    CONDITIONS IucA_IucC

RULE ectoine
    CATEGORY other
    CUTOFF 20
    NEIGHBOURHOOD 5
    CONDITIONS ectoine_synt

RULE NAGGN
    CATEGORY other
    COMMENT N-acetylglutaminylglutamine amide cluster (Psyr_3747-Psyr_3749 in NC_007005.1)
            see https://doi.org/10.1128/AEM.00686-10
    CUTOFF 10
    NEIGHBOURHOOD 5
    CONDITIONS (TIGR03104 or cds(GATase_7 and Asn_synthase))  # amidotransferase ggnA
               and TIGR03103                                  # acetyltransferase ggnB
               and (TIGR03106 or Peptidase_M42)               # aminopeptidase ggnC

RULE butyrolactone
    CATEGORY other
    CUTOFF 20
    NEIGHBOURHOOD 5
    CONDITIONS AfsA

RULE indole
    CATEGORY other
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS indsynth or dmat or indole_PTase

RULE nucleoside
    CATEGORY other
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS LipM or LipV or LipU or ToyB or TunD or pur6 or pur10 or nikJ or nikO or truD

RULE phosphoglycolipid
    CATEGORY other
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS MoeO5 or moeGT

RULE melanin
    CATEGORY other
    CUTOFF 20
    NEIGHBOURHOOD 5
    CONDITIONS melC

RULE oligosaccharide
    CATEGORY saccharide
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS minimum(3,[Glycos_transf_1,Glycos_transf_2,Glyco_transf_28,MGT,DUF1205])
               and minscore(MGT, 150)

RULE furan
    CATEGORY other
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS mmyO or AvrD

RULE hserlactone
    CATEGORY other
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS Autoind_synth

RULE phenazine
    CATEGORY other
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS phzB

RULE phosphonate
    CATEGORY other
    CUTOFF 20
    NEIGHBOURHOOD 20
    CONDITIONS phosphonates

RULE guanidinotides
    CATEGORY RiPP
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS pgm1 and pgm_amidino

RULE other
    CATEGORY other
    CUTOFF 20
    NEIGHBOURHOOD 20
    CONDITIONS LmbU or Neocarzinostat or fom1 or bcpB
               or frbD or mitE or vlmB or prnB or CaiA or bacilysin or orf2_PTase

RULE acyl_amino_acids
    CATEGORY other
    CUTOFF 30
    NEIGHBOURHOOD 30
    CONDITIONS NasY

RULE PBDE
    CATEGORY other
    COMMENT polybrominated diphenyl ethers (PBDEs) such as KX588877
    CUTOFF 10
    NEIGHBOURHOOD 10
    CONDITIONS FMO-like and p450 and DUF98

RULE PpyS-KS
    CATEGORY PKS
    COMMENT PPY-like specific ketosynthases (PPYSKS) such as KT373879
    CUTOFF 10
    NEIGHBOURHOOD 10
    CONDITIONS PpyS

RULE betalactone
    CATEGORY other
    COMMENT beta-lactone containing protease inhibitor such as KY249118
    RELATED RimK, Abhydrolase_6
    CUTOFF 10
    NEIGHBOURHOOD 10
    CONDITIONS HMGL-like and AMP-binding

RULE RaS-RiPP
    CATEGORY RiPP
    COMMENT streptide-like thioether-bond RiPPs such as FR875178
            See https://pubs.acs.org/doi/10.1021/jacs.8b11060 and
            https://pubs.acs.org/doi/full/10.1021/jacs.8b10266
    CUTOFF 5
    NEIGHBOURHOOD 10
    CONDITIONS PF04055 and TIGR01716

RULE fungal-RiPP
    CATEGORY RiPP
    COMMENT fungal RiPP with POP or UstH peptidase types and a modification
    CUTOFF 15
    NEIGHBOURHOOD 15
    CONDITIONS (pop or ustH) and (p450 or TP_methylase)
               or
               #DUF3228 seems to be quite specific and also co-occurs with these peptidases
               DUF3328 and (Peptidase_S41 or Peptidase_S28 or pop or ustH)

RULE tropodithietic-acid
    CATEGORY other
    COMMENT tropodithietic acid like cluster as described in DOI: 10.1039/C4CC01924E
    CUTOFF 20
    NEIGHBOURHOOD 10
    CONDITIONS (GST_N_3 or GST_C)
               and (Acyl-CoA_dh_N or Acyl-CoA_dh_M or Acyl-CoA_dh_1)
               and TIGR02278

RULE pyrrolidine
    CATEGORY other
    COMMENT Pyrrolidines like described in BGC0001510
            See https://dx.doi.org/10.1073.pnas.1701361114
    CUTOFF 10
    NEIGHBOURHOOD 10
    CONDITIONS Glycos_transf_1 and Alpha-amylase and Aminotran_3 and DXP_synthase_N
