GitHub PullRequestReviewCommentEvent at 2014-05-12 15:06:33
Repository: varify
Actor: naegelyd
Payload: {"comment":{"url":"https://api.github.com/repos/cbmi/varify/pulls/comments/12533902","id":12533902,"diff_hunk":"@@ -390,6 +393,200 @@ def get(self, request, pk):\n         return serialize(instance, **self.template)\n \n \n+class UploadResource(ThrottledResource):\n+\n+    supported_content_types = ('multipart/form-data',\n+                               'application/vnd.openxmlformats-officedocument'\n+                               + 'spreadsheetml.sheet', )\n+\n+    def change(self, ref, a1, a2):\n+        \"\"\" Given ref allele1 and allele2, returns the type of change.\n+            The only case of an amino acid insertion is when the ref is\n+            represented as a '.'\n+            In all cases of an insertion or a deletion, the genomic starting\n+            position is decremented by one and the ref and alt values change\n+            to resemble their representations in the varify database.\"\"\"\n+        if ref == '.':\n+            return 'INSERTION'\n+        elif a1 == '.' or a2 == '.':\n+            return 'DELETION'\n+        else:\n+            return 'NOCHANGE'\n+\n+    # Consume the variants excel file and search the database for\n+    # Matching queries\n+    def post(self, request):\n+\n+        # Samplename must be unique and so must the batch. The latter is not\n+        # specified in a variant list excel sheet.\n+        sampleName = request.POST['sampleName']\n+        sample = Sample.objects.filter(name=sampleName)\n+        sample = sample[0]\n+\n+        # Try opening the excel file that was uploaded\n+        try:\n+            variantBook = request.FILES['qqfile']\n+            workbook = openpyxl.load_workbook(variantBook)\n+        except:\n+            return HttpResponse(status=codes.unprocessable_entity)\n+\n+        sheet = workbook.get_active_sheet()\n+\n+        # Find the row where our useful data starts\n+        startRow = 0\n+        for row in range(0, len(sheet.rows)):\n+            cellValue = sheet.cell(row=row, column=0).value\n+            if cellValue == 'Chromosome':\n+                    startRow = row\n+                    break\n+\n+        # retrive all the fields from the sheet\n+        fields = [sheet.cell(row=startRow, column=col).value\n+                  for col in range(len(sheet.columns))]\n+\n+        fields = [field.lower() for field in fields]\n+\n+        matches = set()\n+        noMatches = []\n+\n+        for row in range(startRow + 1, len(sheet.rows)):\n+            # Retrive rsid, ref, start and chr from our spreadsheet\n+            # So we can retrive objects from our database\n+            dbsnpValue = sheet.cell(row=row,\n+                                    column=fields.index('dbsnp')).value\n+            dbsnpValue = dbsnpValue if dbsnpValue else None\n+            refValue = sheet.cell(row=row,\n+                                  column=fields.index('reference')).value\n+            startValue = sheet.cell(row=row,\n+                                    column=fields.index('start')).value\n+            chrLabel = \\\n+                sheet.cell(row=row,\n+                           column=fields.index('chromosome')).value\n+            print chrLabel","path":"varify/samples/resources.py","position":88,"original_position":88,"commit_id":"477f4236a5162d967a9691d59d67e299f78c4351","original_commit_id":"477f4236a5162d967a9691d59d67e299f78c4351","user":{"login":"naegelyd","id":3911912,"avatar_url":"https://avatars.githubusercontent.com/u/3911912?","gravatar_id":"f2b6f2cec914521893ab3f5de23d1a4c","url":"https://api.github.com/users/naegelyd","html_url":"https://github.com/naegelyd","followers_url":"https://api.github.com/users/naegelyd/followers","following_url":"https://api.github.com/users/naegelyd/following{/other_user}","gists_url":"https://api.github.com/users/naegelyd/gists{/gist_id}","starred_url":"https://api.github.com/users/naegelyd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/naegelyd/subscriptions","organizations_url":"https://api.github.com/users/naegelyd/orgs","repos_url":"https://api.github.com/users/naegelyd/repos","events_url":"https://api.github.com/users/naegelyd/events{/privacy}","received_events_url":"https://api.github.com/users/naegelyd/received_events","type":"User","site_admin":false},"body":"Remove print statements. If anything is truly important and these aren't meant for your own testing purposes, then change these to log at the appropriate level.","created_at":"2014-05-12T15:06:33Z","updated_at":"2014-05-12T15:06:33Z","html_url":"https://github.com/cbmi/varify/pull/297#discussion_r12533902","pull_request_url":"https://api.github.com/repos/cbmi/varify/pulls/297","_links":{"self":{"href":"https://api.github.com/repos/cbmi/varify/pulls/comments/12533902"},"html":{"href":"https://github.com/cbmi/varify/pull/297#discussion_r12533902"},"pull_request":{"href":"https://api.github.com/repos/cbmi/varify/pulls/297"}}}}