Results 1 to 9 of 9

Thread: php preg_match_all Qt alternative

  1. #1
    Join Date
    May 2008
    Location
    Tripoli Libya
    Posts
    70
    Thanks
    10
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default php preg_match_all Qt alternative

    hi
    is there any way to use php preg_match_all in Qt .

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: php preg_match_all Qt alternative

    You'll need to be a bit more precise.

    If you are looking for regular expression handling, see QRegularExpression

    Cheers,
    _

  3. #3
    Join Date
    May 2008
    Location
    Tripoli Libya
    Posts
    70
    Thanks
    10
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: php preg_match_all Qt alternative

    thanks anda the original code is looks like :
    Qt Code:
    1. while (preg_match_all("$pattren","$vary","$res")==1){$x++;}
    To copy to clipboard, switch view to plain text mode 
    the problem is both QRegExp::exactMatch and regular QString.contains some times gives diffrent resault .

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: php preg_match_all Qt alternative

    Can you given an example?

    Cheers,
    _

  5. #5
    Join Date
    May 2008
    Location
    Tripoli Libya
    Posts
    70
    Thanks
    10
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: php preg_match_all Qt alternative

    i'm trying to port biophp "Microsatellite repeats finder"
    this is the link for demo http://collegesoftwareconnection.com...satellites.php

    and this is the source code in php :
    Qt Code:
    1. <html>
    2. <head>
    3. <meta charset="UTF-8">
    4. <title></title>
    5. </head>
    6. <body>
    7. <?php
    8.  
    9. function includeN_1($primer,$minus) {
    10. $code=".".substr($primer,1);
    11. $wpos=1;
    12. while ($wpos<strlen($primer)-$minus){
    13. $code.="|".substr($primer,0,$wpos).".".substr($primer,$wpos+1);
    14. $wpos++;
    15. }
    16. return ($code);
    17. }
    18.  
    19.  
    20.  
    21. function includeN_2($primer,$minus) {
    22. $max=strlen($primer)-$minus;
    23. $code="";
    24. for($i=0;$i<$max;$i++){
    25. for($j=0;$j<$max-$i-1;$j++){
    26. $code.="|".substr($primer,0,$i).".";
    27. $resto=substr($primer,$i+1);
    28. $code.=substr($resto,0,$j).".".substr($resto,$j+1);
    29. }
    30. }
    31.  
    32. $code=substr($code,1);
    33. return ($code);
    34. }
    35.  
    36. function includeN_3($primer,$minus) {
    37. $max=strlen($primer)-$minus;
    38. $code="";
    39. for($i=0;$i<$max;$i++){
    40. for($j=0;$j<$max-$i-1;$j++){
    41. $code.="|".substr($primer,0,$i).".";
    42. $resto=substr($primer,$i+1);
    43. $code.=substr($resto,0,$j).".".substr($resto,$j+1);
    44. }
    45. }
    46. $code=substr($code,1);
    47. return ($code);
    48. }
    49.  
    50. function find_microsatellite_repeats($sequence,$min_length,$max_length,$min_repeats,$min_length_of_MR,$mismatches_allowed){
    51. $len_seq=strlen($sequence);
    52. $counter=0;
    53. for ($i=0;$i<$len_seq-3;$i++){
    54. for ($j=$min_length;$j<$max_length+1;$j++){
    55. if (($i+$j)>$len_seq){break;}
    56. $sub_seq=substr($sequence,$i,$j);
    57.  
    58. $len_sub_seq=strlen ($sub_seq);
    59. $mismatches=floor($len_sub_seq*$mismatches_allowed/100);
    60. if ($mismatches==1){$sub_seq_pattern=includeN_1($sub_seq,0);}
    61. elseif ($mismatches==2){$sub_seq_pattern=includeN_2($sub_seq,0);}
    62. elseif ($mismatches==3){$sub_seq_pattern=includeN_3($sub_seq,0);}
    63. else {$sub_seq_pattern=$sub_seq;}
    64.  
    65. $matches=1;
    66.  
    67. while (preg_match_all("/($sub_seq_pattern)/",substr($sequence,($i+$j*$matches),$j),$out)==1){$matches++;}
    68. echo $matches;
    69. if ($matches>=$min_repeats and ($j*$matches)>=$min_length_of_MR){
    70.  
    71. $results[$counter]["start_position"]=$i;
    72. $results[$counter]["length"]=$j;
    73. $results[$counter]["repeats"]=$matches;
    74. $results[$counter]["sequence"]=substr($sequence,$i,$j*$matches);
    75. $counter++;
    76. $i+=$j*$matches;
    77. }
    78. }
    79. }
    80. return ($results);
    81. }
    82. //echo includeN_2("saifab",1);
    83. //echo "\n";
    84. //echo includeN_3("saifab",1);
    85.  
    86. $sequence="AACAATGCCATGATGATGATTATTACGACACAACAACACCGCGCTTGACGGCGGCGGATGGATGCCGCGATCAGACGTTCAACGCCCACGTAACGTAACGCAACGTAACCTAACGACACTGTTAACGGTACGAT";
    87. //print_r( find_microsatellite_repeats($sequence,2,6,3,6,0));
    88. find_microsatellite_repeats($sequence,2,6,3,6,0);
    89. ?>
    90. </body>
    91. </html>
    To copy to clipboard, switch view to plain text mode 

    and this is my c++ port :
    Qt Code:
    1. QString includeN_1(const QString & primer,int minus)
    2. {
    3. QString code="."+primer.mid(1);
    4. int wpos=1;
    5.  
    6. while (wpos<primer.size()-minus){
    7. code+="|"+primer.mid(0,wpos)+"."+primer.mid(wpos+1);
    8. wpos++;
    9. }
    10. return code;
    11. }
    12.  
    13. QString includeN_2(const QString & primer,int minus)
    14. {
    15. int max=primer.size()-minus;
    16. QString code="";
    17. for(int i=0;i<max;i++){
    18. for(int j=0; j<max-i-1;j++){
    19. code+="|"+primer.mid(0,i)+".";
    20. QString resto=primer.mid(i+1);
    21. code+=resto.mid(0,j)+"."+resto.mid(j+1);
    22.  
    23. }//j
    24. }
    25. code=code.mid(1);
    26. return code;
    27. }
    28.  
    29. QString includeN_3(const QString & primer,int minus)
    30. {
    31. int max=primer.size()-minus;
    32. QString code="";
    33. for(int i=0;i<max;i++){
    34. for(int j=0;j<max-i-1;j++){
    35. code+="|"+primer.mid(0,i)+".";
    36. QString resto=primer.mid(i+1);
    37. code+=resto.mid(0,j)+"."+resto.mid(j+1);
    38. }
    39. }
    40. code=code.mid(1);
    41. return code;
    42. }
    43.  
    44. void FindMicrosatelliteRepeats(QString &seq,int MinLen,int MaxLen,int MinRepeat,int MRMinLen,int MismatchesAllowed)
    45. {
    46.  
    47. int len_seq=seq.size();
    48. int counter=0;
    49. // QString sub_seq_pattern;
    50. for (int i=0;i<len_seq-3;i++){
    51. for (int j=MinLen;j<MaxLen+1;j++){
    52.  
    53. if ((i+j)>len_seq)
    54. {break;}
    55. QString sub_seq_pattern;
    56. QString sub_seq=seq.mid(i,j) ;
    57.  
    58. int len_sub_seq=sub_seq.size();
    59.  
    60. int mismatches=floor(len_sub_seq*MismatchesAllowed/100);
    61.  
    62. if (mismatches==1)
    63. {
    64. sub_seq_pattern=includeN_1(sub_seq,0);
    65. }
    66. else if (mismatches==2){sub_seq_pattern=includeN_2(sub_seq,0);}
    67. else if (mismatches==3){sub_seq_pattern=includeN_3(sub_seq,0);}
    68. else {sub_seq_pattern=sub_seq;}
    69. int matches=1;
    70. if(seq.mid(i+j*matches,j)==sub_seq_pattern==1)
    71. matches++;
    72.  
    73. // qDebug()<<matches;
    74. if(matches >=MinRepeat && (j*matches) >=MRMinLen)
    75. {
    76. qDebug()<<"yes";
    77. qDebug()<<"start postion = "<<i;
    78. qDebug()<<"length = "<<j;
    79. qDebug()<<"repeats = "<<matches;
    80. qDebug()<<"sequence = "<<seq.mid(i,j*matches);
    81. counter++;
    82. i+=j*matches;
    83.  
    84. }//j
    85. }
    86.  
    87. }//i
    88.  
    89. }
    90.  
    91.  
    92. //================================================================
    93.  
    94. int main(int argc, char *argv[])
    95. {
    96. QCoreApplication a(argc, argv);
    97.  
    98. QString primer="AACAATGCCATGATGATGATTATTACGACACAACAACACCGCGCTTGACGGCGGCGGATGGATGCCGCGATCAGACGTTCAACGCCCACGTAACGTAACGCAACGTAACCTAACGACACTGTTAACGGTACGAT";
    99.  
    100. FindMicrosatelliteRepeats(primer,2,6,3,6,0);
    101. return a.exec();
    102. }
    To copy to clipboard, switch view to plain text mode 
    the problem in variable matches dont give the same waht the original do (due to preg_match_all).
    regards
    Last edited by alrawab; 23rd June 2014 at 15:46.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: php preg_match_all Qt alternative

    Hmm, your C++ code doesn't seem to have any usage of regular expressions or I am not seeing it.

    Cheers,
    _

  7. #7
    Join Date
    May 2008
    Location
    Tripoli Libya
    Posts
    70
    Thanks
    10
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: php preg_match_all Qt alternative

    yes the original code comparing the pattrern with chunks from the original string
    seq.mid(i+j*matches,j).contains( QRegExp("["+sub_seq_pattern+"]") will gives the same effect.
    Last edited by alrawab; 23rd June 2014 at 20:38.

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: php preg_match_all Qt alternative

    Ah, ok. Misunderstanding. I thought there was still an open question.

    Cheers,
    _

  9. The following user says thank you to anda_skoa for this useful post:

    alrawab (23rd June 2014)

  10. #9
    Join Date
    May 2008
    Location
    Tripoli Libya
    Posts
    70
    Thanks
    10
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: php preg_match_all Qt alternative

    thanks for your help the problem is solved and this the php port of Microsatellite repeats finder
    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QtCore>
    3.  
    4. //======================================================================
    5. //**************************Find Microsatellite Repeats****************
    6. //======================================================================
    7. QString includeN_1(const QString & primer,int minus)
    8. {
    9. QString code="."+primer.mid(1);
    10. int wpos=1;
    11.  
    12. while (wpos<primer.size()-minus){
    13. code+="|"+primer.mid(0,wpos)+"."+primer.mid(wpos+1);
    14. wpos++;
    15. }
    16. return code;
    17. }
    18. //----------------------------------------------------------
    19. QString includeN_2(const QString & primer,int minus)
    20. {
    21. int max=primer.size()-minus;
    22. QString code="";
    23. for(int i=0;i<max;i++){
    24. for(int j=0; j<max-i-1;j++){
    25. code+="|"+primer.mid(0,i)+".";
    26. QString resto=primer.mid(i+1);
    27. code+=resto.mid(0,j)+"."+resto.mid(j+1);
    28.  
    29. }//j
    30. }
    31. code=code.mid(1);
    32. return code;
    33. }
    34. //---------------------------------------------------------------------
    35. QString includeN_3(const QString & primer,int minus)
    36. {
    37. int max=primer.size()-minus;
    38. QString code="";
    39. for(int i=0;i<max;i++){
    40. for(int j=0;j<max-i-1;j++){
    41. code+="|"+primer.mid(0,i)+".";
    42. QString resto=primer.mid(i+1);
    43. code+=resto.mid(0,j)+"."+resto.mid(j+1);
    44. }
    45. }
    46. code=code.mid(1);
    47. return code;
    48. }
    49. //--------------------------------------------------------------------------
    50. void FindMicrosatelliteRepeats(QString &sequence,int min_length,int max_length,int min_repeats,int min_length_of_MR,int mismatches_allowed)
    51. {
    52. int len_seq= sequence.size();
    53. int counter=0;
    54.  
    55. for (int i=0;i<len_seq-3;i++){
    56.  
    57. for (int j=min_length;j<max_length+1;j++){
    58.  
    59. if ((i+j)>len_seq){break;}
    60. QString sub_seq=sequence.mid(i,j);
    61. int len_sub_seq=sub_seq.size();
    62. int mismatches=floor(len_sub_seq*mismatches_allowed/100);
    63. QString sub_seq_pattern;
    64. if (mismatches==1){sub_seq_pattern=includeN_1(sub_seq,0);}
    65. else if(mismatches==2){sub_seq_pattern=includeN_2(sub_seq,0);}
    66. else if(mismatches==3){sub_seq_pattern=includeN_3(sub_seq,0);}
    67. else {sub_seq_pattern=sub_seq;}
    68. int matches=1;
    69. while(sequence.mid((i+j*matches),j).contains(QRegExp("("+sub_seq_pattern+")"))==true)matches++;
    70.  
    71.  
    72. if (matches>=min_repeats && (j*matches)>=min_length_of_MR){
    73. qDebug()<<"start_position"<<i;
    74. qDebug()<<"length"<<j;
    75. qDebug()<<"repeats"<<matches;
    76. qDebug()<<"sequence"<<sequence.mid(i,j*matches);
    77. counter++;
    78. i+=j*matches;
    79. }
    80.  
    81.  
    82. }//j
    83.  
    84. }//i
    85.  
    86.  
    87. }
    88.  
    89. //========================================================================
    90.  
    91. int main(int argc, char *argv[])
    92. {
    93. QCoreApplication a(argc, argv);
    94.  
    95. QString primer="AACAATGCCATGATGATGATTATTACGACACAACAACACCGCGCTTGACGGCGGCGGATGGATGCCGCGATCAGACGTTCAACGCCCACGTAACGTAACGCAACGTAACCTAACGACACTGTTAACGGTACGAT";
    96.  
    97. FindMicrosatelliteRepeats(primer,2,6,3,6,0);
    98. return a.exec();
    99. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by alrawab; 23rd June 2014 at 23:27.

Similar Threads

  1. simplified alternative
    By wirasto in forum Newbie
    Replies: 4
    Last Post: 23rd October 2013, 08:07
  2. Is there a C++ alternative to QML/Qt Quick?
    By Awareness in forum Newbie
    Replies: 6
    Last Post: 30th April 2013, 23:57
  3. QAssistantClient in Qt 4.7.3 alternative
    By Raghaw in forum Qt Programming
    Replies: 2
    Last Post: 11th May 2011, 07:45
  4. alternative for strtok_s in QT??
    By Gokulnathvc in forum Newbie
    Replies: 1
    Last Post: 15th April 2011, 12:14
  5. alternative to COM??
    By TheKedge in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 15:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.