Perl program to print previous set of lines once a pattern is matched

Hi all,

I have a text data file. My aim here is to find line called *FIELD* AV for every record and print lines after that till *FIELD* RF. But here I want first 3 to four lines for very record as well. FIELD AV is some where in between for very record. SO I am not sure how to retrieve lines in this case. AN example of a record is given below. If the program finds FIELD AV for a record, I want to get first 3 lines say till FIELD TX for very record and lines after FIELD AV till FIELD RF. I want a perl program

CODE

#!/usr/bin/perl
open(DATA, 'generecordsdata.txt');
# or die("Could not open generecordsdata file.");
open(MYOUTPUT, ">mutationsdata.txt");
# or die ("could not open mutationsdata file.");
while(<DATA>)
{
if (/^\*FIELD\*\sAV$/)
{
print $_=<DATA> until /^\*FIELD\*\sRF$/ ;
}
}
close(MYOUTPUT);
close(DATA);
*100710 CHOLINERGIC RECEPTOR, NICOTINIC, BETA POLYPEPTIDE 1; CHRNB1
;;CHRNB;;
ACETYLCHOLINE RECEPTOR, MUSCLE, BETA SUBUNIT; ACHRB
*FIELD* TX
For background information on the acetylcholine receptor, see CHRNA1
(100690).
BIOCHEMICAL FEATURES
By recording images at liquid-helium temperatures and applying a
computational method to correct for distortions, Miyazawa et al. (2003)
reported the crystal structure of the acetylcholine receptor of the
Torpedo electric ray at a resolution of 4 angstroms. The pore is shaped
by an inner ring of 5 alpha helices, which curve radially to create a
tapering path for the ions, and an outer ring of 15 alpha helices, which
coil around each other and shield the inner ring from the lipids. The
gate is a constricting hydrophobic girdle at the middle of a lipid
bilayer, formed by weak interactions between neighboring inner helices.
When acetylcholine enters the ligand-binding domain, it triggers
rotations of the protein chains on opposite sides of the entrance to the
pore. These rotations are communicated through the inner helices and
open the pore by breaking the girdle apart.
MAPPING
In the Torpedo (electric ray), the 4 subunits of the AChR show
conspicuous sequence homology. Heidmann et al. (1986) analyzed
restriction fragment length polymorphisms of each of the 4 subunits of
muscle nicotinic acetylcholine receptor in crosses between 2 mouse
species. They found that the beta subunit gene is located on mouse
chromosome 11. The beta subunit gene was found to be tightly linked with
the locus encoding the different isoforms (embryonic, perinatal and
adult) of the myosin heavy chain genes which are located on mouse
chromosome 11. In man these genes are located on chromosome 17p
(160730), arguing from likely homology of synteny. The beta subunit of
the acetylcholine receptor may be coded by a gene on human 17p also.
Using a panel of human-rodent somatic cell hybrids segregating human
chromosomes, Beeson et al. (1989) demonstrated that the CHRNB locus is
on human chromosome 17. Beeson et al. (1990) regionalized the CHRNB gene
to 17p12-p11 by in situ hybridization.
MOLECULAR GENETICS
In a patient with slow-channel congenital myasthenic syndrome (601462),
Engel et al. (1996) identified a heterozygous mutation in the CHRNB1
gene (100710.0001).
In 3 sibs with congenital myasthenic syndrome associated with
acetylcholine receptor deficiency (608931), Quiram et al. (1999)
identified compound heterozygosity for 2 mutations in the CHRNB1 gene
(100710.0003; 100710.0004).
*FIELD* AV
.0001
MYASTHENIC SYNDROME, CONGENITAL, SLOW-CHANNEL
CHRNB1, VAL266MET
In a 19-year-old female with slow-channel congenital myasthenic syndrome
(601462), Engel et al. (1996) identified a heterozygous 796G-A
transition in exon 8 of the CHRNB1 gene, resulting in a val266-to-met
(V266M) substitution in a conserved residue in the M2 transmembrane
domain of the AChR-beta subunit. Functional expression studies showed
that the V266M mutation slowed the rate of AChR channel closure and
increased the apparent affinity for ACh. The mutation also caused
pathologic channel openings even in the absence of ACh, resulting in a
leaky channel. Cationic overload of the postsynaptic region caused an
endplate myopathy.
.0002
MYASTHENIC SYNDROME, CONGENITAL, SLOW-CHANNEL
CHRNB1, LEU263MET
In a 32-year-old male with slow-channel congenital myasthenic syndrome
(601462), Gomez et al. (1996) identified a heterozygous C-to-A
transversion in the CHRNB1 gene, resulting in a leu263-to-met (L263M)
substitution. Functional expression studies showed that the L263M
mutation interrupted the leucine ring of the AChR channel gate, causing
an 8-fold increase in channel open time and resulting in severe endplate
myopathy and extensive remodeling of the postsynaptic membrane. The
pronounced abnormalities in neuromuscular synaptic architecture and
function and the muscle fiber damage and weakness resulting from a
single point mutation were a dramatic example of a mutation having a
dominant gain of function and of hereditary excitotoxicity.
.0003
MYASTHENIC SYNDROME, CONGENITAL, ASSOCIATED WITH ACETYLCHOLINE RECEPTOR
DEFICIENCY
CHRNB1, 9-BP DEL, NT1276 
In 3 sibs with congenital myasthenia and AChR deficiency (608931),
Quiram et al. (1999) identified compound heterozygosity for 2 mutations
in the CHRNB1 gene. One mutation was a 9-bp deletion (1276del9) in exon
10, resulting in a deletion of 3 codons (426-428) in the long
cytoplasmic loop between the M3 and M4 domains of the protein. The
second mutation was a skipping of exon 8 (100710.0004), truncating the
beta subunit before its M1 transmembrane domain and abolishing surface
expression of pentameric AChR. By coexpressing the 3-codon deleted
subunit with combinations of wildtype subunits in HEK293 cells, Quiram
et al. (1999) demonstrated that the mutation impairs AChR assembly by
disrupting a specific interaction between the beta and delta (100720)
subunits. Studies with related deletion and missense mutations indicated
that secondary structure in this region of the beta subunit is crucial
for interaction with the delta subunit. The findings implied that the
mutated residues are positioned at the interface between beta and delta
subunits and demonstrated contribution of this local region of the long
cytoplasmic loop to AChR assembly.
.0004
MYASTHENIC SYNDROME, CONGENITAL, ASSOCIATED WITH ACETYLCHOLINE RECEPTOR
DEFICIENCY
CHRNB1, EX8DEL 
See 100710.0003 and Quiram et al. (1999).
*FIELD* SA
Beeson et al. (1989)
*FIELD* RF

