[RegExp] Adapter une regexp Perl vers du Java
Hello
Auparavant, je scannais une banque de données avec un script Perl pour en retirer une information. Voici le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#!/usr/bin/perl -w
use strict;
my $s = "Semaphorin 3F";
open FILE, "< /homegldavid/Snippets/Bases/GeneOntology/gene_association.goa_human" or die "$!\n";
while(<FILE>){
if(/\t$s/){
my $current = $_;
if($current =~ /(GO:[0-9]+)/){
print "$1\n";
}
}
}
close FILE; |
Simple, non ?
Maintenant, je veux faire l'équivalent en Java :
Code:
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
|
import java.io.*;
import java.util.regex.*;
public class SearchOntology {
public static void main(String[] args) throws FileNotFoundException, IOException {
String prot = new String("Semaphorin 3F");
File f = new File("/home/dbourgais/Snippets/Bases/GeneOntology/gene_association.goa_human");
BufferedReader bf = new BufferedReader(new FileReader(f));
String current;
while((current=bf.readLine())!=null){
if(current.contains(prot)){
System.out.println(""+current);
String s = current;
Pattern p = Pattern.compile("(GO:[0-9]+)");
Matcher m = p.matcher(s);
if(m.matches()){
System.out.println(""+m.group());
}
}
}
}
} |
Mais apparemment, il ne me retourne pas le résultat de ma recherche.
Me suis-je trompé avec les appels vers Matcher ?
Merci d'avance de vos infos.
@++