浏览代码

Merge branch '7.x-3.x' into merger-step2

Lacey Sanderson 5 年之前
父节点
当前提交
130a11bed2

+ 12 - 3
tripal_jbrowse_mgmt/includes/tripal_jbrowse_mgmt.api.inc

@@ -381,18 +381,27 @@ function tripal_jbrowse_mgmt_move_file($file, $path = NULL) {
  *   File path of the source file.
  * @param $destination
  *   File path to the destination directory.
- *
+ * @param $symbolic_link
+ *   bool indicates create symbolic_link or copy
  * @return bool
  */
-function tripal_jbrowse_mgmt_copy_file($source, $destination) {
+function tripal_jbrowse_mgmt_copy_file($source, $destination, $sym_link) {
   if (empty($destination)) {
     throw new Exception('Please provide a valid destination path to copy the source to.');
   }
 
   file_prepare_directory($destination, FILE_CREATE_DIRECTORY);
-  return file_unmanaged_copy($source, $destination, FILE_EXISTS_ERROR);
+  if (isset($sym_link) AND ($sym_link == true)){
+    $destination_symlink = $destination.'/'.basename($source);
+    return symlink($source, $destination_symlink);
+  }
+  else{
+    return file_unmanaged_copy($source, $destination, FILE_EXISTS_ERROR);
+  }
+
 }
 
+
 /**
  * Build the http query for a given instance to link to JBrowse.
  *

+ 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 (!mkdir($path)) {
       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.'
       );
     }
@@ -69,21 +69,39 @@ function tripal_jbrowse_mgmt_cmd_add_track($track) {
     case 'HTMLVariants':
       $json = tripal_jbrowse_mgmt_get_json($instance);
       $directory = 'vcf';
-
       $file_name = $track->file;
       if (is_dir($track->file)) {
         $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'];
 
-      $json['tracks'][] = [
-        'label' => $track->label,
+      $track_in_json = [
+        'label' => tripal_jbrowse_mgmt_make_slug($track->label),
         'key' => $track->label,
-        'storeClass' => 'JBrowse/Store/SeqFeature/VCFTabix',
         'urlTemplate' => $directory . '/' . $file_name,
         '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);
       break;
 
@@ -143,7 +161,7 @@ function tripal_jbrowse_mgmt_cmd_generate_names($instance) {
   if (!file_exists($path)) {
     if (!mkdir($path)) {
       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.'
       );
     }

+ 27 - 22
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'] = [
     '#type' => 'file',
-    '#title' => t('TBI File'),
+    '#title' => t('Index File'),
     '#states' => [
       'visible' => [
         ':input[name="file_type"]' => ['value' => 'vcf'],
@@ -94,11 +94,16 @@ function tripal_jbrowse_mgmt_add_track_form($form, &$form_state, $instance_id) {
     ],
   ];
 
+  $form['data']['symbolic_link'] = [
+    '#type' => 'checkbox',
+    '#title' => t('Symbolic Link'),
+    '#description' => t('Create a symbolic link rather than make a copy of the file. This only applies when a path on the server is supplied.'),
+  ];
+
   $form['submit'] = [
     '#type' => 'submit',
     '#value' => 'Add New Track',
   ];
-
   return $form;
 }
 
@@ -120,6 +125,7 @@ function tripal_jbrowse_mgmt_add_track_form_validate($form, &$form_state) {
   $instance = tripal_jbrowse_mgmt_get_instance($values['instance_id']);
   $data = $settings['data_dir'];
   $file_type = $values['file_type'];
+  $symbolic_link = $values['symbolic_link'];
   $path = NULL;
 
   $base_path = $data . '/' . tripal_jbrowse_mgmt_make_slug($instance->title) . '/data';
@@ -136,14 +142,14 @@ function tripal_jbrowse_mgmt_add_track_form_validate($form, &$form_state) {
 
   switch ($file_type) {
     case 'vcf':
-      $tbi = $_FILES['files']['tmp_name']['file2'];
+      $index = $_FILES['files']['tmp_name']['file2'];
       $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',
           '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)) {
           form_set_error('file_path', 'The directory provided does not exist.');
         }
@@ -154,19 +160,18 @@ function tripal_jbrowse_mgmt_add_track_form_validate($form, &$form_state) {
           }
           else {
             $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',
-                '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 {
               try {
-                if (!tripal_jbrowse_mgmt_copy_file($file_gz[0], $path)) {
+                if (!tripal_jbrowse_mgmt_copy_file($file_gz[0], $path, $symbolic_link)) {
                   form_set_error('file_path', 'Failed to copy file' . $file_gz[0] . ' to ' . $path);
                 }
                 else {
-                  if (!tripal_jbrowse_mgmt_copy_file($file_tbi[0], $path)) {
+                  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);
                   }
                 }
@@ -178,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 {
         $gz_uploaded = tripal_jbrowse_mgmt_upload_file('file');
@@ -199,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');
         }
         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 {
-            $form_state['values']['uploaded_tbi'] = $tbi_uploaded;
+            $form_state['values']['uploaded_tbi'] = $index_uploaded;
           }
         }
       }
@@ -229,7 +234,7 @@ function tripal_jbrowse_mgmt_add_track_form_validate($form, &$form_state) {
         }
         else {
           try {
-            if (!tripal_jbrowse_mgmt_copy_file($local_file, $path)) {
+            if (!tripal_jbrowse_mgmt_copy_file($local_file, $path, $symbolic_link)) {
               form_set_error('file_path', 'Failed to copy file ' . $local_file . ' to ' . $path);
             }
           } catch (Exception $exception) {