Hi, could you post a sample of what you would want your output to look like given your input sample?

Hi Scrutinizer,

The expected output is given below:

*100710 CHOLINERGIC RECEPTOR, NICOTINIC, BETA POLYPEPTIDE 1; CHRNB1
;;CHRNB;;
ACETYLCHOLINE RECEPTOR, MUSCLE, BETA SUBUNIT; ACHRB
*FIELD* AV
.0001
MYASTHENIC SYNDROME, CONGENITAL, SLOW-CHANNEL
CHRNB1, VAL266MET
In a 19-year-old female with slow-channel congenital myasthenic syndrome
(601462), Engel et al. (1996) identified a heterozygous 796G-A
transition in exon 8 of the CHRNB1 gene, resulting in a val266-to-met
(V266M) substitution in a conserved residue in the M2 transmembrane
domain of the AChR-beta subunit. Functional expression studies showed
that the V266M mutation slowed the rate of AChR channel closure and
increased the apparent affinity for ACh. The mutation also caused
pathologic channel openings even in the absence of ACh, resulting in a
leaky channel. Cationic overload of the postsynaptic region caused an
endplate myopathy.
.0002
MYASTHENIC SYNDROME, CONGENITAL, SLOW-CHANNEL
CHRNB1, LEU263MET
In a 32-year-old male with slow-channel congenital myasthenic syndrome
(601462), Gomez et al. (1996) identified a heterozygous C-to-A
transversion in the CHRNB1 gene, resulting in a leu263-to-met (L263M)
substitution. Functional expression studies showed that the L263M
mutation interrupted the leucine ring of the AChR channel gate, causing
an 8-fold increase in channel open time and resulting in severe endplate
myopathy and extensive remodeling of the postsynaptic membrane. The
pronounced abnormalities in neuromuscular synaptic architecture and
function and the muscle fiber damage and weakness resulting from a
single point mutation were a dramatic example of a mutation having a
dominant gain of function and of hereditary excitotoxicity.
.0003
MYASTHENIC SYNDROME, CONGENITAL, ASSOCIATED WITH ACETYLCHOLINE RECEPTOR
DEFICIENCY
CHRNB1, 9-BP DEL, NT1276 
In 3 sibs with congenital myasthenia and AChR deficiency (608931),
Quiram et al. (1999) identified compound heterozygosity for 2 mutations
in the CHRNB1 gene. One mutation was a 9-bp deletion (1276del9) in exon
10, resulting in a deletion of 3 codons (426-428) in the long
cytoplasmic loop between the M3 and M4 domains of the protein. The
second mutation was a skipping of exon 8 (100710.0004), truncating the
beta subunit before its M1 transmembrane domain and abolishing surface
expression of pentameric AChR. By coexpressing the 3-codon deleted
subunit with combinations of wildtype subunits in HEK293 cells, Quiram
et al. (1999) demonstrated that the mutation impairs AChR assembly by
disrupting a specific interaction between the beta and delta (100720)
subunits. Studies with related deletion and missense mutations indicated
that secondary structure in this region of the beta subunit is crucial
for interaction with the delta subunit. The findings implied that the
mutated residues are positioned at the interface between beta and delta
subunits and demonstrated contribution of this local region of the long
cytoplasmic loop to AChR assembly.
.0004
MYASTHENIC SYNDROME, CONGENITAL, ASSOCIATED WITH ACETYLCHOLINE RECEPTOR
DEFICIENCY
CHRNB1, EX8DEL 
See 100710.0003 and Quiram et al. (1999).
*FIELD* SA
Beeson et al. (1989)
*FIELD* RF