Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6719645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:07:02+00:00 2026-05-26T09:07:02+00:00

I am new to python (well to coding in general) and am trying to

  • 0

I am new to python (well to coding in general) and am trying to use it to analyze some data at work. I have a file like this:

    HWI-ST591_0064:5:1101:1228:2111#0/1 +   7included   11  A>G -   -
    HWI-ST591_0064:5:1101:1205:2125#0/1 +   genomic 17  A>G -   -
    HWI-ST591_0064:5:1101:1178:2129#0/1 +   7included   6   A>C 8   A>T
    HWI-ST591_0064:5:1101:1176:2164#0/1 +   7included   6   A>T 8   A>G
    HWI-ST591_0064:5:1101:1199:2234#0/1 +   7included   14  T>C 21  G>A
    HWI-ST591_0064:5:1101:1208:2249#0/1 +   7included   32  C>T -   -

Tab delimited. I am trying to create a dictionary that contains the first value of the line (a unique identifier) as a list of values that matches the joined last 4 values as the key, like this:

     {'32C>T--': ['HWI-ST591_0064:5:1101:1208:2249#0/1'], 
    '6A>C8A>C': ['HWI-ST591_0064:5:1101:1318:2090#0/1'], 
    '36A>G--': ['HWI-ST591_0064:5:1101:1425:2093#0/1'], 
     '----': ['HWI-ST591_0064:5:1101:1222:2225#0/1'], 
    '6A>C8A>T': ['HWI-ST591_0064:5:1101:1178:2129#0/1','HWIST591_0064:5:1101:1176:2164#0/1']}

This way I can then get a list of the unique identifies and count or sort or do the other things I need to do. I can get the dictionary made, but when I try to output it to a file I get an error. I think the problem is because this is a list, I keep getting the error

File “trial.py”, line 33, in
outFile.write(“%s\t%s\n” % (‘\t’ .join(key, mutReadDict[key])))
TypeError: unhashable type: ‘list’

Is there a way to make this work so I can have it in a file? I tried .iteritems() on the for loop making the dictionary but that didn’t seem to work. Thanks and here is my code:

inFile = open('path', 'rU')
outFile = open('path', 'w')

from collections import defaultdict

mutReadDict = defaultdict(list)

 for line in inFile:
entry               = line.strip('\n').split('\t')
fastQ_ID            = entry[0]
strand              = entry[1]
chromosome          = entry[2]
mut1pos             = entry[3]
mut1base            = entry[4]
mut2pos             = entry[5]
mut2base            = entry[6]

mutKey = mut1pos + mut1base + mut2pos + mut2base

if chromosome == '7included':
    mutReadDict[mutKey].append(fastQ_ID)
else:
    pass

keyList = [mutReadDict.keys()]
keyList.sort()

for key in keyList:
outFile.write("%s\t%s\n" % ('\t' .join(key, mutReadDict[key])))

outFile.close()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:07:03+00:00Added an answer on May 26, 2026 at 9:07 am

    I think you want:

    keyList = mutReadDict.keys()
    

    instead of

    keyList = [mutReadDict.keys()]
    

    You probably mean this too:

    for key in keyList:
        outFile.write("%s\t%s\n" % (key, '\t'.join(mutReadDict[key])))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Python (as well as GAE), I'm trying to include gaesessions in
I'm new to Python and I have been trying to search through html with
I'm new to python so I really don't know the language very well. the
Im new two python and am trying to grow a dictionary of dictionaries. I
I am new to Python, and I'm working on writing some database code using
I am really new to Python and I have been looking for an example
I'm new to python, and have a list of longs which I want to
I have the following python modules. Sorry if the code is ugly. This is
I have new to python and django I am creating poll application and in
I am new to Python, and I am currently stumped by this problem: I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.