473,671 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Memory error due to the huge/huge input file size

Hello Everyone,

I need to read a .csv file which has a size of 2.26 GB . And I wrote a
Python script , where I need to read this file. And my Computer has 2
GB RAM Please see the code as follows:

"""
This program has been developed to retrieve all the promoter sequences
for the specified
list of genes in the given cluster

So, this program will act as a substitute to the whole EZRetrieve
system

Input arguments:

1) Cluster.txt or DowRatClust1617 18bwithDummy.tx t
2) TransProCrossRe ferenceAndSeque nces.csv -This is the file that has
all the promoter sequences
3) -2000
4) 500
"""

import time
import csv
import sys
import linecache
import re
from sets import Set
import gc

print time.localtime( )

fileInputHandle r = open(sys.argv[1],"r")
line = fileInputHandle r.readline()

refSeqIDsinTran sPro = []
promoterSequenc esinTransPro = []
reader2 = csv.reader(open (sys.argv[2],"rb"))
reader2_list = []
reader2_list.ex tend(reader2)

for data2 in reader2_list:
refSeqIDsinTran sPro.append(dat a2[3])
for data2 in reader2_list:
promoterSequenc esinTransPro.ap pend(data2[4])

while line:
l = line.rstrip('\n ')
for j in range(1,len(ref SeqIDsinTransPr o)):
found = re.search(l,ref SeqIDsinTransPr o[j])
if found:
"""promoterSequ encesinTransPro[j] """
print l

line = fileInputHandle r.readline()
fileInputHandle r.close()
The error that I got is given as follows:
Traceback (most recent call last):
File "RefSeqsToPromo terSequences.py ", line 31, in <module>
reader2_list.ex tend(reader2)
MemoryError

I understand that the issue is Memory error and it is caused because
of the line reader2_list.ex tend(reader2). Is there any other
alternative method in reading the .csv file line by line?

sincerely,
Suprabhath
Nov 10 '08 #1
3 4553
On Tue, Nov 11, 2008 at 7:47 AM, <te******@gmail .comwrote:
refSeqIDsinTran sPro = []
promoterSequenc esinTransPro = []
reader2 = csv.reader(open (sys.argv[2],"rb"))
reader2_list = []
reader2_list.ex tend(reader2)
Without testing, this looks like you're reading the _ENTIRE_
input stream into memory! Try this:

def readCSV(file):

if type(file) == str:
fd = open(file, "rU")
else:
fd = file

sniffer = csv.Sniffer()
dialect = sniffer.sniff(f d.readline())
fd.seek(0)

reader = csv.reader(fd, dialect)
for line in reader:
yield line

for line in readCSV(open("f oo.csv", "r")):
...

--JamesMills

--
--
-- "Problems are solved by method"
Nov 10 '08 #2
On Nov 11, 8:47*am, tejsu...@gmail. com wrote:
import linecache
Why???
reader2 = csv.reader(open (sys.argv[2],"rb"))
reader2_list = []
reader2_list.ex tend(reader2)

for data2 in reader2_list:
* *refSeqIDsinTra nsPro.append(da ta2[3])
for data2 in reader2_list:
* *promoterSequen cesinTransPro.a ppend(data2[4])

All you need to do is replace the above by:

reader2 = csv.reader(open (sys.argv[2],"rb"))

for data2 in reader2:
refSeqIDsinTran sPro.append(dat a2[3])
promoterSequenc esinTransPro.ap pend(data2[4])
Nov 10 '08 #3
On Nov 10, 4:47*pm, tejsu...@gmail. com wrote:
Hello Everyone,

I need to read a .csv file which has a size of 2.26 GB . And I wrote a
Python script , where I need to read this file. And my Computer has 2
GB RAM Please see the code as follows:

"""
This program has been developed to retrieve all the promoter sequences
for the specified
list of genes in the given cluster

So, this program will act as a substitute to the whole EZRetrieve
system

Input arguments:

1) Cluster.txt or DowRatClust1617 18bwithDummy.tx t
2) TransProCrossRe ferenceAndSeque nces.csv -This is the file that has
all the promoter sequences
3) -2000
4) 500
"""

