<commit_before>{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/data/SS_RNA_seq/dropseq_retina_dataset/digital_expression/GSM1626796_P14Retina_4\n"
     ]
    }
   ],
   "source": [
    "cd /data/SS_RNA_seq/dropseq_retina_dataset/digital_expression/GSM1626796_P14Retina_4/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import subprocess\n",
    "\n",
    "def get_barcode_dict(dir_path):\n",
    "    barcode_dict={}\n",
    "    for flname in os.listdir(dir_path): #iterating over the files in directory\n",
    "        assert flname.endswith('.sam') #Making sure all files in the directory\n",
    "        #are sam files with barcode as the file name\n",
    "        \n",
    "        barcodename=flname.split('.')[0]\n",
    "        \n",
    "        p = subprocess.Popen(['wc', '-l', flname], stdout=subprocess.PIPE, \n",
    "                             stderr=subprocess.PIPE)\n",
    "        out, err = p.communicate()\n",
    "        print out, err\n",
    "        \n",
    "        num_reads = int(out.split()[0])\n",
    "        \n",
    "        #print barcodename\n",
    "        assert barcodename not in barcode_dict #Making sure same barcode is not seen \n",
    "        #twice\n",
    "        \n",
    "        barcode_dict[barcodename]=num_reads\n",
    "    \n",
    "    return barcode_dict\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " wc: CTACTAAATTTG.sam: No such file or directory\n",
      "\n"
     ]
    },
    {
     "ename": "IndexError",
     "evalue": "list index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-9-038832684280>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0mdir_path\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'/data/SS_RNA_seq/dropseq_retina_dataset/digital_expression/GSM1626796_P14Retina_4/'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mbarcode_dict\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mget_barcode_dict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdir_path\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m<ipython-input-8-d11e96606bf7>\u001b[0m in \u001b[0;36mget_barcode_dict\u001b[1;34m(dir_path)\u001b[0m\n\u001b[0;32m     15\u001b[0m         \u001b[1;32mprint\u001b[0m \u001b[0mout\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0merr\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     16\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 17\u001b[1;33m         \u001b[0mnum_reads\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mout\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     18\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     19\u001b[0m         \u001b[1;31m#print barcodename\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mIndexError\u001b[0m: list index out of range"
     ]
    }
   ],
   "source": [
    "dir_path='/data/SS_RNA_seq/dropseq_retina_dataset/digital_expression/GSM1626796_P14Retina_4/'\n",
    "\n",
    "barcode_dict=get_barcode_dict(dir_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",<commit_msg>initial commit<commit_after>{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/data/SS_RNA_seq/dropseq_retina_dataset/digital_expression/GSM1626796_P14Retina_4\n"
     ]
    }
   ],
   "source": [
    "cd /data/SS_RNA_seq/dropseq_retina_dataset/digital_expression/GSM1626796_P14Retina_4/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import subprocess\n",
    "\n",
    "def get_barcode_dict(dir_path):\n",
    "    barcode_dict={}\n",
    "    for flname in os.listdir(dir_path): #iterating over the files in directory\n",
    "        assert flname.endswith('.sam') #Making sure all files in the directory\n",
    "        #are sam files with barcode as the file name\n",
    "        \n",
    "        barcodename=flname.split('.')[0]\n",
    "        \n",
    "        p = subprocess.Popen(['wc', '-l', dir_path+flname], stdout=subprocess.PIPE, \n",
    "                             stderr=subprocess.PIPE)\n",
    "        out, err = p.communicate()\n",
    "        #print out, err\n",
    "        \n",
    "        num_reads = int(out.split()[0])\n",
    "        \n",
    "        #print barcodename\n",
    "        assert barcodename not in barcode_dict #Making sure same barcode is not seen \n",
    "        #twice\n",
    "        \n",
    "        barcode_dict[barcodename]=num_reads\n",
    "    \n",
    "    return barcode_dict\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "dir_path='/data/SS_RNA_seq/dropseq_retina_dataset/digital_expression/GSM1626796_P14Retina_4/'\n",
    "\n",
    "barcode_dict=get_barcode_dict(dir_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
{'fraction_non_alphanumeric': 0.195403981264637, 'fraction_numerical': 0.0977751756440281, 'mean_word_length': 2.4915687276443537, 'pattern_counts': {'":': 85, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4190639', 'n_tokens_mistral': 3334, 'n_tokens_neox': 2955, 'n_words': 354}