Kaynağa Gözat

Ensure bam/cram submits and job adds it to JBrowse.

Lacey Sanderson 4 yıl önce
ebeveyn
işleme
c5045a0ccc

+ 20 - 7
tripal_jbrowse_mgmt/includes/tripal_jbrowse_mgmt.api.inc

@@ -734,18 +734,31 @@ function tripal_jbrowse_mgmt_get_instance_properties($id) {
    if (empty($file) && empty($index) && empty($local_directory)) {
      form_set_error('Please provide a local directory path or upload files.');
    }
-   elseif (empty($file) && empty($index) && !empty($local_dir)) {
-     if (!file_exists($local_dir)) {
+   elseif (empty($file) && empty($index) && !empty($local_directory)) {
+     if (!file_exists($local_directory)) {
        form_set_error('The directory provided does not exist.');
      }
      else {
-       if (!is_dir($local_dir)) {
+       if (!is_dir($local_directory)) {
          form_set_error('file_path',
            'The file provided is not a directory.');
        }
        else {
-         $file_file = glob($local_dir . '/*.[vcf.gz][bam][cram]');
-         $file_index = glob($local_dir . '/*.[csi][tbi][idx][bai][cram][crai]');
+         // Retrieve an array of data file and index
+         // to ensure there is only one of each.
+         $file_file = [];
+         $file_index = [];
+         foreach (scandir($local_directory) as $f) {
+           $fparts = pathinfo($f);
+
+           if (in_array($fparts['extension'], ['gz', 'bam', 'cram'])) {
+             $file_file[] = $f;
+           }
+           if (in_array($fparts['extension'], ['csi','tbi','idx','bai','crai'])) {
+             $file_index[] = $f;
+           }
+         }
+         // CHECK: Only a single data file and index.
          if (count($file_file) != 1 || count($file_index) != 1) {
            form_set_error('file_path',
              'Please provide a directory with exactly one data file and one index file.');
@@ -777,7 +790,7 @@ function tripal_jbrowse_mgmt_get_instance_properties($id) {
    else {
      $file_data_uploaded = tripal_jbrowse_mgmt_upload_file('file');
      if (!$file_data_uploaded) {
-       form_set_error('file', 'Unable to upload file');
+       form_set_error('file', 'Unable to upload file.');
      }
      else {
        $file_data_uploaded = tripal_jbrowse_mgmt_move_file($file_data_uploaded, $path);
@@ -791,7 +804,7 @@ function tripal_jbrowse_mgmt_get_instance_properties($id) {
 
      $index_uploaded = tripal_jbrowse_mgmt_upload_file('file2');
      if (!$index_uploaded) {
-       form_set_error('file2', 'Unable to upload file');
+       form_set_error('file2', 'Unable to upload index.');
      }
      else {
        $index_uploaded = tripal_jbrowse_mgmt_move_file($index_uploaded, $path);

+ 4 - 3
tripal_jbrowse_mgmt/includes/tripal_jbrowse_mgmt_commands.inc

@@ -116,14 +116,14 @@ function tripal_jbrowse_mgmt_cmd_add_track($track) {
       $directory = 'bam';
       $file_name = $track->file;
       if (is_dir($track->file)) {
-        $file_name = glob($track->file . '/' . '*.[bam][cram]')[0];
+        $file_name = glob($track->file . '/' . '*.bam')[0];
+        if (!$file_name) { $file_name = glob($track->file . '/' . '*.cram')[0]; }
       }
-      $file_name = pathinfo($file_name)['basename'];
 
       $track_in_json = [
         'label' => tripal_jbrowse_mgmt_make_slug($track->label),
         'key' => $track->label,
-        'urlTemplate' => $directory . '/' . $file_name,
+        'urlTemplate' => $directory . '/' . pathinfo($file_name)['basename'],
         'type' => 'JBrowse/View/Track/Alignment2',
       ];
 
@@ -136,6 +136,7 @@ function tripal_jbrowse_mgmt_cmd_add_track($track) {
           $track_in_json['storeClass'] = 'JBrowse/Store/SeqFeature/CRAM';
           break;
       }
+      $json['tracks'][] = $track_in_json;
       tripal_jbrowse_mgmt_save_json($instance, $json);
       break;
 

+ 1 - 1
tripal_jbrowse_mgmt/includes/tripal_jbrowse_mgmt_tracks.form.inc

@@ -165,7 +165,7 @@ function tripal_jbrowse_mgmt_add_track_form_validate($form, &$form_state) {
       $form_state = tripal_jbrowse_mgmt_validate_folder_upload($file, $index, $path, $form_state);
       break;
 
-    case 'carm':
+    case 'cram':
       $index = $_FILES['files']['tmp_name']['file2'];
       $form_state = tripal_jbrowse_mgmt_validate_folder_upload($file, $index, $path, $form_state);
       break;