|  | @@ -52,7 +52,7 @@ function tripal_jbrowse_mgmt_add_track_form($form, &$form_state, $instance_id) {
 | 
	
		
			
				|  |  |    $form['data']['file_type'] = [
 | 
	
		
			
				|  |  |      '#type' => 'select',
 | 
	
		
			
				|  |  |      '#title' => t('File Type'),
 | 
	
		
			
				|  |  | -    '#options' => drupal_map_assoc(['gff', 'bed', 'gbk', 'vcf', 'bw']),
 | 
	
		
			
				|  |  | +    '#options' => drupal_map_assoc(['gff', 'bed', 'gbk', 'bam', 'cram', 'vcf', 'bw']),
 | 
	
		
			
				|  |  |      '#description' => t('See http://gmod.org/wiki/JBrowse_Configuration_Guide#flatfile-to-json.pl for more info.'),
 | 
	
		
			
				|  |  |      '#required' => TRUE,
 | 
	
		
			
				|  |  |    ];
 | 
	
	
		
			
				|  | @@ -67,7 +67,9 @@ function tripal_jbrowse_mgmt_add_track_form($form, &$form_state, $instance_id) {
 | 
	
		
			
				|  |  |      '#title' => t('Index File'),
 | 
	
		
			
				|  |  |      '#states' => [
 | 
	
		
			
				|  |  |        'visible' => [
 | 
	
		
			
				|  |  | -        ':input[name="file_type"]' => ['value' => 'vcf'],
 | 
	
		
			
				|  |  | +        [':input[name="file_type"]' => ['value' => 'vcf'],],
 | 
	
		
			
				|  |  | +        [':input[name="file_type"]' => ['value' => 'bam'],],
 | 
	
		
			
				|  |  | +        [':input[name="file_type"]' => ['value' => 'cram'],],
 | 
	
		
			
				|  |  |        ],
 | 
	
		
			
				|  |  |      ],
 | 
	
		
			
				|  |  |    ];
 | 
	
	
		
			
				|  | @@ -79,7 +81,9 @@ function tripal_jbrowse_mgmt_add_track_form($form, &$form_state, $instance_id) {
 | 
	
		
			
				|  |  |      '#maxlength' => 255,
 | 
	
		
			
				|  |  |      '#states' => [
 | 
	
		
			
				|  |  |        'invisible' => [
 | 
	
		
			
				|  |  | -        ':input[name="file_type"]' => ['value' => 'vcf'],
 | 
	
		
			
				|  |  | +        [':input[name="file_type"]' => ['value' => 'vcf'],],
 | 
	
		
			
				|  |  | +        [':input[name="file_type"]' => ['value' => 'bam'],],
 | 
	
		
			
				|  |  | +        [':input[name="file_type"]' => ['value' => 'cram'],],
 | 
	
		
			
				|  |  |        ],
 | 
	
		
			
				|  |  |      ],
 | 
	
		
			
				|  |  |    ];
 | 
	
	
		
			
				|  | @@ -91,7 +95,9 @@ function tripal_jbrowse_mgmt_add_track_form($form, &$form_state, $instance_id) {
 | 
	
		
			
				|  |  |      '#maxlength' => 255,
 | 
	
		
			
				|  |  |      '#states' => [
 | 
	
		
			
				|  |  |        'visible' => [
 | 
	
		
			
				|  |  | -        ':input[name="file_type"]' => ['value' => 'vcf'],
 | 
	
		
			
				|  |  | +        [':input[name="file_type"]' => ['value' => 'vcf'],],
 | 
	
		
			
				|  |  | +        [':input[name="file_type"]' => ['value' => 'bam'],],
 | 
	
		
			
				|  |  | +        [':input[name="file_type"]' => ['value' => 'cram'],],
 | 
	
		
			
				|  |  |        ],
 | 
	
		
			
				|  |  |      ],
 | 
	
		
			
				|  |  |    ];
 | 
	
	
		
			
				|  | @@ -99,6 +105,7 @@ function tripal_jbrowse_mgmt_add_track_form($form, &$form_state, $instance_id) {
 | 
	
		
			
				|  |  |    $form['data']['symbolic_link'] = [
 | 
	
		
			
				|  |  |      '#type' => 'checkbox',
 | 
	
		
			
				|  |  |      '#title' => t('Symbolic Link'),
 | 
	
		
			
				|  |  | +    '#default_value' => true,
 | 
	
		
			
				|  |  |      '#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.<br>Please have Symbolic Link selected if the same file is used for new track.'),
 | 
	
		
			
				|  |  |    ];
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -136,10 +143,7 @@ function tripal_jbrowse_mgmt_add_track_form_validate($form, &$form_state) {
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |    $base_path = $base_path . '/data';
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  if ($file_type === 'vcf') {
 | 
	
		
			
				|  |  | -    $path = $base_path . '/vcf';
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | -  elseif ($file_type === 'bw') {
 | 
	
		
			
				|  |  | +  if ($file_type === 'bw') {
 | 
	
		
			
				|  |  |      $path = $base_path . '/wig';
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |    else {
 | 
	
	
		
			
				|  | @@ -147,83 +151,21 @@ function tripal_jbrowse_mgmt_add_track_form_validate($form, &$form_state) {
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |    switch ($file_type) {
 | 
	
		
			
				|  |  |      case 'vcf':
 | 
	
		
			
				|  |  | +      $path = $base_path . '/vcf';
 | 
	
		
			
				|  |  |        $index = $_FILES['files']['tmp_name']['file2'];
 | 
	
		
			
				|  |  | -      $local_dir = isset($values['dir_path']) ? $values['dir_path'] : NULL;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -      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($index) && !empty($local_dir)) {
 | 
	
		
			
				|  |  | -        if (!file_exists($local_dir)) {
 | 
	
		
			
				|  |  | -          form_set_error('file_path', 'The directory provided does not exist.');
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        else {
 | 
	
		
			
				|  |  | -          if (!is_dir($local_dir)) {
 | 
	
		
			
				|  |  | -            form_set_error('file_path',
 | 
	
		
			
				|  |  | -              'The file provided is not a directory.');
 | 
	
		
			
				|  |  | -          }
 | 
	
		
			
				|  |  | -          else {
 | 
	
		
			
				|  |  | -            $file_gz = glob($local_dir . '/*.vcf.gz');
 | 
	
		
			
				|  |  | -            $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 index file.');
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            else {
 | 
	
		
			
				|  |  | -              try {
 | 
	
		
			
				|  |  | -                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.'. If this track is expected to create by existed file, please have Symbolic Link selected.');
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                else {
 | 
	
		
			
				|  |  | -                  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.'. If this track is expected to create by existed file, please have Symbolic Link selected.');
 | 
	
		
			
				|  |  | -                  }
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -              } catch (Exception $exception) {
 | 
	
		
			
				|  |  | -                form_set_error($exception->getMessage());
 | 
	
		
			
				|  |  | -              }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -          }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -      }
 | 
	
		
			
				|  |  | -      elseif (empty($file) && !empty($index)) {
 | 
	
		
			
				|  |  | -        form_set_error('file', 'Please upload both a gz and an index 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');
 | 
	
		
			
				|  |  | -        if (!$gz_uploaded) {
 | 
	
		
			
				|  |  | -          form_set_error('file', 'Unable to upload file');
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        else {
 | 
	
		
			
				|  |  | -          $gz_uploaded = tripal_jbrowse_mgmt_move_file($gz_uploaded, $path);
 | 
	
		
			
				|  |  | -          if (!isset($gz_uploaded)) {
 | 
	
		
			
				|  |  | -            form_set_error('file', 'Failed to move gz file to ' . $path . '.');
 | 
	
		
			
				|  |  | -          }
 | 
	
		
			
				|  |  | -          else {
 | 
	
		
			
				|  |  | -            $form_state['values']['uploaded_gz'] = $gz_uploaded;
 | 
	
		
			
				|  |  | -          }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +      $form_state = tripal_jbrowse_mgmt_validate_folder_upload($file, $index, $path, $form_state);
 | 
	
		
			
				|  |  | +      break;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        $index_uploaded = tripal_jbrowse_mgmt_upload_file('file2');
 | 
	
		
			
				|  |  | -        if (!$index_uploaded) {
 | 
	
		
			
				|  |  | -          form_set_error('file2', 'Unable to upload file');
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        else {
 | 
	
		
			
				|  |  | -          $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'] = $index_uploaded;
 | 
	
		
			
				|  |  | -          }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -      }
 | 
	
		
			
				|  |  | +    case 'bam':
 | 
	
		
			
				|  |  | +      $path = $base_path . '/bam';
 | 
	
		
			
				|  |  | +      $index = $_FILES['files']['tmp_name']['file2'];
 | 
	
		
			
				|  |  | +      $form_state = tripal_jbrowse_mgmt_validate_folder_upload($file, $index, $path, $form_state);
 | 
	
		
			
				|  |  | +      break;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    case 'cram':
 | 
	
		
			
				|  |  | +      $path = $base_path . '/bam';
 | 
	
		
			
				|  |  | +      $index = $_FILES['files']['tmp_name']['file2'];
 | 
	
		
			
				|  |  | +      $form_state = tripal_jbrowse_mgmt_validate_folder_upload($file, $index, $path, $form_state);
 | 
	
		
			
				|  |  |        break;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      default:
 | 
	
	
		
			
				|  | @@ -283,11 +225,11 @@ function tripal_jbrowse_mgmt_add_track_form_submit($form, &$form_state) {
 | 
	
		
			
				|  |  |    if (!empty($values['dir_path'])) {
 | 
	
		
			
				|  |  |      $file = $values['dir_path'];
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -  if (!empty($values['uploaded_gz'])) {
 | 
	
		
			
				|  |  | -    $file = $values['uploaded_gz'];
 | 
	
		
			
				|  |  | +  if (!empty($values['uploaded_file_index'])) {
 | 
	
		
			
				|  |  | +    $file = $values['uploaded_file_index'];
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -  if (!empty($values['uploaded_file'])) {
 | 
	
		
			
				|  |  | -    $file = $values['uploaded_file'];
 | 
	
		
			
				|  |  | +  if (!empty($values['uploaded_file_data'])) {
 | 
	
		
			
				|  |  | +    $file = $values['uploaded_file_data'];
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    $instance = tripal_jbrowse_mgmt_get_instance($values['instance_id']);
 |