• Publicidad

Procesando archivo de Pubchem

Perl aplicado a la bioinformática

Procesando archivo de Pubchem

Notapor dandy » 2014-03-18 11:11 @507

Hola, estoy intentando procesar varios archivos que he obtenido de Pubchem. Este es un ejemplo del tipo de archivos:
Sintáxis: [ Descargar ] [ Ocultar ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE eSummaryResult PUBLIC "-//NLM//DTD esummary v1 20060131//EN" "http://eutils.ncbi.nlm.nih.gov/eutils/dtd/20060131/esummary-v1.dtd">
  3. <eSummaryResult>
  4. <DocSum>
  5.         <Id>1811</Id>
  6.         <Item Name="AssayName" Type="String">Experimentally measured binding affinity data derived from PDB</Item>
  7.         <Item Name="AssayDescription" Type="String">This data entry provides a collection of experimentally measured binding affinity data (Kd, Ki, and IC50), which are exclusively for the protein-ligand complexes available in the Protein Data Bank (PDB). All of the binding affinity data compiled in this data entry are cited from original references. This work is contributed by the PDBbind database.</Item>
  8.         <Item Name="ReadoutCount" Type="Integer">0</Item>
  9.         <Item Name="SourceNameList" Type="List">
  10.                 <Item Name="string" Type="String">Shanghai Institute of Organic Chemistry</Item>
  11.         </Item>
  12.         <Item Name="ActiveSidCount" Type="Integer">3073</Item>
  13.         <Item Name="ActivityOutcomeMethod" Type="String">other</Item>
  14.         <Item Name="InactiveSidCount" Type="Integer">0</Item>
  15.         <Item Name="InconclusiveSidCount" Type="Integer">0</Item>
  16.         <Item Name="TotalSidCount" Type="Integer">3073</Item>
  17.         <Item Name="XRefDburlList" Type="List">
  18.                 <Item Name="string" Type="String">http://www.sioc.ac.cn/esioc/1.htm</Item>
  19.         </Item>
  20.         <Item Name="XRefAsurlList" Type="List">
  21.                 <Item Name="string" Type="String">http://www.pdbbind.org.cn</Item>
  22.                 <Item Name="string" Type="String">http://www.pdbbind.org.cn</Item>
  23.         </Item>
  24.         <Item Name="ModifyDate" Type="Date">2010/07/01 00:00</Item>
  25.         <Item Name="DepositDate" Type="Date">2009/06/08 00:00</Item>
  26.         <Item Name="HoldUntilDate" Type="Date">1/01/01 00:00</Item>
  27.         <Item Name="AID" Type="Integer">1811</Item>
  28.         <Item Name="TotalCidCount" Type="Integer">2438</Item>
  29.         <Item Name="ActiveCidCount" Type="Integer">2438</Item>
  30.         <Item Name="ProteinTargetList" Type="List">
  31.                 <Item Name="ProteinTarget" Type="Structure">
  32.                         <Item Name="Name" Type="String">Chain 1, Crystal Structure Of Gamma-Chymotrypsin In Complex With 7- Hydroxycoumarin</Item>
  33.                         <Item Name="GI" Type="Integer">17943055</Item>
  34. <DocSum>
  35.  
  36. <DocSum>
  37.         <Id>648328</Id>
  38.         <Item Name="AssayName" Type="String">Cytotoxicity against human A549 cells at 10 to 100 uM after 48 hrs by MTT assay</Item>
  39.         <Item Name="AssayDescription" Type="String">Title: New antitumor compounds from Carya cathayensis. Abstract: A new lignan (7R,8S,8'R)-4,4',9-trihydroxy-7,9'-epoxy-8,8'-lignan, and three new phenolics, carayensin-A, carayensin-B, and carayensin-C, together with 13 known compounds were isolated from the shells of Carya cathayensis. Their chemical structures were established mainly by 1D and 2D NMR techniques and mass spectrometry. All the compounds were evaluated for cytotoxicity against several human tumor types including human colorectal cancer cell lines (HCT-116, HT-29), human lung cancer cell line (A549), and human breast cancer cell line (MCF-7). The compounds 1, 5, 6, and 16 are considered to be potential as antitumor agents, which could significantly inhibit the cancer cell growth in a dose-dependent manner.</Item>
  40.         <Item Name="ReadoutCount" Type="Integer">5</Item>
  41.         <Item Name="SourceNameList" Type="List">
  42.                 <Item Name="string" Type="String">ChEMBL</Item>
  43.         </Item>
  44.         <Item Name="ActiveSidCount" Type="Integer">8</Item>
  45.         <Item Name="ActivityOutcomeMethod" Type="String"></Item>
  46.         <Item Name="InactiveSidCount" Type="Integer">0</Item>
  47.         <Item Name="InconclusiveSidCount" Type="Integer">0</Item>
  48.         <Item Name="TotalSidCount" Type="Integer">8</Item>
  49.         <Item Name="XRefDburlList" Type="List">
  50.                 <Item Name="string" Type="String">http://www.ebi.ac.uk/chembldb/</Item>
  51.         </Item>
  52.         <Item Name="XRefAsurlList" Type="List">
  53.                 <Item Name="string" Type="String">http://www.ebi.ac.uk/chembldb/index.php/assay/inspect/805776</Item>
  54.                 <Item Name="string" Type="String">http://www.ebi.ac.uk/chembldb/index.php/assay/inspect/805776</Item>
  55.                 <Item Name="string" Type="String">http://www.ebi.ac.uk/chembldb/index.php/assay/inspect/805776</Item>
  56.         </Item>
  57.         <Item Name="ModifyDate" Type="Date">2013/07/07 00:00</Item>
  58.         <Item Name="DepositDate" Type="Date">2012/09/09 00:00</Item>
  59.         <Item Name="HoldUntilDate" Type="Date">1/01/01 00:00</Item>
  60.         <Item Name="AID" Type="Integer">648328</Item>
  61.         <Item Name="TotalCidCount" Type="Integer">8</Item>
  62.         <Item Name="ActiveCidCount" Type="Integer">8</Item>
  63.         <Item Name="ProteinTargetList" Type="List"></Item>
  64. </DocSum>
  65.  
  66. <DocSum>
  67.         <Id>399372</Id>
  68.         <Item Name="AssayName" Type="String">Deterrent activity against Perknaster fuscus assessed as induction of sustained retractions of tube-feet by sea-star deterrent assay</Item>
  69.         <Item Name="AssayDescription" Type="String">Title: Purine and nucleoside metabolites from the Antarctic sponge Isodictya erinacea. Abstract: The bright yellow sponge Isodictya erinacea is one of several chemically defended sponges found on the benthos of McMurdo Sound, Antarctica. An investigation of the metabolites from this sponge has resulted in the isolation of purine and nucleoside metabolites, including the previously unreported erinacean (1) and p-hydroxybenzaldehyde. The latter metabolite has been demonstrated to cause a feeding deterrence behavior in Perknaster fuscus, the major predator of antarctic sponges.</Item>
  70.         <Item Name="ReadoutCount" Type="Integer">5</Item>
  71.         <Item Name="SourceNameList" Type="List">
  72.                 <Item Name="string" Type="String">ChEMBL</Item>
  73.         </Item>
  74.         <Item Name="ActiveSidCount" Type="Integer">1</Item>
  75.         <Item Name="ActivityOutcomeMethod" Type="String"></Item>
  76.         <Item Name="InactiveSidCount" Type="Integer">6</Item>
  77.         <Item Name="InconclusiveSidCount" Type="Integer">0</Item>
  78.         <Item Name="TotalSidCount" Type="Integer">7</Item>
  79.         <Item Name="XRefDburlList" Type="List">
  80.                 <Item Name="string" Type="String">http://www.ebi.ac.uk/chembldb/</Item>
  81.         </Item>
  82.         <Item Name="XRefAsurlList" Type="List">
  83.                 <Item Name="string" Type="String">http://www.ebi.ac.uk/chembldb/index.php/assay/inspect/547401</Item>
  84.                 <Item Name="string" Type="String">http://www.ebi.ac.uk/chembldb/index.php/assay/inspect/547401</Item>
  85.         </Item>
  86.         <Item Name="ModifyDate" Type="Date">2013/05/08 00:00</Item>
  87.         <Item Name="DepositDate" Type="Date">2010/05/26 00:00</Item>
  88.         <Item Name="HoldUntilDate" Type="Date">1/01/01 00:00</Item>
  89.         <Item Name="AID" Type="Integer">399372</Item>
  90.         <Item Name="TotalCidCount" Type="Integer">7</Item>
  91.         <Item Name="ActiveCidCount" Type="Integer">1</Item>
  92.         <Item Name="ProteinTargetList" Type="List"></Item>
  93. </DocSum>
  94.  
  95. </eSummaryResult>
Coloreado en 0.005 segundos, usando GeSHi 1.0.8.4


Lo que está entre </DocSum> corresponde a una entrada en la base de datos. A mi me interesa extraer las líneas que contengan:

<Item Name="GI" Type="Integer">

Eso es sencillo. El problema que tengo es que antes de obtener esas líneas quiero evitar las entradas que contengan la siguiente línea:

<Item Name="AssayName" Type="String">Experimentally measured binding affinity data derived from PDB</Item>

Para ello he escrito el siguiente código:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #! /usr/bin/perl
  2.  
  3. my $file=$ARGV[0];
  4.  
  5. open FILE, $file;
  6.  
  7. my @array=<FILE>;
  8. chomp @array;
  9. close FILE;
  10. my $skip_pdb='<Item Name="AssayName" Type="String">Experimentally measured binding affinity data derived from PDB</Item>';
  11. my $gi_id='<Item Name="GI" Type="Integer">';
  12.  
  13. for ($i=0;$i<scalar(@array); $i++){
  14.  
  15.       if ($array[$i]=~ '<DocSum>'){
  16.      
  17.       my $j=$i+2;
  18.       my $k=$i+29;
  19.           if ($array[$j]=~ $skip_pdb){
  20.          
  21.           next;
  22.           }
  23.          
  24.          
  25.           print "$array[$k]\n";
  26.          
  27.          
  28.       }
  29. }
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4

El código funciona, es posible extraer las líneas deseadas (las cuales están en $k). El problema surge cuando intento utilar otros archivos ya que la estructura no es fija, es decir, la línea deseada no siempre está en "$i + 29". ¿Alguna sugerencia?

¡Saludos y gracias!
dandy
Perlero nuevo
Perlero nuevo
 
Mensajes: 3
Registrado: 2014-03-18 10:45 @489

Publicidad

Re: Procesando archivo de Pubchem

Notapor explorer » 2014-03-18 11:40 @527

Bienvenido a los foros de Perl en Español, dandy.

Si el problema es extraer solamente las líneas que contengan <Item Name="GI" Type="Integer">, pues podemos hacer solo eso:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl
  2.  
  3. my $file = $ARGV[0];
  4. open FILE, $file;
  5.  
  6. while (<FILE>) {                                # para todas las líneas del archivo
  7.     if (/<Item Name="GI" Type="Integer">/) {    # si contiene lo que buscamos
  8.         print;                                  # imprimimos toda la línea
  9.     }
  10. }
  11.  
  12. close FILE;
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4

Podemos hacer una mejora: mostrar solo el valor numérico de la línea.
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl
  2.  
  3. my $file = $ARGV[0];
  4. open FILE, $file;
  5.  
  6. while (<FILE>) {                                        # para todas las líneas del archivo
  7.     if (/<Item Name="GI" Type="Integer">\s*(\d+)/) {    # si contiene lo que buscamos
  8.         print "$1\n";                                   # imprimimos el valor numérico capturado con los paréntesis
  9.     }
  10. }
  11.  
  12. close FILE;
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4

A propósito, los patrones de las expresiones regulares suelen estar rodeados por delimitadores (como los '/' que he usado yo).
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14476
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Procesando archivo de Pubchem

Notapor dandy » 2014-03-18 12:00 @542

Hola, gracias por tu respuesta, pero como mencionaba, extraer solo las líneas con <Item Name="GI" Type="Integer" es fácil, tal como lo muestras en tu código.

El detalle es que no deseo extraer todas.

Quiero evitar las líneas con <Item Name="GI" Type="Integer" pero que están entre los dos <DocSum> (principio y final) más <Item Name="AssayName" Type="String">Experimentally measured binding affinity data derived from PDB</Item>.

Es decir, todas las <Item Name="GI" Type="Integer" asociadas a la línea Type="String">Experimentally measured binding affinity data derived from PDB</Item>, son un solo grupo (delimitado por los dos <DocSum>) y no las deseo incluir (esto es constante en todos los archivos).

Mi código es lo que trata de hacer (línea 15 a la 22), evitar el grupo "Experimentally measured binding affinity data derived from PDB", todas sus líneas Item Name="GI" asociadas y solo imprimir la de los otros grupos (línea 18 del código).

El problema es que en otros archivos la línea que deseo Item Name="GI" no siempre está en "$i + 29". Espero no haberte confundido.

La parte del archivo que muestro más abajo corresponde al grupo que deseo evitar.

Sintáxis: [ Descargar ] [ Ocultar ]
Using xml Syntax Highlighting
  1. <DocSum>
  2.         <Id>1811</Id>
  3.         <Item Name="AssayName" Type="String">Experimentally measured binding affinity data derived from PDB</Item>
  4.         <Item Name="AssayDescription" Type="String">This data entry provides a collection of experimentally measured binding affinity data (Kd, Ki, and IC50), which are exclusively for the protein-ligand complexes available in the Protein Data Bank (PDB). All of the binding affinity data compiled in this data entry are cited from original references. This work is contributed by the PDBbind database.</Item>
  5.         <Item Name="ReadoutCount" Type="Integer">0</Item>
  6.         <Item Name="SourceNameList" Type="List">
  7.                 <Item Name="string" Type="String">Shanghai Institute of Organic Chemistry</Item>
  8.         </Item>
  9.         <Item Name="ActiveSidCount" Type="Integer">3073</Item>
  10.         <Item Name="ActivityOutcomeMethod" Type="String">other</Item>
  11.         <Item Name="InactiveSidCount" Type="Integer">0</Item>
  12.         <Item Name="InconclusiveSidCount" Type="Integer">0</Item>
  13.         <Item Name="TotalSidCount" Type="Integer">3073</Item>
  14.         <Item Name="XRefDburlList" Type="List">
  15.                 <Item Name="string" Type="String">http://www.sioc.ac.cn/esioc/1.htm</Item>
  16.         </Item>
  17.         <Item Name="XRefAsurlList" Type="List">
  18.                 <Item Name="string" Type="String">http://www.pdbbind.org.cn</Item>
  19.                 <Item Name="string" Type="String">http://www.pdbbind.org.cn</Item>
  20.         </Item>
  21.         <Item Name="ModifyDate" Type="Date">2010/07/01 00:00</Item>
  22.         <Item Name="DepositDate" Type="Date">2009/06/08 00:00</Item>
  23.         <Item Name="HoldUntilDate" Type="Date">1/01/01 00:00</Item>
  24.         <Item Name="AID" Type="Integer">1811</Item>
  25.         <Item Name="TotalCidCount" Type="Integer">2438</Item>
  26.         <Item Name="ActiveCidCount" Type="Integer">2438</Item>
  27.         <Item Name="ProteinTargetList" Type="List">
  28.                 <Item Name="ProteinTarget" Type="Structure">
  29.                         <Item Name="Name" Type="String">Chain 1, Crystal Structure Of Gamma-Chymotrypsin In Complex With 7- Hydroxycoumarin</Item>
  30.                         <Item Name="GI" Type="Integer">17943055</Item>
  31. <DocSum>
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4
dandy
Perlero nuevo
Perlero nuevo
 
Mensajes: 3
Registrado: 2014-03-18 10:45 @489

Re: Procesando archivo de Pubchem

Notapor explorer » 2014-03-18 14:45 @656

Vale, entendido... Además, veo que las marcas no están bien puestas. La línea 34 es otra marca de inicio de <DocSum>.

Con el siguiente programa, se obtiene lo que quieres:
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl
  2.  
  3. my $file = $ARGV[0];
  4. open FILE, $file;
  5.  
  6. my $dentro_de_DocSum = 0;                               # bandera que indica nuestra posición
  7.  
  8. while (<FILE>) {                                        # para todas las líneas del archivo
  9.  
  10.     if (my $pos = m{<DocSum>} ... m{</?DocSum>}) {      # estamos dentro de <DocSum>
  11.  
  12.         if ($pos == 1) {                                # si es la primera línea del bloque
  13.             $dentro_de_DocSum = 1;                      # entonces sí estamos dentro de un bloque
  14.         }
  15.  
  16.         if (m{Experimentally measured binding affinity data derived from PDB}) {        # pero nos encontramos con esto
  17.             $dentro_de_DocSum = 0;                                                      # entonces este bloque no nos interesa
  18.         }
  19.  
  20.         if ($dentro_de_DocSum and m{<Item Name="GI" Type="Integer">\s*(\d+)}) {         # si encontramos un dato
  21.             print "$1\n";                                                               # imprimimos el valor
  22.         }
  23.     }
  24. }
  25.  
  26. close FILE;
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4
Se utiliza el operador rango (...), con una "trampa": si la línea 34 del primer XML es correcta (hay varios <DocSum> uno dentro del otro), entonces indicamos en el operador rango que nos vale como marca de fin encontrar otra marca de inicio de <DocSum>.

Si, en cambio, la marca de la línea 34 es realmente una de cierre (</DocSum>), entonces lo mejor es quitar el '?' de la segunda expresión regular del operador rango.
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14476
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Procesando archivo de Pubchem

Notapor dandy » 2014-03-18 15:31 @688

¡Funciona perfecto!

Gracias.
dandy
Perlero nuevo
Perlero nuevo
 
Mensajes: 3
Registrado: 2014-03-18 10:45 @489


Volver a Bioinformática

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 3 invitados

cron