Jump to content


Photo

Reading specific parts of a text file in PHP.


  • Please log in to reply
1 reply to this topic

#1 vidyashankara

vidyashankara
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 16 May 2006 - 09:20 PM

I have a text file named 123.pdb. It contains
HEADER    LIPID TRANSPORT                         23-SEP-97   1AV1              
TITLE     CRYSTAL STRUCTURE OF HUMAN APOLIPOPROTEIN A-I                         
COMPND    MOL_ID: 1;                                                            
COMPND   2 MOLECULE: APOLIPOPROTEIN A-I;                                        
COMPND   3 CHAIN: A, B, C, D;                                                   
COMPND   4 FRAGMENT: LIPID-BINDING DOMAIN;                                      
COMPND   5 SYNONYM: APO A-I;                                                    
COMPND   6 ENGINEERED: YES;                                                     
COMPND   7 MUTATION: N-TERMINAL MET, DEL(1-43)                                  
SOURCE    MOL_ID: 1;                                                            
SOURCE   2 ORGANISM_SCIENTIFIC: HOMO SAPIENS;                                   
SOURCE   3 ORGANISM_COMMON: HUMAN;                                              
SOURCE   4 TISSUE: BLOOD;                                                       
SOURCE   5 EXPRESSION_SYSTEM: ESCHERICHIA COLI;                                 
SOURCE   6 EXPRESSION_SYSTEM_STRAIN: BL21 (DE3);                                
SOURCE   7 EXPRESSION_SYSTEM_VECTOR_TYPE: PLASMID;                              
SOURCE   8 EXPRESSION_SYSTEM_VECTOR: PGEMEX                                     
KEYWDS    LIPOPROTEIN, LIPID TRANSPORT, CHOLESTEROL METABOLISM,                 
KEYWDS   2 ATHEROSCLEROSIS, HDL, LCAT-ACTIVATION                                
EXPDTA    X-RAY DIFFRACTION  

I am writing a code to read this file and echo the output. Like.
Description:

Name: CRYSTAL STRUCTURE OF HUMAN APOLIPOPROTEIN A-I
PDB ID : 1av1
Number of Chains: A, B, C, D;
Experimental Method: X-RAY DIFFRACTION 

I have the following code.
$id = $_GET["file"];
$file = "$id.pdb";
$contents = file_get_contents($file);
$title=  preg_replace('/^(?!TITLE).*?(?:\n|$)/m','',$contents);
$exp=  preg_replace('/^(?!EXPDTA).*?(?:\n|$)/m','',$contents);
$chain=  preg_replace('/^(?!COMPND   3 CHAIN:).*?(?:\n|$)/m','',$contents);

echo "Description:<p>";

echo "Name: $title<br>";
echo "PDB ID : $id<br>";
echo "Number of Chains: $chain<br>";
echo "Experimental Method:$exp<br>";

This outputs
Description:

Name: TITLE CRYSTAL STRUCTURE OF HUMAN APOLIPOPROTEIN A-I
PDB ID : 1av1
Number of Chains: COMPND 3 CHAIN: A, B, C, D;
Experimental Method:EXPDTA X-RAY DIFFRACTION 

Basically the script reads the line starting with TITLE, COMPND 3 CHAIN and EXPDTA to get this information. what do i modify in the script to omit these words? the script should just show
Name: CRYSTAL STRUCTURE OF HUMAN APOLIPOPROTEIN A-I
instead of
Name: TITLE CRYSTAL STRUCTURE OF HUMAN APOLIPOPROTEIN A-I
The starting word TITLE should be omitted.

If i say
READ from 123.pdb. The lines starting from TITLE, It must output what comes after TITLE, not the whole line.

Any help would be appreciated!
Thanks
Vidyashankara


#2 vidyashankara

vidyashankara
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 16 May 2006 - 10:06 PM

I got it, just replaced the text with a space :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users