top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

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

0 votes

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

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')
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)

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

posted Jun 9, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

1) You probably planned to use the loop above to populate the ercc_contigs dict, but there's no code for that.

2) Remember that ercc_contigs is empty; therefore the test

3) I think ercc_rpkm = defaultdict(float) should suffice.

4) You can remove all strip() method calls here as line.split() implicitly removes all whitespace.

answer Jun 9, 2013 by anonymous
Similar Questions
+4 votes

I am getting the following error -

UserProfile.picture: (fields.E210) Cannot use ImageField because Pillow is not installed.

HINT: Get Pillow at or run command "pip install pillow".
System check identified 1 issue (0 silenced).

This is installation Summary of pillow

version Pillow 2.6.1
platform linux 3.4.2 (default, Oct 8 2014, 13:08:17) [GCC 4.9.1]

--- TKINTER support available
--- JPEG support available
--- OPENJPEG (JPEG2000) support not available
--- ZLIB (PNG/ZIP) support available
--- LIBTIFF support available
--- FREETYPE2 support available
--- LITTLECMS2 support available
--- WEBP support available
--- WEBPMUX support available
+3 votes

input: 1 2 3 4 5
output: 5 4 1 2 3 or 1 2 3 5 4

Can any one tell?

0 votes

I am running a python script and it will create a file name like filename0.0.0 and If I run it again then new file will create one more like filename0.0.1......
my code is-

i = 0
for i in range(1000):
 with open('filename%d.%d.%d.json'%(0,0,i,)): pass
 except IOError:
 dataFile = file('filename%d.%d.%d.json'%(0,0,i,), 'a+')

But It will take more time after creating many files, So i want to store value of last var "i" in a variable so that when I run my script again then I can use it. for example-
my last created file is filename0.0.27 then it should store 27 in a variable and when i run again then new file should be created 0.0.28 according to last value "27", so that i could save time and it can create file fast..