<commit_before>// upload a copy of the current plasmid in genbank or sbol format to ice
import request from 'superagent/lib/client';
import assign from 'lodash/object/assign';

var query = location.search;
var cookie = document.cookie;
var id = query.match(/entryId=[\d]+/) + "";
id = id.replace(/entryId=/, "");
var sid = cookie.match(/sessionId=%22[0-9a-z\-]+%22/) + "";
sid = sid.replace(/sessionId=|%22/g, "");

export default function saveToServer({input, state, output}) {
    // BUILD AN OBJECT FROM THE STATE TREE THAT'S SETUP THE WAY JSON WANTS
    // MAKE SURE YOU'RE TYPING IN ALL CAPS
    // THEN PUT THAT OBJECT IN THE BODY OF THE REQUEST TO THE URL BELOw
    // BOOYAH
    var sequenceData = state.get("sequenceData");
    var newSequenceData = {};
    // massage the data back into a form that ICE can accept
    newSequenceData.seqId = newSequenceData._id;
    newSequenceData.isCircular = newSequenceData.circular;
    newSequenceData.name = sequenceData.name;
    newSequenceData.sequence = sequenceData.sequence;
    // var feature = {};
    // for(var f = 0; f++; f<sequenceData.features.length) {
    //     feature = newSequenceData.features[f];
    //     feature.locations.genbankStart = feature.start;
    //     feature.locations.end = feature.end;
    // }
    newSequenceData.uri = window.location.origin + "/rest/parts/" + id;

    // remember to do checks for bad id and sid and sequence length

    // parts is always parts, even for plasmids and seeds
    request
        .post('rest/parts/' + id + '/sequence?sid=' + sid)
        .set('X-ICE-Authentication-sessionId', sid)
        .set('Content-Type', 'application/json')
        .send(newSequenceData)
        .end(function(err, result) {
            if(err) {
                console.log("unable to save to registry, something went wrong: " + err)
            }
        }<commit_msg>saving up to server works with features (maybe not notes) but the code is uglyyyy<commit_after>// upload a copy of the current plasmid in genbank or sbol format to ice
import request from 'superagent/lib/client';
import assign from 'lodash/object/assign';

var query = location.search;
var cookie = document.cookie;
var id = query.match(/entryId=[\d]+/) + "";
id = id.replace(/entryId=/, "");
var sid = cookie.match(/sessionId=%22[0-9a-z\-]+%22/) + "";
sid = sid.replace(/sessionId=|%22/g, "");

export default function saveToServer({input, state, output}) {
    // BUILD AN OBJECT FROM THE STATE TREE THAT'S SETUP THE WAY JSON WANTS
    // MAKE SURE YOU'RE TYPING IN ALL CAPS
    // THEN PUT THAT OBJECT IN THE BODY OF THE REQUEST TO THE URL BELOw
    // BOOYAH
    var sequenceData = state.get('sequenceData');
    var newSequenceData = {};
    var featureList = [];
    // massage the data back into a form that ICE can accept
    newSequenceData.sequence = sequenceData.sequence;
    newSequenceData.name = state.get('name');
    newSequenceData.isCircular = sequenceData.circular;

    // we have to copy these over instead of pushing the object because we need to delete certain props
    for (var f = 0; f < sequenceData.features.length; f++) {
        featureList[f] = {};
        featureList[f].id = sequenceData.features[f].id;
        featureList[f].type = sequenceData.features[f].type;
        featureList[f].name = sequenceData.features[f].name;
        featureList[f].strand = sequenceData.features[f].strand;
        featureList[f].notes = sequenceData.features[f].notes;
        // featureList[f].notes.push(sequenceData.features[f].notes);
        featureList[f].locations = [{}];
        featureList[f].locations[0].genbankStart = sequenceData.features[f].start;
        featureList[f].locations[0].end = sequenceData.features[f].end;
    }

    newSequenceData.features = featureList;

    // remember to do checks for bad id and sid and sequence length

    // parts is always parts, even for plasmids and seeds
    request
        .post('rest/parts/' + id + '/sequence?sid=' + sid)
        .set('X-ICE-Authentication-sessionId', sid)
        .set('Content-Type', 'application/json')
        .send(newSequenceData)
        .end(function(err, result) {
            if(err) {
                console.log("unable to save to registry, something went wrong: " + err)
            }
        }
{'fraction_non_alphanumeric': 0.12842105263157894, 'fraction_numerical': 0.004678362573099415, 'mean_word_length': 2.9085923217550276, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4315210', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1248, 'n_words': 369}