import time
import csv
import sys
import linecache
import re
from sets import Set
import gc

print time.localtime( )

fileInputHandle r = open(sys.argv[1],"r")
line = fileInputHandle r.readline()

refSeqIDsinTran sPro = []
promoterSequenc esinTransPro = []
reader2 = csv.reader(open (sys.argv[2],"rb"))
reader2_list = []
reader2_list.ex tend(reader2)

for data2 in reader2_list:
* *refSeqIDsinTra nsPro.append(da ta2[3])
for data2 in reader2_list:
* *promoterSequen cesinTransPro.a ppend(data2[4])

while line:
* *l = line.rstrip('\n ')
* *for j in range(1,len(ref SeqIDsinTransPr o)):
* * * found = re.search(l,ref SeqIDsinTransPr o[j])
* * * if found:
* * * * *"""promoterSeq uencesinTransPr o[j] *"""
* * * * *print l

* *line = fileInputHandle r.readline()

fileInputHandle r.close()

The error that I got is given as follows:
Traceback (most recent call last):
* File "RefSeqsToPromo terSequences.py ", line 31, in <module>
* * reader2_list.ex tend(reader2)
MemoryError

I understand that the issue is Memory error and it is caused because
of the *line reader2_list.ex tend(reader2). Is there any other
alternative method in reading the .csv file *line by line?

sincerely,
Suprabhath
Thanks a Lot James Mills. It worked

Nov 20 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4531
by: Joe | last post by:
I have an upload file operation in the web application. UploadForm.asp is the form, and UploadAction.asp is the form processing. //UploadForm.asp <FORM NAME="InputForm" ACTION="UploadAction.asp" METHOD="POST" enctype=multipart/form-data> <input type="file" name="fileName"> //etc ... </FORM>
67
4249
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. Unfortunately these ad hominem rhetorts are frequently introduced into purely technical discussions on the feasibility of supporting such functionality in C++. That usually serves to divert the discussion from the technical subject to a discussion of the...
10
3804
by: VM | last post by:
How can I limit the use of the PC's virtual memory? I'm running a process that basically takes a txt file and loads it to a datatable. The problem is that the file is over 400,000 lines long (77 MB) and after a while I get the Windows message saying that the virtual memory's getting really low. Plus the machine gets really sluggish (with multi-threading). Is it possible to use the virtual memory until it reaches a certain limit and then use...
12
5354
by: Jeff Calico | last post by:
I have 2 XML data files that I want to extract data from simultaneously and transform with XSLT to generate a report. The first file is huge and when XSLT builds the DOM tree in memory, it runs out of space. I only need a few branches of elements from the original XML, so I am seeking a recomended way of building a DOM for XSLT of only the elements that I need. I'm writing a Java application that invokes Xalan, and reading up on SAX...
11
7585
by: Hari Sekhon | last post by:
I do import zipfile zip=zipfile.ZipFile('d:\somepath\cdimage.zip') zip.namelist() then either of the two: A) file('someimage.iso','w').write(zip.read('someimage.iso'))
30
4684
by: MAG1301 | last post by:
I've detected memory leaks in our huge .NET 1.1 C# application but couldn't localize them directly. So I've reduced the code to the following console application: using System; using System.IO; namespace MemLeak { class MemLeak
11
3771
by: skumar434 | last post by:
Hi everybody, I am faceing problem while assigning the memory dynamically to a array of structures . Suppose I have a structure typedef struct hom_id{ int32_t nod_de; int32_t hom_id;
2
3271
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres and arrays of pointers to them. I have gotten the program to compile with gcc on WinXP. If the file i read doesnt have alot of records, it runs thru. But once i add more, it dies. In this program i have 4 files setup to read. The
7
1892
by: ucfcpegirl06 | last post by:
Hello, Maybe someone can help me with this. I believe I have a memory allocation problem. The program crashes w/ a debug error. cpp file: #include <cstdio> #include <cstring> #include <iostream> // C++ I/O #include <iomanip> // C++ I/O Manipulators
0
8474
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8912
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8597
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8669
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2049
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1807
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.