Skip to content

Commit

Permalink
Merge pull request #292 from Merfoo/gene-sequences-import
Browse files Browse the repository at this point in the history
Gene sequences import for Maddison Lab
  • Loading branch information
mjy committed Nov 17, 2017
2 parents 9a033d1 + a5674f7 commit a9162b1
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 101 deletions.
75 changes: 53 additions & 22 deletions app/controllers/descriptors_controller.rb
@@ -1,8 +1,8 @@
class DescriptorsController < ApplicationController
include DataControllerConfiguration::ProjectDataControllerConfiguration

before_action :set_descriptor, only: [:show, :edit, :update, :destroy, :annotations]

# GET /descriptors
# GET /descriptors.json
def index
Expand All @@ -16,30 +16,30 @@ def index
}
end
end

# GET /descriptors/1
# GET /descriptors/1.json
def show
end

def list
@descriptor = Descriptor.with_project_id(sessions_current_project_id).page(params[:page])
end

# GET /descriptors/new
def new
@descriptor = Descriptor.new
end

# GET /descriptors/1/edit
def edit
end

# POST /descriptors
# POST /descriptors.json
def create
@descriptor = Descriptor.new(descriptor_params)

respond_to do |format|
if @descriptor.save
format.html { redirect_to @descriptor.metamorphosize, notice: 'Descriptor was successfully created.' }
Expand All @@ -50,7 +50,7 @@ def create
end
end
end

# PATCH/PUT /descriptors/1
# PATCH/PUT /descriptors/1.json
def update
Expand All @@ -64,7 +64,7 @@ def update
end
end
end

# DELETE /descriptors/1
# DELETE /descriptors/1.json
def destroy
Expand All @@ -74,21 +74,21 @@ def destroy
format.json { head :no_content }
end
end

def autocomplete
t = "#{params[:term]}%"
@descriptors = Descriptor.where(project_id: sessions_current_project_id).where('name like ? or short_name like ?', t, t)
data = @descriptors.collect do |t|
{id: t.id,
label: t.name,
gid: t.to_global_id.to_s,
response_values: {
params[:method] => t.id
},
label_html: t.name
}
end
render :json => data
label: t.name,
gid: t.to_global_id.to_s,
response_values: {
params[:method] => t.id
},
label_html: t.name
}
end
render :json => data
end

def search
Expand All @@ -105,15 +105,46 @@ def annotations
render '/shared/data/all/annotations'
end

def batch_load
end

def preview_modify_gene_descriptor_batch_load
if params[:file]
@result = BatchLoad::Import::Descriptors::ModifyGeneDescriptorInterpreter.new(batch_params)
digest_cookie(params[:file].tempfile, :modify_gene_descriptor_batch_load_descriptors_md5)
render 'descriptors/batch_load/modify_gene_descriptor/preview'
else
flash[:notice] = "No file provided!"
redirect_to action: :batch_load
end
end

def create_modify_gene_descriptor_batch_load
if params[:file] && digested_cookie_exists?(params[:file].tempfile, :modify_gene_descriptor_batch_load_descriptors_md5)
@result = BatchLoad::Import::Descriptors::ModifyGeneDescriptorInterpreter.new(batch_params)
if @result.create
flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} Gene Descriptors were modified."
render 'descriptors/batch_load/modify_gene_descriptor/create' and return
else
flash[:alert] = 'Batch import failed.'
end
else
flash[:alert] = 'File to batch upload must be supplied.'
end
render :batch_load
end

private

private

def set_descriptor
@descriptor = Descriptor.find(params[:id])
end

def descriptor_params
params.require(:descriptor).permit(:name, :short_name, :type)
end

def batch_params
params.permit(:file).merge(user_id: sessions_current_user_id, project_id: sessions_current_project_id).to_h.symbolize_keys
end
end
Expand Up @@ -18,7 +18,7 @@
<li>Assumes a namespace with name "GenBank" and shortname "GBK" exists</li>
<li>Identifier Global::Uri will be attached with the value of the "guid" column if not blank to each collection object</li>
<li>Identifier Global::MorphbankSpecimenNumber will be attached with the value of the "morphbank_specimen_id" column if not blank to each collection object</li>
<li>Identifier with namespace DRMLabVoucher will be attached with the value of the "voucher_number_prefix" + "voucher_number_string" column if not blank to each collection object</li>
<li>Identifier with namespace DRMLabVoucher will be attached with the value of the "voucher_number_prefix" + "voucher_number_string" column once if not blank to each collection object</li>
<li>Identifier with namespace DRMDNAVoucher will be attached with the value of the "sample_code_prefix" and "sample_code" column if not blank to each collection object</li>
<li>Identifier with namespace GenBank will be attached with the value of the "sample_code_prefix" and "sample_code" columns if not blank to each extract</li>
<li>DataAttribute of predicate "SpecimenNumber" with value of "specimen_number" will be attached if not blank to each collection object.</li>
Expand Down
1 change: 1 addition & 0 deletions app/views/descriptors/batch_load.html.erb
@@ -0,0 +1 @@
<%= render 'descriptors/batch_load/modify_gene_descriptor/batch_load' -%>
@@ -0,0 +1,35 @@
<div>
<h2> Modify Gene Descriptor batch load </h2>

