J-Express forum
June 04, 2020, 03:41:20 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: J-Express 2011 released. Download from jexpress.bioinfo.no
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Collapse probes on genes  (Read 5468 times)
annekristin
Administrator
Jr. Member
*****
Posts: 61


View Profile Email
« on: June 08, 2007, 10:37:50 AM »

from java.lang import String
from expresscomponents.MissingValues import Stat

APMColumn = 2

#set column id used as unique id's before collapsing
old_id=0
#set column id to be used as unique id after collapsing
id_col=1

inf = data.getInfos()
n=data.getDataLength()
m=data.getDataWidth()

other_inf_indices = []

for i in range(len(inf[0])):
   if (i == old_id ):
      continue
   elif (i == id_col):
      continue
   other_inf_indices = other_inf_indices +



a = data.clone()

a.setFile("Probes collapsed to genes")
dat = data.getData()

newdata = []

unique_genes = []

# lager liste over unike gener p? gen-niv?
for i in range(n):
   gene = inf[id_col]
   if gene != '':
      if gene not in unique_genes:
         unique_genes.append(inf[id_col])

#lager en ordbok med de unike genene og henger p? en tom tabell
u_genes = {}
for i in unique_genes:
   u_genes = []

#putter indexene til probene inn i tabellen som er knyttet til hvert gen i ordboken
indices = []
for i in range(n):
   gene = inf[id_col]
   if gene !='':
      indices =u_genes[gene]
      indices.append(i)

newrowID = []

for k, v in u_genes.items():
   newline = []

   for j in range(m):
      nval=[]
      tmp=''
      for i in range(len(v)):
         nval = nval+[dat[v][j]]
         if tmp!='':
            tmp = tmp+','+inf[v][old_id]
         else:
            tmp = inf[v][old_id]
      newline = newline+[Stat.median(nval)]
   
   rest=[]
   for id in other_inf_indices:
      rest = rest+[inf[v[0]][id]]
   newrowID = newrowID+[ [k]+[tmp]+[inf[v[0]][old_id] ]+rest]

   newdata = newdata+[newline]

a.removeFromParent()
main.addNode(a,data)
a.unLink(0)

a.setData(newdata)

infoHeader = data.getInfoHeaders()
header = [infoHeader[id_col], 'collapsed '+infoHeader[old_id], infoHeader[old_id]]
for id in other_inf_indices:
   header = header+[infoHeader[id]]

a.setInfoHeaders(header)

#newcolumnID = []
#for j in range(n):
#   newColumn =[inf[j]]
#   print newColumn
#   newcolumnID=newcolumnID+[newColumn]

#print 'hei',(newcolumnID)

#a.setColInfos(newcolumnID)

a.setInfos(newrowID)

a.setColInfoHeaders( ["New identifiers"] )
« Last Edit: June 08, 2007, 11:21:02 AM by annekristin » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.14 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!