Browse Source

Merge pull request #37 from Jiu9Shen/34-modify_add_vcf_track

34 modify add vcf track
Lacey-Anne Sanderson 5 years ago
parent
commit
43dee33963

+ 24 - 6
tripal_jbrowse_mgmt/includes/tripal_jbrowse_mgmt_commands.inc

@@ -18,7 +18,7 @@ function tripal_jbrowse_mgmt_cmd_prepare_refseq($instance) {
   if (!file_exists($path)) {
   if (!file_exists($path)) {
     if (!mkdir($path)) {
     if (!mkdir($path)) {
       throw new Exception(
       throw new Exception(
-        'Unable to make data directory! Please make sure the directory 
+        'Unable to make data directory! Please make sure the directory
       at ' . $data . ' exists and is writable by the current user.'
       at ' . $data . ' exists and is writable by the current user.'
       );
       );
     }
     }
@@ -69,21 +69,39 @@ function tripal_jbrowse_mgmt_cmd_add_track($track) {
     case 'HTMLVariants':
     case 'HTMLVariants':
       $json = tripal_jbrowse_mgmt_get_json($instance);
       $json = tripal_jbrowse_mgmt_get_json($instance);
       $directory = 'vcf';
       $directory = 'vcf';
-
       $file_name = $track->file;
       $file_name = $track->file;
       if (is_dir($track->file)) {
       if (is_dir($track->file)) {
         $file_name = glob($track->file . '/' . '*.vcf.gz')[0];
         $file_name = glob($track->file . '/' . '*.vcf.gz')[0];
+        $index_name = glob($track->file . '/' . '*.vcf.gz.[tci][bsd][ix]')[0];
       }
       }
       $file_name = pathinfo($file_name)['basename'];
       $file_name = pathinfo($file_name)['basename'];
 
 
-      $json['tracks'][] = [
-        'label' => $track->label,
+      $track_in_json = [
+        'label' => tripal_jbrowse_mgmt_make_slug($track->label),
         'key' => $track->label,
         'key' => $track->label,
-        'storeClass' => 'JBrowse/Store/SeqFeature/VCFTabix',
         'urlTemplate' => $directory . '/' . $file_name,
         'urlTemplate' => $directory . '/' . $file_name,
         'type' => $track->track_type,
         'type' => $track->track_type,
       ];
       ];
+      // check if index format and give specific (csi)urltemplate / storeClass
+      if ($index_name){
+        $index_name = pathinfo($index_name)['basename'];
+        $extension = pathinfo($index_name)['extension'];
+        switch ($extension)
+        {
+          case 'csi':
+            $track_in_json['storeClass'] = 'JBrowse/Store/SeqFeature/VCFTabix';
+            $track_in_json['csiUrlTemplate'] = $directory . '/' . $index_name;
+            break;
+          case 'tbi':
+            $track_in_json['storeClass'] = 'JBrowse/Store/SeqFeature/VCFTabix';
+            break;
+          case 'idx':
+            $track_in_json['storeClass'] = 'JBrowse/Store/SeqFeature/VCFTribble';
+            break;
+        }
+      }
 
 
+      $json['tracks'][] = $track_in_json;
       tripal_jbrowse_mgmt_save_json($instance, $json);
       tripal_jbrowse_mgmt_save_json($instance, $json);
       break;
       break;
 
 
@@ -143,7 +161,7 @@ function tripal_jbrowse_mgmt_cmd_generate_names($instance) {
   if (!file_exists($path)) {
   if (!file_exists($path)) {
     if (!mkdir($path)) {
     if (!mkdir($path)) {
       throw new Exception(
       throw new Exception(
-        'Unable to make data directory! Please make sure the directory 
+        'Unable to make data directory! Please make sure the directory
       at ' . $data . ' exists and is writable by the current user.'
       at ' . $data . ' exists and is writable by the current user.'
       );
       );
     }
     }

+ 18 - 19
tripal_jbrowse_mgmt/includes/tripal_jbrowse_mgmt_tracks.form.inc

@@ -64,7 +64,7 @@ function tripal_jbrowse_mgmt_add_track_form($form, &$form_state, $instance_id) {
 
 
   $form['data']['file2'] = [
   $form['data']['file2'] = [
     '#type' => 'file',
     '#type' => 'file',
-    '#title' => t('TBI File'),
+    '#title' => t('Index File'),
     '#states' => [
     '#states' => [
       'visible' => [
       'visible' => [
         ':input[name="file_type"]' => ['value' => 'vcf'],
         ':input[name="file_type"]' => ['value' => 'vcf'],
@@ -142,14 +142,14 @@ function tripal_jbrowse_mgmt_add_track_form_validate($form, &$form_state) {
 
 
   switch ($file_type) {
   switch ($file_type) {
     case 'vcf':
     case 'vcf':
-      $tbi = $_FILES['files']['tmp_name']['file2'];
+      $index = $_FILES['files']['tmp_name']['file2'];
       $local_dir = isset($values['dir_path']) ? $values['dir_path'] : NULL;
       $local_dir = isset($values['dir_path']) ? $values['dir_path'] : NULL;
 
 
-      if (empty($file) && empty($tbi) && empty($local_dir)) {
+      if (empty($file) && empty($index) && empty($local_dir)) {
         form_set_error('file',
         form_set_error('file',
           'Please provide a local directory path or upload files.');
           'Please provide a local directory path or upload files.');
       }
       }
-      elseif (empty($file) && empty($tbi) && !empty($local_dir)) {
+      elseif (empty($file) && empty($index) && !empty($local_dir)) {
         if (!file_exists($local_dir)) {
         if (!file_exists($local_dir)) {
           form_set_error('file_path', 'The directory provided does not exist.');
           form_set_error('file_path', 'The directory provided does not exist.');
         }
         }
@@ -160,11 +160,10 @@ function tripal_jbrowse_mgmt_add_track_form_validate($form, &$form_state) {
           }
           }
           else {
           else {
             $file_gz = glob($local_dir . '/*.vcf.gz');
             $file_gz = glob($local_dir . '/*.vcf.gz');
-            $file_tbi = glob($local_dir . '/*.vcf.gz.tbi');
-
-            if (count($file_gz) != 1 || count($file_tbi) != 1) {
+            $file_index = glob($local_dir . '/*.vcf.gz.[cti][sbd][ix]');
+            if (count($file_gz) != 1 || count($file_index) != 1) {
               form_set_error('file_path',
               form_set_error('file_path',
-                'Please provide a directory with exactly one gz and one tbi file.');
+                'Please provide a directory with exactly one gz and one index file.');
             }
             }
             else {
             else {
               try {
               try {
@@ -172,7 +171,7 @@ function tripal_jbrowse_mgmt_add_track_form_validate($form, &$form_state) {
                   form_set_error('file_path', 'Failed to copy file' . $file_gz[0] . ' to ' . $path);
                   form_set_error('file_path', 'Failed to copy file' . $file_gz[0] . ' to ' . $path);
                 }
                 }
                 else {
                 else {
-                  if (!tripal_jbrowse_mgmt_copy_file($file_tbi[0], $path, $symbolic_link)) {
+                  if (!tripal_jbrowse_mgmt_copy_file($file_index[0], $path, $symbolic_link)) {
                     form_set_error('file_path', 'Failed to copy file' . $file_gz[0] . ' to ' . $path);
                     form_set_error('file_path', 'Failed to copy file' . $file_gz[0] . ' to ' . $path);
                   }
                   }
                 }
                 }
@@ -184,11 +183,11 @@ function tripal_jbrowse_mgmt_add_track_form_validate($form, &$form_state) {
           }
           }
         }
         }
       }
       }
-      elseif (empty($file) && !empty($tbi)) {
-        form_set_error('file', 'Please upload both a gz and a tbi file.');
+      elseif (empty($file) && !empty($index)) {
+        form_set_error('file', 'Please upload both a gz and an index file.');
       }
       }
-      elseif (!empty($file) && empty($tbi)) {
-        form_set_error('file2', 'Please upload both a gz and a tbi file.');
+      elseif (!empty($file) && empty($index)) {
+        form_set_error('file2', 'Please upload both a gz and an index file.');
       }
       }
       else {
       else {
         $gz_uploaded = tripal_jbrowse_mgmt_upload_file('file');
         $gz_uploaded = tripal_jbrowse_mgmt_upload_file('file');
@@ -205,17 +204,17 @@ function tripal_jbrowse_mgmt_add_track_form_validate($form, &$form_state) {
           }
           }
         }
         }
 
 
-        $tbi_uploaded = tripal_jbrowse_mgmt_upload_file('file2');
-        if (!$tbi_uploaded) {
+        $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 file');
         }
         }
         else {
         else {
-          $tbi_uploaded = tripal_jbrowse_mgmt_move_file($tbi_uploaded, $path);
-          if (!isset($tbi_uploaded)) {
-            form_set_error('file2', 'Failed to move tbi file to ' . $path . '.');
+          $index_uploaded = tripal_jbrowse_mgmt_move_file($index_uploaded, $path);
+          if (!isset($index_uploaded)) {
+            form_set_error('file2', 'Failed to move index file to ' . $path . '.');
           }
           }
           else {
           else {
-            $form_state['values']['uploaded_tbi'] = $tbi_uploaded;
+            $form_state['values']['uploaded_tbi'] = $index_uploaded;
           }
           }
         }
         }
       }
       }