<div class="flexbox full_viewport_whitespace">
<div class="item item1 one_third_width">
<h3> Description and requirements </h3>

<p> Modifies each gene descriptors gene attribute logic to be at least one forward primer and one reverse primer. </p>
<ul>
<li>A tab-delimited, UTF-8 compatible text file is required.</li>
<li>Column headers are (see <%= link_to('sample template', asset_path('batch_load_templates/descriptors/modify_gene_descriptor_batch_load.tab'), target: '_blank') -%>).</li>
<li>Each primer is separated by a comma and space (", ")</li>
<li>Multiple uploads of the same data will X.</li>
<li>It is assumed each gene has one forward primer and one reverse primer.</li>
<li>There is currently some|no size limit to the file being loaded but this may change in the future.</li>
</ul>
</div>

<div class="item item2 one_third_width">
<h3> Example file </h3>

<p> A tab delimited formatted file
In the example whitespace is a tab. View sample file template.</p>

<pre class="fixed_width_font">
gene_name forward_primers reverse_primers
</pre>
</div>

<div class="item item3">
<h3> Go! </h3>
<%= render partial: '/descriptors/batch_load/modify_gene_descriptor/form', locals: {url: preview_modify_gene_descriptor_batch_load_descriptors_path, submit: :preview} -%>
</div>
</div>
</div>
@@ -0,0 +1,10 @@
<%= form_tag url, multipart: true do -%>
<div class="field">
<%= label_tag :file, 'Select a file' -%>
<br>
<%= file_field_tag :file -%>
</div>

<%= content_for :warn_level -%>
<%= submit_tag submit -%>
<% end %>
@@ -0,0 +1 @@
<%= render partial: '/shared/data/all/batch_load/create' -%>
@@ -0,0 +1,33 @@
<% content_for :warn_level do -%>
<%= warn_level_input(@result) -%>
<% end %>
<%= content_for :batch_form do -%>
<%= render partial: '/descriptors/batch_load/modify_gene_descriptor/form', locals: {url: create_modify_gene_descriptor_batch_load_descriptors_path, submit: :create} -%>
<% end %>
<%= content_for :line_breakdown do -%>
<table class="top_align_text">
<tr>
<th class="four_character_width">line</th>
<th class="four_character_width">data count</th>
<th> gene attribute logic </th>
<th class=""> data errors* </th>
<th class=""> parse errors </th>
</tr>

<% @result.sorted_processed_rows.each do |i, rp| -%>
<tr>
<%= batch_line_link_td(i) -%>
<%= batch_all_objects_count_td(rp) -%>
<td>
<%= rp.objects[:descriptor].each_with_index.collect{|n, i| "#{i + 1}: " + n.gene_attribute_logic }.join('<br>').html_safe -%>
</td>
<%= batch_data_errors_td(rp) -%>
<%= batch_parse_errors_td(rp) -%>
</tr>
<% end -%>
</table>
<% end %>
<%= render partial: '/shared/data/all/batch_load/preview' -%>
Expand Up @@ -5,7 +5,7 @@
<div class="item item1 one_third_width">
<h3> Description and requirements </h3>

<p>Create sequence relationships between sequences and primer sequences</p>
<p>Create sequence relationships between sequences and primer sequences and creates gene descriptors and gene attributes</p>
<ul>
<li>A tab-delimited, UTF-8 compatible text file is required.</li>
<li>Column headers are (see <%= link_to('sample template', asset_path('batch_load_templates/sequence_relationships/sequence_relationships_primers_batch_load.tab'), target: '_blank') -%>).</li>
Expand All @@ -20,7 +20,7 @@
<p> A tab delimited formatted file. In the example whitespace is a tab. View sample file template.</p>

<pre class="fixed_width_font">
identifier sample_code gene fragment publication taxon_name primers
identifier dna_number gene_name forward_primers reverse_primers
</pre>
</div>

Expand Down

0 comments on commit a9162b1

Please sign in to comment.