Advertisement
jbjares

aloka_code

Sep 3rd, 2015
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.78 KB | None | 0 0
  1. __author__ = 'jbjares'
  2.  
  3. import csv
  4. import re
  5. import sys
  6.  
  7. def isGreaterThenZeroDotFive(number,actualRow,actualColumn):
  8.     try:
  9.         if float(number) > float(0.5):
  10.             print(number,actualRow,actualColumn)
  11.     except NameError:
  12.         pass
  13.  
  14.     return False
  15.  
  16. with open('gene.matrix.csv', newline='') as csvfile:
  17.     spamreader = csv.reader(csvfile, delimiter='"', quotechar=',')
  18.     columnsName = list()
  19.     rowsName = list()
  20.     countRows = 0
  21.     actualColumn = 0
  22.  
  23.     for row in spamreader:
  24.         for content in row:
  25.             if countRows == 0 and len(columnsName) < 16 and content!='':
  26.                 columnsName.append(content)
  27.                 continue
  28.  
  29.  
  30.             # Cleaning empty and string fields
  31.             if content == '':
  32.                 continue
  33.  
  34.             if actualColumn<=16:
  35.                 actualColumn = actualColumn+1
  36.             if actualColumn==16:
  37.                 actualColumn = 0;
  38.  
  39.             if countRows==0:
  40.                 countRows = countRows+1
  41.  
  42.             #avoid numbers as list of char
  43.             if countRows>0 and len(content)<30:
  44.                 rowsName.append(content)
  45.  
  46.             result = re.search('[a-zA-Z]+',content)
  47.             #just to avoid not numbers
  48.             if result != None:
  49.                 continue
  50.             #Start processment, just for numbers.
  51.             else:
  52.                 try:
  53.                     words = content.split(',')
  54.                     for word in words:
  55.                         if(isinstance(word, str)):
  56.                             #treatment for found special case
  57.                             specialCaseWords = word.split('.')
  58.                             lenf = len(specialCaseWords)
  59.                             if lenf >= 3:
  60.                                 firstWord = None
  61.                                 restWord = None
  62.                                 middleWord = None
  63.                                 afterSecondDotWord = None
  64.                                 fixedNumberA = None
  65.                                 fixedNumberB = None
  66.                                 count = 1
  67.                                 for specialCaseWord in specialCaseWords:
  68.                                     if count == 1 and firstWord == None:
  69.                                         firstWord = specialCaseWord
  70.                                     if count == 2 and firstWord != None:
  71.                                         lenfStart = len(specialCaseWord)-1
  72.                                         lenfFinal = len(specialCaseWord)
  73.                                         restWord = specialCaseWord[lenfStart:lenfFinal]
  74.                                         middleWord = specialCaseWord[0:lenfStart]
  75.                                     if count == 3 and firstWord != None:
  76.                                         afterSecondDotWord = specialCaseWord
  77.                                         count = count+1
  78.                                     if(count==4):
  79.                                         fixedNumberA = firstWord+'.'+middleWord
  80.                                         fixedNumberB = restWord+'.'+afterSecondDotWord
  81.                                         isGreaterThenZeroDotFive(fixedNumberA,countRows,actualColumn)
  82.                                         actualColumn = actualColumn+1;
  83.                                         isGreaterThenZeroDotFive(fixedNumberB,countRows,actualColumn)
  84.                                         actualColumn = actualColumn+1;
  85.                                     count = count+1
  86.                             else:
  87.                                 isGreaterThenZeroDotFive(word,countRows,actualColumn)
  88.                     countRows = countRows+1
  89.  
  90.                 except NameError:
  91.                     pass
  92.  
  93.  
  94.  
  95. #print(columnsName+" "+rowsName)
  96. print(rowsName)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement