1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/ef4a1377fcc6/ changeset: ef4a1377fcc6 user: jgoecks date: 2011-12-15 22:21:39 summary: Custom builds: (a) reinstitute support for len files/len entries and (b) improve UI so that it is easy to specify build definition and help is accurate. affected #: 2 files diff -r fdcdc0115a123aa40bc46e69df769f171837534e -r ef4a1377fcc62bad6feb11df126339c639b7e56a lib/galaxy/web/controllers/user.py --- a/lib/galaxy/web/controllers/user.py +++ b/lib/galaxy/web/controllers/user.py @@ -1198,14 +1198,57 @@ # Add new custom build. name = kwds.get('name', '') key = kwds.get('key', '') - dataset_id = kwds.get('dataset_id', '') - if not name or not key or not dataset_id: + + # Look for build's chrom info in len_file and len_text. + len_file = kwds.get( 'len_file', None ) + if getattr( len_file, "file", None ): # Check if it's a FieldStorage object + len_text = len_file.file.read() + else: + len_text = kwds.get( 'len_text', None ) + + if not len_text: + # Using FASTA from history. + dataset_id = kwds.get('dataset_id', '') + + if not name or not key or not ( len_text or dataset_id ): message = "You must specify values for all the fields." elif key in dbkeys: message = "There is already a custom build with that key. Delete it first if you want to replace it." else: - dataset_id = trans.security.decode_id( dataset_id ) - dbkeys[key] = { "name": name, "fasta": dataset_id } + # Have everything needed; create new build. + build_dict = { "name": name } + if len_text: + # Create new len file + new_len = trans.app.model.HistoryDatasetAssociation( extension="len", create_dataset=True, sa_session=trans.sa_session ) + trans.sa_session.add( new_len ) + new_len.name = name + new_len.visible = False + new_len.state = trans.app.model.Job.states.OK + new_len.info = "custom build .len file" + trans.sa_session.flush() + counter = 0 + f = open(new_len.file_name, "w") + # LEN files have format: + # <chrom_name><tab><chrom_length> + for line in len_text.split("\n"): + lst = line.strip().rsplit(None, 1) # Splits at the last whitespace in the line + if not lst or len(lst) < 2: + lines_skipped += 1 + continue + chrom, length = lst[0], lst[1] + try: + length = int(length) + except ValueError: + lines_skipped += 1 + continue + counter += 1 + f.write("%s\t%s\n" % (chrom, length)) + f.close() + build_dict.update( { "len": new_len.id, "count": counter } ) + else: + dataset_id = trans.security.decode_id( dataset_id ) + build_dict[ "fasta" ] = dataset_id + dbkeys[key] = build_dict # Save builds. # TODO: use database table to save builds. user.preferences['dbkeys'] = to_json_string(dbkeys) diff -r fdcdc0115a123aa40bc46e69df769f171837534e -r ef4a1377fcc62bad6feb11df126339c639b7e56a templates/user/dbkeys.mako --- a/templates/user/dbkeys.mako +++ b/templates/user/dbkeys.mako @@ -40,6 +40,15 @@ padding: 10px; } %endif + div.def_tab { + float: left; + padding: 0.2em 0.5em; + background-color: white; + } + div.def_tab.active { + background-color: #CCF; + border: solid 1px #66A; + } </style></%def> @@ -60,6 +69,43 @@ $("#show_installed_builds").click(function() { $("#installed_builds").show(); }); + + // Set up behavior for build definition tab controls. + $("div.def_tab > a").each(function() { + $(this).click(function() { + var tab_id = $(this).attr("id"); + + // Hide all build inputs, help. + $("div.build_definition").children(":input").hide(); + $(".infomessagesmall > div").hide(); + + // Show input item, help corresponding to tab id. + $("#" + tab_id + "_input").show(); + $("." + tab_id + "_help").show(); + + // Update tabs. + $("div.def_tab").removeClass("active"); + $(this).parent().addClass("active"); + }); + }); + + ## If there are fasta HDAs available, show fasta tab; otherwise show len file tab. + // Set starting tab. + % if fasta_hdas.first(): + $("#fasta").click(); + % else: + $("#len_file").click(); + % endif + + // Before submit, remove inputs not associated with the active tab. + $("#submit").click(function() { + var id = $(".active > a").attr("id"); + $("div.build_definition").children(":input").each(function() { + if ( $(this).attr("id") !== (id + "_input") ) { + $(this).remove(); + } + }); + }); }); </script> @@ -70,7 +116,6 @@ </%def><%def name="body()"> - % if message: <div class="errormessagelarge">${message}</div> % elif lines_skipped > 0: @@ -123,50 +168,82 @@ <hr /><h3>Add a Custom Build</h3><form action="dbkeys" method="post" enctype="multipart/form-data"> + ## Custom build via fasta in history. <div class="toolForm" style="float: left;"><div class="toolFormTitle">New Build</div><div class="toolFormBody"><div class="form-row"> - <label for="name">Build Name (eg: Mouse):</label> + <label for="name">Name (eg: Hamster):</label><input type="text" id="name" name="name" /></div><div class="form-row"> - <label for="key">Build Key (eg: mm9):</label> + <label for="key">Key (eg: hamster_v1):</label><input type="text" id="key" name="key" /></div> - <div class="form-row"> - <label for="len_file">Build Genome:</label> - <select name="dataset_id"> + <div class="form-row build_definition"> + <label>Definition:</label> + <div class="def_tab"> + <a id="fasta" href="javascript:void(0)">FASTA</a> + </div> + <div class="def_tab"> + <a id="len_file" href="javascript:void(0)">Len File</a> + </div> + <div class="def_tab"> + <a id="len_entry" href="javascript:void(0)">Len Entry</a> + </div> + <div style="clear: both; padding-bottom: 0.5em"></div> + <select id="fasta_input" name="dataset_id"> %for dataset in fasta_hdas: <option value="${trans.security.encode_id( dataset.id )}">${dataset.hid}: ${dataset.name}</option> %endfor </select> - </div> - - <div class="form-row"><input type="submit" name="add" value="Submit"/></div> + <input type="file" id="len_file_input" name="len_file" /></input> + <textarea id="len_entry_input" name="len_text" cols="30" rows="8"></textarea> + </div> + <div class="form-row"><input id="submit" type="submit" name="add" value="Submit"/></div></div></div></form><div class="infomessagesmall" style="float: left; margin-left: 10px; width: 40%;"> - <h3>Length Format</h3> - <p> - The length format is two-column, separated by whitespace, of the form: - <pre>chrom/contig length of chrom/contig</pre> - </p> - <p> - For example, the first few entries of <em>mm9.len</em> are as follows: - <pre> -chr1 197195432 -chr2 181748087 -chr3 159599783 -chr4 155630120 -chr5 152537259 - </pre> - </p> + <div class="fasta_help"> + <h3>FASTA format</h3> + <p> + This is a multi-fasta file from your current history that provides the genome + sequences for each chromosome/contig in your build. + </p> + + <p> + Here is a snippet from an example multi-fasta file: + <pre> + >chr1 + ATTATATATAAGACCACAGAGAGAATATTTTGCCCGG... + >chr2 + GGCGGCCGCGGCGATATAGAACTACTCATTATATATA... + ... + </pre> + </p> + </div> + <div class="len_file_help len_entry_help"> + <h3>Length Format</h3> + <p> + The length format is two-column, separated by whitespace, of the form: + <pre>chrom/contig length of chrom/contig</pre> + </p> + <p> + For example, the first few entries of <em>mm9.len</em> are as follows: + <pre> + chr1 197195432 + chr2 181748087 + chr3 159599783 + chr4 155630120 + chr5 152537259 + </pre> + </p> - <p>Trackster uses this information to populate the select box for chrom/contig, and - to set the maximum basepair of the track browser. You may either upload a .len file - of this format, or directly enter the information into the box.</p> - + <p>Trackster uses this information to populate the select box for chrom/contig, and + to set the maximum basepair of the track browser. You may either upload a .len file + of this format (Len File option), or directly enter the information into the box + (Len Entry option).</p> + </div></div></%def> \ No newline at end of file Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.