<commit_before>{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import sys, os\n",
    "# sys.path.insert(0,'/global/homes/b/bpb/repos/metatlas')\n",
    "import metatlas.metatlas_objects as metob"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%%time\n",
    "ids = metob.retrieve('CompoundIdentification',username='*')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# now we have to fetch stubs for all frag refs.\n",
    "f = [cid for cid in ids if cid.frag_references]\n",
    "len(f)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "MetAtlas 2.7",
   "language": "python",
   "name": "metatlas"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"<commit_msg>simpler example showing connection overflow<commit_after>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prior to running, there should be 2 connections.  These are for the MySQLWorkbench.\n",
    "\n",
    "Counts are determined using this SQL syntax\n",
    "\n",
    "```\n",
    "SELECT COUNT(*) FROM information_schema.PROCESSLIST;\n",
    "```\n",
    "\n",
    "All counts "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import sys, os\n",
    "sys.path.insert(0,'/global/homes/b/bpb/repos/metatlas')\n",
    "import metatlas.metatlas_objects as metob"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "After importing metob, there should still only be the two connections"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "ids = metob.retrieve('CompoundIdentification',name='serine')#unique_id='c964f97a6d794856b3c2d50334fc0f40')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This retrieve command leaves an extra connection.  There are now three connections.\n",
    "\n",
    "The third will be persistent until it times out (at least a couple hours)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "frags = [f for f in ids if f.frag_references]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This clone command creates two new processes.  There are now 5 connections."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'compound': [{'chebi_id': u'CHEBI:17115///CHEBI:33384///CHEBI:32836///CHEBI:32837',\n",
      " 'chebi_url': u'http://www.ebi.ac.uk/chebi/searchId.do?chebiId=CHEBI:17115///http://www.ebi.ac.uk/chebi/searchId.do?chebiId=CHEBI:33384///http://www.ebi.ac.uk/chebi/searchId.do?chebiId=CHEBI:32836///http://www.ebi.ac.uk/chebi/searchId.do?chebiId=CHEBI:32837',\n",
      " 'creation_time': '2016-06-17T18:11:02',\n",
      " 'description': u'A serinate that is the conjugate base of L-serine, obtained by deprotonation of the carboxy group.///A serine zwitterion obtained by transfer of a proton from the carboxy to the amino group of L-serine.///The L-enantiomer of serine.///A serinium that is the conjugate acid of L-serine, obtained by protonation of the amino group.',\n",
      " 'formula': u'C3H7NO3',\n",
      " 'head_id': u'20a6f472ad3d4e1aab58337c754ebbbc',\n",
      " 'hmdb_id': u'HMDB00187',\n",
      " 'hmdb_url': u'http://www.hmdb.ca/metabolites/HMDB00187',\n",
      " 'img_abc_id': u'',\n",
      " 'inchi': u'InChI=1S/C3H7NO3/c4-2(1-5)3(6)7/h2,5H,1,4H2,(H,6,7)/t2-/m0/s1',\n",
      " 'inchi_key': u'<KEY>JLQNBG-REOHCLBHSA-N',\n",
      " 'iupac_name': u'',\n",
      " 'kegg_id': u'C00065',\n",
      " 'kegg_url': u'http://www.genome.jp/dbget-bin/www_bget?C00065',\n",
      " 'last_modified': '2016-06-17T18:11:02',\n",
      " 'lipidmaps_id': u'',\n",
      " 'lipidmaps_url': u'',\n",
      " 'metacyc_id': u'SER',\n",
      " 'mono_isotopic_molecular_weight': 105.042593084,\n",
      " 'name': u'L-serine',\n",
      " 'neutralized_2d_inchi': u'InChI=1S/C3H7NO3/c4-2(1-5)3(6)7/h2,5H,1,4H2,(H,6,7)',\n",
      " 'neutralized_2d_inchi_key': u'<KEY>',\n",
      " 'neutralized_inchi': u'InChI=1S/C3H7NO3/c4-2(1-5)3(6)7/h2,5H,1,4H2,(H,6,7)/t2-/m0/s1',\n",
      " 'neutralized_inchi_key': u'<KEY>',\n",
      " 'num_free_radicals': 0,\n",
      " 'number_components': 1,\n",
      " 'permanent_charge': 0,\n",
      " 'prev_uid': u'origin',\n",
      " 'pubchem_compound_id': u'5951',\n",
      " 'pubchem_url': u'http://pubchem.ncbi.nlm.nih.gov/compound/5951',\n",
      " 'source': u'chebi///msmls///wikidata///metacyc///hmdb',\n",
      " 'synonyms': u'L-serine///serine///56-45-1///(S)-2-Amino-3-hydroxypropanoic acid///(S)-Serine///beta-Hydroxyalanine///L-ser///L-(-)-Serine///Serine, L-///L-3-Hydroxy-alanine///beta-Hydroxy-L-alanine///L-2-Amino-3-hydroxypropionic acid///2-Amino-3-hydroxypropionic acid///(-)-Serine///L-3-Hydroxy-2-aminopropionic acid///Serinum [Latin]///L-Serin///(S)-(-)-Serine///Serina [Spanish]///Serine (VAN)///b-Hydroxy-L-alanine///H-Ser-OH///(S)-2-Amino-3-hydroxypropionic acid///Serinum///SER (IUPAC abbrev)///(2S)-2-amino-3-hydroxypropanoic acid///(S)-alpha-Amino-beta-hydroxypropionic acid///alpha-Amino-beta-hydroxypropionic acid///HSDB 680///2-Amino-3-hydroxypropanoic acid, (S)-///3-hydroxy-L-Alanine///CHEBI:17115///Serine [USAN:INN]///Propanoic acid, 2-amino-3-hydroxy-, (S)-///(S)-a-Amino-b-hydroxypropionic acid///(S)-2-amino-3-hydroxy-Propanoic acid///BRN 1721404///L-3-Hydroxy-2-aminopropionate///3-Hydroxyalanine///UNII-452VLY9402///(S)-a-Amino-b-hydroxypropionate///(S)-b-Amino-3-hydroxypropionate///(S)-2-Amino-3-hydroxypropanoate///MTCFGRXMJLQNBG-REOHCLBHSA-N///(S)-2-amino-3-hydroxy-Propanoate///(S)-beta-Amino-3-hydroxypropionate///EINECS 200-274-3///(S)-b-Amino-3-hydroxypropionic acid///MFCD00064224///NSC 118365',\n",
      " 'unique_id': u'20a6f472ad3d4e1aab58337c754ebbbc',\n",
      " 'username': u'bpb',\n",
      " 'wikipedia_url': u''}],\n",
      " 'creation_time': '2016-08-10T17:36:58',\n",
      " 'description': u'No description',\n",
      " 'frag_references': [{'collision_energy': 0.0,\n",
      " 'creation_time': '2016-08-10T17:36:59',\n",
      " 'description': u'No description',\n",
      " 'enabled': True,\n",
      " 'head_id': u'ee411b298e974842a5ecb87be4dd249b',\n",
      " 'last_modified': '2016-08-10T17:37:52',\n",
      " 'lcms_run': {'acquisition_time': None,\n",
      " 'creation_time': '2016-02-10T17:08:10',\n",
      " 'description': u'20160119_KZ_HILIC_Avena_exu_uptake 20160119_pHILIC___POS_MSMS_KZ_RootCass_4_MeOH_____Run237.mzML',\n",
      " 'experiment': u'20160119_KZ_HILIC_Avena_exu_uptake',\n",
      " 'hdf5_file': u'/global/project/projectdirs/metatlas/raw_data/katezh/20160119_KZ_HILIC_Avena_exu_uptake/20160119_pHILIC___POS_MSMS_KZ_RootCass_4_MeOH_____Run237.h5',\n",
      " 'head_id': u'864a1365f2ee43179c9bace0ba2641c8',\n",
      " 'injection_volume': None,\n",
      " 'injection_volume_units': 'uL',\n",
      " 'last_modified': '2016-02-10T19:10:53',\n",
      " 'method': None,\n",
      " 'mzml_file': u'/global/project/projectdirs/metatlas/raw_data/katezh/20160119_KZ_HILIC_Avena_exu_uptake/20160119_pHILIC___POS_MSMS_KZ_RootCass_4_MeOH_____Run237.mzML',\n",
      " 'name': u'20160119_pHILIC___POS_MSMS_KZ_RootCass_4_MeOH_____Run237.mzML',\n",
      " 'pass_qc': None,\n",
      " 'prev_uid': u'origin',\n",
      " 'sample': None,\n",
      " 'unique_id': u'864a1365f2ee43179c9bace0ba2641c8',\n",
      " 'username': u'pasteur'},\n",
      " 'mz_intensities': [{'creation_time': '2016-08-10T17:36:59',\n",
      " 'description': u'No description',\n",
      " 'head_id': u'd53c45c2b8e44f39bcbcdac62d4e1537',\n",
      " 'intensity': 1192.43,\n",
      " 'last_modified': '2016-08-10T17:37:52',\n",
      " 'mz': 51.9229,\n",
      " 'name': u'Untitled',\n",
      " 'prev_uid': u'origin',\n",
      " 'unique_id': u'd53c45c2b8e44f39bcbcdac62d4e1537',\n",
      " 'username': u'bpb'},\n",
      "                    {'creation_time': '2016-08-10T17:36:59',\n",
      " 'description': u'No description',\n",
      " 'head_id': u'162e36dee74942edbd45b51f50d191ee',\n",
      " 'intensity': 1447.72,\n",
      " 'last_modified': '2016-08-10T17:37:52',\n",
      " 'mz': 56.7214,\n",
      " 'name': u'Untitled',\n",
      " 'prev_uid': u'origin',\n",
      " 'unique_id': u'162e36dee74942edbd45b51f50d191ee',\n",
      " 'username': u'bpb'},\n",
      "                    {'creation_time': '2016-08-10T17:36:59',\n",
      " 'description': u'No description',\n",
      " 'head_id': u'16cf1da0427b44d393aebbad9b8bd41c',\n",
      " 'intensity': 238468.0,\n",
      " 'last_modified': '2016-08-10T17:37:52',\n",
      " 'mz': 60.0454,\n",
      " 'name': u'Untitled',\n",
      " 'prev_uid': u'origin',\n",
      " 'unique_id': u'16cf1da0427b44d393aebbad9b8bd41c',\n",
      " 'username': u'bpb'},\n",
      "                    {'creation_time': '2016-08-10T17:36:59',\n",
      " 'description': u'No description',\n",
      " 'head_id': u'dff134c530434134881feb3072edc928',\n",
      " 'intensity': 1343.89,\n",
      " 'last_modified': '2016-08-10T17:37:52',\n",
      " 'mz': 70.0132,\n",
      " 'name': u'Untitled',\n",
      " 'prev_uid': u'origin',\n",
      " 'unique_id': u'dff134c530434134881feb3072edc928',\n",
      " 'username': u'bpb'},\n",
      "                    {'creation_time': '2016-08-10T17:36:59',\n",
      " 'description': u'No description',\n",
      " 'head_id': u'704e0208754545d188c23ed7e2129a04',\n",
      " 'intensity': 6348.91,\n",
      " 'last_modified': '2016-08-10T17:37:52',\n",
      " 'mz': 70.0297,\n",
      " 'name': u'Untitled',\n",
      " 'prev_uid': u'origin',\n",
      " 'unique_id': u'704e0208754545d188c23ed7e2129a04',\n",
      " 'username': u'bpb'},\n",
      "                    {'creation_time': '2016-08-10T17:36:59',\n",
      " 'description': u'No description',\n",
      " 'head_id': u'86a7995859d7438e9d2bf33aa3f76f2b',\n",
      " 'intensity': 1557.26,\n",
      " 'last_modified': '2016-08-10T17:37:52',\n",
      " 'mz': 78.3879,\n",
      " 'name': u'Untitled',\n",
      " 'prev_uid': u'origin',\n",
      " 'unique_id': u'86a7995859d7438e9d2bf33aa3f76f2b',\n",
      " 'username': u'bpb'},\n",
      "                    {'creation_time': '2016-08-10T17:36:59',\n",
      " 'description': u'No description',\n",
      " 'head_id': u'2d34ca3a90424d75af97f25e0889c93a',\n",
      " 'intensity': 1425.1,\n",
      " 'last_modified': '2016-08-10T17:37:52',\n",
      " 'mz': 81.8921,\n",
      " 'name': u'Untitled',\n",
      " 'prev_uid': u'origin',\n",
      " 'unique_id': u'2d34ca3a90424d75af97f25e0889c93a',\n",
      " 'username': u'bpb'},\n",
      "                    {'creation_time': '2016-08-10T17:36:59',\n",
      " 'description': u'No description',\n",
      " 'head_id': u'd0ec98c09278495f91ac902f0b603b9e',\n",
      " 'intensity': 1545.08,\n",
      " 'last_modified': '2016-08-10T17:37:52',\n",
      " 'mz': 83.8573,\n",
      " 'name': u'Untitled',\n",
      " 'prev_uid': u'origin',\n",
      " 'unique_id': u'd0ec98c09278495f91ac902f0b603b9e',\n",
      " 'username': u'bpb'},\n",
      "                    {'creation_time': '2016-08-10T17:36:59',\n",
      " 'description': u'No description',\n",
      " 'head_id': u'83573dd21fd04db58dc1d882935010eb',\n",
      " 'intensity': 38169.3,\n",
      " 'last_modified': '2016-08-10T17:37:52',\n",
      " 'mz': 88.0401,\n",
      " 'name': u'Untitled',\n",
      " 'prev_uid': u'origin',\n",
      " 'unique_id': u'83573dd21fd04db58dc1d882935010eb',\n",
      " 'username': u'bpb'},\n",
      "                    {'creation_time': '2016-08-10T17:36:59',\n",
      " 'description': u'No description',\n",
      " 'head_id': u'2dd26ed10b0b46b6b098bf6335f6bfe1',\n",
      " 'intensity': 1470.74,\n",
      " 'last_modified': '2016-08-10T17:37:52',\n",
      " 'mz': 89.2828,\n",
      " 'name': u'Untitled',\n",
      " 'prev_uid': u'origin',\n",
      " 'unique_id': u'2dd26ed10b0b46b6b098bf6335f6bfe1',\n",
      " 'username': u'bpb'},\n",
      "                    {'creation_time': '2016-08-10T17:36:59',\n",
      " 'description': u'No description',\n",
      " 'head_id': u'4ba02b14672f4ae8870430893d6093de',\n",
      " 'intensity': 13497.4,\n",
      " 'last_modified': '2016-08-10T17:37:52',\n",
      " 'mz': 106.05,\n",
      " 'name': u'Untitled',\n",
      " 'prev_uid': u'origin',\n",
      " 'unique_id': u'4ba02b14672f4ae8870430893d6093de',\n",
      " 'username': u'bpb'}],\n",
      " 'name': u'Untitled',\n",
      " 'polarity': 'positive',\n",
      " 'precursor_mz': 106.05,\n",
      " 'prev_uid': u'origin',\n",
      " 'ref_type': u'',\n",
      " 'technique': 'cid',\n",
      " 'unique_id': u'ee411b298e974842a5ecb87be4dd249b',\n",
      " 'username': u'bpb'}],\n",
      " 'head_id': u'2fa0785d32f648d39f71fabd8f8f1255',\n",
      " 'identification_grade': None,\n",
      " 'intensity_references': [],\n",
      " 'last_modified': '2016-08-10T17:37:52',\n",
      " 'mz_references': [],\n",
      " 'name': u'serine',\n",
      " 'prev_uid': u'origin',\n",
      " 'rt_references': [],\n",
      " 'unique_id': u'2fa0785d32f648d39f71fabd8f8f1255',\n",
      " 'username': u'bpb'}\n"
     ]
    }
   ],
   "source": [
    "print frags[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This print command bumps it up to 8 connections"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "MetAtlas 2.7",
   "language": "python",
   "name": "metatlas"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
{'fraction_non_alphanumeric': 0.22532042541587127, 'fraction_numerical': 0.10328606490319062, 'mean_word_length': 2.9742617176916823, 'pattern_counts': {'":': 100, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 7, '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': '4334492', 'n_tokens_mistral': 7273, 'n_tokens_neox': 6153, 'n_words': 772}