Jump to content

Archived

This topic is now archived and is closed to further replies.

vidyashankara

Reading specific parts of a text file in PHP.

Recommended Posts

I have a text file named 123.pdb. It contains
[code]
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  
[/code]

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

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

I have the following code.
[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>";
[/code]

This outputs
[code]
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
[/code]

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.