top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

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 Google+ Share Button LinkedIn Share Button Multiple Social 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..

0 votes

Does any one have a good solution for how to embed the output of a subprocess (ex. subprocess.Popen("htop", stdout=subprocess.PIPE)) into an ncurses window? So for example, the terminal window is broken up into quadrants and the top right has htop running inside. I'd imagine this would involve some kind of terminal emulation as the dimensions of the window would need to be queried by htop.

Useful Links with Similar Problem
Contact Us
+91 9880187415
#470/147, 3rd Floor, 5th Main,
HSR Layout Sector 7,
Bangalore - 560102,
Karnataka INDIA.