gff_loader.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. function tripal_core_load_gff3() {
  3. $gff_file = drupal_get_path('module', 'tripal_core').'/test.gff3';
  4. $lines = file($gff_file,FILE_SKIP_EMPTY_LINES);
  5. $i = 0;
  6. // get the controlled vocaubulary that we'll be using. The
  7. // default is the 'sequence' ontology
  8. $vocab = 'sequence';
  9. $sql = "SELECT * FROM cv WHERE name = '%s'";
  10. $cv = db_fetch_object(db_query($sql,$vocab));
  11. foreach ($lines as $line_num => $line) {
  12. $i++;
  13. $cols = explode("\t",$line);
  14. if(sizeof($cols) > 9){
  15. print "ERROR: improper number of columns on line $i\n";
  16. return '';
  17. }
  18. // get the column values
  19. $seqid = $cols[0];
  20. $source = $cols[1];
  21. $type = $cols[2];
  22. $start = $cols[3];
  23. $end = $cols[4];
  24. $score = $cols[5];
  25. $strand = $cols[6];
  26. $phase = $cols[7];
  27. $attrs = explode(";",$cols[8]); // split by a semi-colon
  28. // break apart each of the attributes
  29. $tags = array();
  30. foreach($attrs as $attr){
  31. $attr = rtrim($attr);
  32. $attr = ltrim($attr);
  33. if(strcmp($attr,'')==0){
  34. continue;
  35. }
  36. if(!preg_match('/^[^\=]+\=[^\=]+$/',$attr)){
  37. print "ERROR: attribute is not correctly formatted on line $i: $attr\n";
  38. return '';
  39. }
  40. // break apart each tag
  41. $tag = explode("=",$attr); // split by equals sign
  42. // multiple instances of an attribute are separated by commas
  43. $tags[$tag[0]] = explode(",",$tag[1]); // split by comma
  44. }
  45. // remove URL encoding
  46. // add the feature
  47. $sql = "INSERT INTO {feature} (organism_id, name, uniquename, residues, seqlen,".
  48. " is_obsolete, type_id)".
  49. " VALUES(%d,'%s','%s','%s',%d, %s, ".
  50. " (SELECT cvterm_id ".
  51. " FROM {CVTerm} CVT ".
  52. " INNER JOIN CV ON CVT.cv_id = CV.cv_id ".
  53. " WHERE CV.name = 'sequence' and CVT.name = '%s'))";
  54. }
  55. return '';
  56. }