0
$\begingroup$

I'm importing a CSV file with two columns. I've done this with other files, but this one is causing issues when trying to create rules to associate IDs with the titles. Here's a sample of the contents of the CSV file. I tried the CharacterEncodings Unicode and UTF-8. With Unicode, I get a bunch of Chinese characters. Which is weird because another file worked with Unicode.

protein/ACCA0AVT1,"Ubiquitin-like modifier-activating enzyme 6 (human)"

protein/ACCA0R666,"HTH-type transcriptional regulator EthR (Mycolicibacterium smegmatis MC2 155)"

protein/ACCA0SYQ0,"Prostaglandin E synthase (dog)"

As you can see in the picture, when I display the rules in a table it looks fine. When I try to call one it throws an error about "mixture of lists and nonlists".

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ I believe you have 619000 entries and some of them are wrong. Can you craft up a form of DeleteCases or Select that will toss the ones that are right or show the ones that are wrong and then use InputForm on the result to see exactly what all the characters including any quotes and spaces and control characters are? I am guessing the moment you see that you will realize what needs to be fixed. If it isn't easy to isolate the problem entries then perhaps keep hacking the size of the list in half until the problem goes away and then increase one at a time till you find a bad entry to see. $\endgroup$
    – Bill
    Commented May 19, 2023 at 3:31
  • $\begingroup$ @Bill that helped, thanks. I started copying lines from the original file to another 250k records at a time and everything was working fine. Look like there was an extra double-quote and line at the end of the file which may have been causing the issue. $\endgroup$
    – Sam B
    Commented May 19, 2023 at 15:05
  • $\begingroup$ WONDERFUL!! I realize it isn't ever going to happen, but I always wish for a "bouncing purple finger of fate" that points to exactly where in a line where I've made an almost certain mistake or even where I've done something that looks very odd and I should really rethink that. $\endgroup$
    – Bill
    Commented May 20, 2023 at 12:25

1 Answer 1

1
$\begingroup$

With MMA version 13.2: After deleting the empty lines, the following seems to work:

p = Import["d:/tmp/test.txt", "CSV"]

{{"protein/ACCA0AVT1", 
  "Ubiquitin-like modifier-activating enzyme 6 (human)"}, \
{"protein/ACCA0R666", 
  "HTH-type transcriptional regulator EthR (Mycolicibacterium \
smegmatis MC2 155)"}, {"protein/ACCA0SYQ0", 
  "Prostaglandin E synthase (dog)"}}
  • r = p /. {x_, y_} -> Rule[x, y]

    {"protein/ACCA0AVT1" -> "Ubiquitin-like modifier-activating enzyme 6 (human)", "protein/ACCA0R666" -> "HTH-type transcriptional regulator EthR (Mycolicibacterium
    smegmatis MC2 155)", "protein/ACCA0SYQ0" -> "Prostaglandin E synthase (dog)"}

"protein/ACCA0AVT1" /. r

"Ubiquitin-like modifier-activating enzyme 6 (human)"
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.