Error in reading expression matrix
1
0
Entering edit mode
4.4 years ago

Hello I am trying to read expression matrix using the code :

adata.var = sc.read_csv('/home/sidrah19220/rna/auxfile/EXP0001_PCG_beforeQC.txt')

But I am facing this error:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/sidrah19220/anaconda3/envs/scenic_protocol/lib/python3.6/site-packages/anndata/_io/read.py", line 48, in read_csv return read_text(filename, delimiter, first_column_names, dtype) File "/home/sidrah19220/anaconda3/envs/scenic_protocol/lib/python3.6/site-packages/anndata/_io/read.py", line 322, in read_text return _read_text(f, delimiter, first_column_names, dtype) File "/home/sidrah19220/anaconda3/envs/scenic_protocol/lib/python3.6/site-packages/anndata/_io/read.py", line 352, in _read_text raise ValueError(f"Did not find delimiter {delimiter!r} in first line.") ValueError: Did not find delimiter ',' in first line.

adata.var = sc.read_csv('/home/sidrah19220/rna/auxfile/EXP0001_PCG_beforeQC.txt') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/sidrah19220/anaconda3/envs/scenic_protocol/lib/python3.6/site-packages/anndata/_io/read.py", line 48, in read_csv return read_text(filename, delimiter, first_column_names, dtype) File "/home/sidrah19220/anaconda3/envs/scenic_protocol/lib/python3.6/site-packages/anndata/_io/read.py", line 322, in read_text return _read_text(f, delimiter, first_column_names, dtype) File "/home/sidrah19220/anaconda3/envs/scenic_protocol/lib/python3.6/site-packages/anndata/_io/read.py", line 352, in _read_text raise ValueError(f"Did not find delimiter {delimiter!r} in first line.") ValueError: Did not find delimiter ',' in first line.

Please suggest the solution.

I even tried using the delimiter argument, but no help.

R python sequencing RNA-Seq • 2.1k views
ADD COMMENT
0
Entering edit mode

what's the delimiter in input file? By default, delimiter is comma. Seems that is not found in the very first line.

ADD REPLY
0
Entering edit mode

Since the input file is txt while it is looking for csv file you have to specify the delimiter argument. Else re-save the file with extension .csv. that should work.

ADD REPLY
1
Entering edit mode

It did work now. Thank you.

ADD REPLY
1
Entering edit mode
4.4 years ago
Shalu Jhanwar ▴ 540

It looks like the header line does not contain the same number of columns as the rest of the files. I'd suggest trying to load the dataset without header (e.g. header=None). If it reads successfully, then you can rename the columns directly in the object. Alternatively, you can skip the header line while reading the file into an object.

ADD COMMENT
0
Entering edit mode

I removed the delimiter argument from default. and it did work. Thnak you for the help

ADD REPLY
0
Entering edit mode

If an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one answer if they work. This will help future users that might find this post find the right answer.

Upvote|Bookmark|Accept

ADD REPLY
0
Entering edit mode

Thanks for the suggestion. I would do so next time onwards. :)

ADD REPLY

Login before adding your answer.

Traffic: 1742 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6