Jump to content

Reading specific parts of a text file in PHP.


vidyashankara

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.