This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error in reading expression matrix

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

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

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.

1 answer

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.

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

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

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

Log in to answer this question.