Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #47444

I used defaultdic to store some variables but the output is blank

X-Received by 10.224.42.141 with SMTP id s13mr5690582qae.3.1370772748540; Sun, 09 Jun 2013 03:12:28 -0700 (PDT)
X-Received by 10.50.20.136 with SMTP id n8mr388729ige.5.1370772748504; Sun, 09 Jun 2013 03:12:28 -0700 (PDT)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!p1no3815990qaj.0!news-out.google.com!y6ni1323qax.0!nntp.google.com!ch1no3271947qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Sun, 9 Jun 2013 03:12:28 -0700 (PDT)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=222.14.252.104; posting-account=4fiQAQkAAAANjB-r4EnBE_ZGEHG3iI9X
NNTP-Posting-Host 222.14.252.104
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <35dd1554-de27-4209-b62e-6a2968c19d0c@googlegroups.com> (permalink)
Subject I used defaultdic to store some variables but the output is blank
From claire morandin <claire.morandin@gmail.com>
Injection-Date Sun, 09 Jun 2013 10:12:28 +0000
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Xref csiph.com comp.lang.python:47444

Show key headers only | View raw


I have the following script which does not return anything, no apparent mistake but my output file is empty.I am just trying to extract some decimal number from a file according to their names which are in another file. from collections import defaultdict import numpy as np

[code]ercc_contigs= {}
for line in open ('Faq_ERCC_contigs_name.txt'):
    gene = line.strip().split()

ercc_rpkm = defaultdict(lambda: np.zeros(1, dtype=float))
output_file = open('out.txt','w')

rpkm_file = open('RSEM_Faq_Q1.genes.results.txt')
rpkm_file.readline()
for line in rpkm_file:
    line = line.strip()
    columns =  line.strip().split()
    gene = columns[0].strip()
    rpkm_value = float(columns[6].strip())
    if gene in ercc_contigs:
        ercc_rpkm[gene] += rpkm_value

ercc_fh = open ('out.txt','w')
for gene, rpkm_value in ercc_rpkm.iteritems():
    ercc = '{0}\t{1}\n'.format(gene, rpkm_value)
    ercc_fh.write (ercc)[/code]

If someone could help me spot what's wrong it would be much appreciate cheers

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

I used defaultdic to store some variables but the output is blank claire morandin <claire.morandin@gmail.com> - 2013-06-09 03:12 -0700
  Re: I used defaultdic to store some variables but the output is blank Peter Otten <__peter__@web.de> - 2013-06-09 13:56 +0200
  Re: I used defaultdic to store some variables but the output is blank claire morandin <claire.morandin@gmail.com> - 2013-06-09 05:27 -0700
    Re: I used defaultdic to store some variables but the output is blank Peter Otten <__peter__@web.de> - 2013-06-09 14:46 +0200

csiph-web