DNA

From DMFP Require Export IndProp2.

(* https://en.wikipedia.org/wiki/Sequence_motif *)
Definition is_N_glycosylation_motif (aminos : list codon) :=
  (* Asn, followed by anything but Pro, followed by either Ser or Thr, followed by anything but Pro *)
  match aminos with
  | [ Asn; Pro; _ ; _ ]false
  | [ Asn; _ ; _ ; Pro ]false
  | [ Asn; a1 ; Ser; a2 ]is_amino a1 && is_amino a2
  | [ Asn; a1 ; Thr; a2 ]is_amino a1 && is_amino a2
  | _false
  end.

Lemma N_glycosylation_eg1 :
  is_N_glycosylation_motif [Asn; Leu; Ser; Met] = true.
Proof. (* FILL IN HERE *) Admitted.

Lemma N_glycosylation_eg2 :
  is_N_glycosylation_motif [Asn; Pro; Ser; Met] = false.
Proof. (* FILL IN HERE *) Admitted.

Lemma N_glycosylation_eg3 :
  is_N_glycosylation_motif [Asn; Trp; Thr; Pro] = false.
Proof. (* FILL IN HERE *) Admitted.

Lemma N_glycosylation_eg4 :
  is_N_glycosylation_motif [Asn; STOP; Thr; Trp] = false.
Proof. (* FILL IN HERE *) Admitted.

Inductive motif_element :=
| oneof (good : list codon)
| exclude (bad : list codon).

Definition motif : Type := list motif_element.

Definition exactly (amino : codon) : motif_element := oneof [amino].

Fixpoint any {A:Type} (p : A bool) (l : list A) : bool :=
  match l with
  | []false
  | x::l'p x || any p l'
  end.

Definition matches_motif_element (e : motif_element) (amino : codon) : bool :=
  match e with
  | oneof aminosany (eq_codon amino) aminos
  | exclude aminosis_amino amino && negb (any (eq_codon amino) aminos)
  end.

Fixpoint matches_motif (m : motif) (aminos : list codon) : bool :=
  match m with
  | []match aminos with
          | []true
          | _false
          end
  | e::m'
    match aminos with
    | []false
    | codon::aminos'matches_motif_element e codon && matches_motif m' aminos'
    end
  end.

Definition N_glycosylation : motif :=
  [exactly Asn; exclude [Pro]; oneof [Ser; Thr]; exclude [Pro]].

Inductive matches : motif list codon Prop :=
| matches_nil : matches [] []
| matches_oneof : (m : motif) (good rest: list codon) (c : codon),
    In c good matches m rest matches (oneof good :: m) (c :: rest)
| matches_exclude : (m : motif) (bad rest: list codon) (c : codon),
    c STOP ¬ (In c bad) matches m rest matches (exclude bad :: m) (c :: rest).

Lemma eq_codon_refl : c,
    eq_codon c c = true.
Proof.
  intros []; reflexivity.
Qed.

Lemma eq_codon_sym : c1 c2,
    eq_codon c1 c2 = eq_codon c2 c1.
Proof.
  intros [] []; reflexivity.
Qed.

Lemma eq_codon_iff : c1 c2,
    eq_codon c1 c2 = true c1 = c2.
Proof.
  intros [] []; split; try discriminate; try reflexivity.
Qed.

(* PRE Logic *)
Lemma any_eq__In : c l,
    any (eq_codon c) l = true In c l.
Proof.
  (* FILL IN HERE *) Admitted.

(* PRE Logic *)
Lemma any_eq__not_In : c l,
    any (eq_codon c) l = false ¬ (In c l).
Proof.
  (* FILL IN HERE *) Admitted.

(* PRE Tactics; tedious *)
Lemma is_amino_STOP : c,
    is_amino c = true c STOP.
Proof.
  (* FILL IN HERE *) Admitted.

(* PRE IndProp *)
Lemma matches_motif__matches : m aminos,
    matches_motif m aminos = true matches m aminos.
Proof.
  (* FILL IN HERE *) Admitted.

(* PRE holy terror w/o automation *)
Lemma N_glycosylation_correct : aminos,
    matches_motif N_glycosylation aminos = is_N_glycosylation_motif aminos.
Proof.
  (* FILL IN HERE *) Admitted.

(* Mon Apr 6 09:16:57 PDT 2020 *)