IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

expression régulière findall


Sujet :

Python

  1. #1
    Membre habitué
    Inscrit en
    Mars 2009
    Messages
    94
    Détails du profil
    Informations forums :
    Inscription : Mars 2009
    Messages : 94
    Points : 147
    Points
    147
    Par défaut expression régulière findall
    Bonjour,

    j'essaye désespérément de parser le texte suivant. Mon but est de faire en sorte que chaque élément entre {{ }} soit un élément d'une liste.

    J'utilise pour cela la fonction findall mais sans succès.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    re.findall("{{ ?.*|\s* ?}}",snp_page)
    Merci d'avance pour votre aide.

    Le texte à parser.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    {{Rsnum
    |rsid=1799966
    |Gene=BRCA1
    |Chromosome=17
    |position=43071077
    |Orientation=minus
    |ReferenceAllele=A
    |MissenseAllele=G
    |GMAF=0.3274
    |Assembly=GRCh38
    |GenomeBuild=38.1
    |dbSNPBuild=141
    |geno1=(A;A)
    |geno2=(A;G)
    |geno3=(G;G)
    |Gene_s=BRCA1
    }}{{ population diversity
    | geno1=(A;A)
    | geno2=(A;G)
    | geno3=(G;G)
    | CEU | 45.5 | 46.4 | 8.2
    | HCB | 46.3 | 41.9 | 11.8
    | JPT | 53.1 | 38.9 | 8.0
    | YRI | 63.3 | 35.4 | 1.4
    | ASW | 50.9 | 45.6 | 3.5
    | CHB | 46.3 | 41.9 | 11.8
    | CHD | 29.4 | 55.0 | 15.6
    | GIH | 31.6 | 50.0 | 18.4
    | LWK | 62.7 | 32.7 | 4.5
    | MEX | 41.4 | 43.1 | 15.5
    | MKK | 60.9 | 35.9 | 3.2
    | TSI | 41.2 | 51.5 | 7.2
    | HapMapRevision=28
    }}
    This SNP, a variant in the [[BRCA1]] gene, is 1 of 25 SNPs reported to represent independently minor, but cumulatively significant, increased risk for [[breast cancer]]. {{PMID|17341484}}

    For details of all 25 SNPs in this group, along with the two methods used to calculate overall risk estimates for [[breast cancer]], refer to the SNPedia [[breast cancer]] entry.

    For this particular SNP, the risk (minor) allele is (G).

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    {{ClinVar
    |rsid=1799966
    |Reversed=1
    |FwdREF=A
    |FwdALT=G,T
    |REF=T
    |ALT=A,C
    |RSPOS=41223094
    |CHROM=17
    |GMAF=0.3274
    |dbSNPBuildID=89
    |SSR=0
    |SAO=0
    |VP=0x05016800000017051f100101
    |GENEINFO=BRCA1:672
    |GENE_NAME=BRCA1
    |GENE_ID=672
    |WGT=0
    |VC=SNV
    |CLNALLE=1; 2
    |CLNHGVS=NC_000017.10:g.41223094T>A; NC_000017.10:g.41223094T>C
    |CLNSIG=2
    |CLNCUI=
    |CLNACC=
    RCV000031194.2; RCV000048673.2; RCV000034753.1; RCV000048672.2
    |Tags=RV;PM;PMC;SLO;VLD;G5A;G5;HD;GNO;KGPhase1;KGPilot123;KGPROD;OTHERKG;PH3;LSD
    |CAF=0.6726; 0.3274
    |CLNDBN=Breast-ovarian cancer, familial 1; Familial cancer of breast; not provided
    |CLNDSDB=GeneReviews:MedGen:OMIM:Orphanet; GeneReviews:MedGen:OMIM:SNOMED_CT
    |CLNDSDBID=NBK1247:C2676676:604370:145; NBK1247:C0346153:114480:254843006
    |COMMON=1
    |Disease=Breast-ovarian cancer; Familial cancer of breast; not provided
    }}
     
    {{PMID Auto
    |PMID=18559551
    |Title=Pathway analysis of single-nucleotide polymorphisms potentially associated with glioblastoma multiforme susceptibility using random forests.
    }}
     
    {{GET Evidence
    |gene=BRCA1
    |aa_change=Ser1634Gly
    |aa_change_short=S1634G
    |impact=not reviewed
    |qualified_impact=Insufficiently evaluated not reviewed
    |inheritance=unknown
    |quality_scores=Array
    |dbsnp_id=rs1799966
    |overall_frequency_n=3203
    |overall_frequency_d=10758
    |overall_frequency=0.297732
    |n_genomes=3
    |n_genomes_annotated=0
    |n_haplomes=3
    |n_articles=0
    |n_articles_annotated=0
    |qualityscore_in_silico=1
    |qualitycomment_in_silico=Y
    |gene_in_genetests=Y
    |genetests_testable=Y
    |genetests_reviewed=Y
    |nblosum100=2
    |autoscore=2
    |webscore=N
    }}
     
    {{on chip | 23andMe v1}}
    {{on chip | 23andMe v2}}
    {{on chip | 23andMe v3}}
    {{on chip | 23andMe v4}}
    {{on chip | FTDNA2}}
    {{on chip | FTDNA}}
    {{on chip | Illumina Human 1M}}

  2. #2
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Salut,

    Si je fais ça:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
     
    # -*- coding: utf-8 -*-
     
    import re
     
    txt = """
    {{Rsnum
    |rsid=1799966
    |Gene=BRCA1
    |Chromosome=17
    |position=43071077
    |Orientation=minus
    |ReferenceAllele=A
    |MissenseAllele=G
    |GMAF=0.3274
    |Assembly=GRCh38
    |GenomeBuild=38.1
    |dbSNPBuild=141
    |geno1=(A;A)
    |geno2=(A;G)
    |geno3=(G;G)
    |Gene_s=BRCA1
    }}{{ population diversity
    | geno1=(A;A)
    | geno2=(A;G)
    | geno3=(G;G)
    | CEU | 45.5 | 46.4 | 8.2
    | HCB | 46.3 | 41.9 | 11.8
    | JPT | 53.1 | 38.9 | 8.0
    | YRI | 63.3 | 35.4 | 1.4
    | ASW | 50.9 | 45.6 | 3.5
    | CHB | 46.3 | 41.9 | 11.8
    | CHD | 29.4 | 55.0 | 15.6
    | GIH | 31.6 | 50.0 | 18.4
    | LWK | 62.7 | 32.7 | 4.5
    | MEX | 41.4 | 43.1 | 15.5
    | MKK | 60.9 | 35.9 | 3.2
    | TSI | 41.2 | 51.5 | 7.2
    | HapMapRevision=28
    }}
    """
     
    rgx = re.compile('(?<={{)(.*?)(?=}})', re.DOTALL)
     
    content = rgx.findall(txt)
    data = []
    for c in content:
        data.append([i.strip() for i in c.split('|')])
     
    for d in data:
        print d
    j'obtiens ça:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    ['Rsnum', 'rsid=1799966', 'Gene=BRCA1', 'Chromosome=17', 'position=43071077', 'Orientation=minus', 'ReferenceAllele=A', 'MissenseAllele=G', 'GMAF=0.3274', 'Assembly=GRCh38', 'GenomeBuild=38.1', 'dbSNPBuild=141', 'geno1=(A;A)', 'geno2=(A;G)', 'geno3=(G;G)', 'Gene_s=BRCA1']
     
    ['population diversity', 'geno1=(A;A)', 'geno2=(A;G)', 'geno3=(G;G)', 'CEU', '45.5', '46.4', '8.2', 'HCB', '46.3', '41.9', '11.8', 'JPT', '53.1', '38.9', '8.0', 'YRI', '63.3', '35.4', '1.4', 'ASW', '50.9', '45.6', '3.5', 'CHB', '46.3', '41.9', '11.8', 'CHD', '29.4', '55.0', '15.6', 'GIH', '31.6', '50.0', '18.4', 'LWK', '62.7', '32.7', '4.5', 'MEX', '41.4', '43.1', '15.5', 'MKK', '60.9', '35.9', '3.2', 'TSI', '41.2', '51.5', '7.2', 'HapMapRevision=28']
    bon ou pas bon ?

  3. #3
    Membre habitué
    Inscrit en
    Mars 2009
    Messages
    94
    Détails du profil
    Informations forums :
    Inscription : Mars 2009
    Messages : 94
    Points : 147
    Points
    147
    Par défaut
    pas tout a fait mais c'est ma faute, je me suis mal exprimé.
    J'ai tout de même réussi à obtenir ce que je souhaitais.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    re.findall("{{\s*[(\w=.*(-;:>,\s*\|)*]*\s*}}",snp_page)

    résultat :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ['{{Rsnum\n|rsid=4986852\n|Gene=BRCA1\n|Chromosome=17\n|position=43092412\n|Orientation=plus\n|ReferenceAllele=G\n|MissenseAllele=A\n|GMAF=0.01194\n|Assembly=GRCh38\n|GenomeBuild=38.1\n|dbSNPBuild=141\n|geno1=(A;A)\n|geno2=(A;G)\n|geno3=(G;G)\n|Gene_s=BRCA1\n}}', '{{ population diversity\n| geno1=(A;A)\n| geno2=(A;G)\n| geno3=(G;G)\n| CEU | 0.0 | 8.8 | 91.2\n| HCB | 0.0 | 0.0 | 100.0\n| JPT | 0.0 | 0.0 | 100.0\n| YRI | 0.0 | 0.0 | 100.0\n| ASW | 0.0 | 5.6 | 94.4\n| CHB | 0.0 | 0.0 | 100.0\n| CHD | 0.0 | 1.0 | 99.0\n| GIH | 0.0 | 3.1 | 96.9\n| LWK | 0.0 | 0.0 | 0.0\n| MEX | 0.0 | 0.0 | 0.0\n| MKK | 0.0 | 2.6 | 97.4\n| TSI | 0.0 | 0.0 | 0.0\n| HapMapRevision=28\n}}', '{{PMID|7894493}}', '{{ neighbor\n| rsid = 1800709\n| distance = 598\n}}', '{{ neighbor\n| rsid = 2227945\n| distance = 299\n}}', '{{omim\n|id=113705\n|rsnum=4986852\n|variant=0011\n}}', '{{ClinVar\n|rsid=4986852\n|Reversed=1\n|FwdREF=G\n|FwdALT=A\n|REF=C\n|ALT=T\n|RSPOS=41244429\n|CHROM=17\n|GMAF=0.0119\n|dbSNPBuildID=113\n|SSR=0\n|SAO=1\n|VP=0x050168000000150517110101\n|GENEINFO=BRCA1:672\n|GENE_NAME=BRCA1\n|GENE_ID=672\n|WGT=0\n|VC=SNV\n|CLNALLE=1\n|CLNHGVS=NC_000017.10:g.41244429C>T\n|CLNSRC=OMIM Allelic Variant\n|CLNORIGIN=1\n|CLNSRCID=113705.0011\n|CLNSIG=255\n|CLNCUI=C2676676\n|CLNDBN=Breast-ovarian cancer, familial 1; not provided; Familial cancer of breast\n|Disease=Breast-ovarian cancer; not provided; Familial cancer of breast\n|CLNACC=RCV000019239.1; RCV000034739.1; RCV000048074.2\n|Tags=RV;PM;PMC;SLO;VLD;G5;HD;GNO;KGPhase1;KGPROD;OTHERKG;PH3;LSD;OM\n|CAF=0.9881; 0.01194\n|CLNDSDB=GeneReviews:MedGen:OMIM:Orphanet; GeneReviews:MedGen:OMIM:SNOMED_CT\n|CLNDSDBID=NBK1247:C2676676:604370:145; NBK1247:C0346153:114480:254843006\n|COMMON=1\n}}', '{{PMID Auto\n|PMID=16111488\n|Title=Phosphorylation states of cell cycle and DNA repair proteins can be altered by the nsSNPs.\n|OA=1\n}}', '{{PMID Auto\n|PMID=19644020\n|Title=Genotyping of frequent BRCA1/2 SNPs with unlabeled probes: a supplement to HRMCA mutation scanning, allowing the strong reduction of sequencing burden.\n|OA=1\n}}', '{{GET Evidence\n|gene=BRCA1\n|aa_change=Ser1040Asn\n|aa_change_short=S1040N\n|impact=pathogenic\n|qualified_impact=Insufficiently evaluated pathogenic\n|inheritance=unknown\n|quality_scores=Array\n|dbsnp_id=rs4986852\n|overall_frequency_n=185\n|overall_frequency_d=10758\n|overall_frequency=0.0171965\n|n_genomes=1\n|n_genomes_annotated=0\n|n_haplomes=1\n|n_articles=0\n|n_articles_annotated=0\n|gene_in_genetests=Y\n|in_omim=Y\n|pph2_score=0.024\n|genetests_testable=Y\n|genetests_reviewed=Y\n|nblosum100=0\n|autoscore=4\n|webscore=N\n|n_web_uneval=10\n}}', '{{on chip | 23andMe v1}}', '{{on chip | 23andMe v2}}', '{{on chip | 23andMe v3}}', '{{on chip | 23andMe v4}}', '{{on chip | FTDNA2}}', '{{on chip | FTDNA}}', '{{on chip | HumanOmni1Quad}}', '{{on chip | Illumina Human 1M}}']

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Expression régulière : findall / match
    Par Bktero dans le forum Général Python
    Réponses: 5
    Dernier message: 17/04/2012, 23h57
  2. Expression réguliére
    Par Mad_Max dans le forum Langages de programmation
    Réponses: 2
    Dernier message: 16/09/2003, 18h17
  3. [expression régulière] mon cerveau fait des noeuds..
    Par nawac dans le forum Algorithmes et structures de données
    Réponses: 7
    Dernier message: 27/05/2003, 10h06
  4. Expressions réguliéres
    Par Tooms dans le forum Langage
    Réponses: 4
    Dernier message: 06/12/2002, 18h42
  5. Réponses: 5
    Dernier message: 11/06/2002, 15h21

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo