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 8317753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:42:50+00:00 2026-06-08T21:42:50+00:00

I have a dictionary of compound objects made up of a string, a list,

  • 0

I have a dictionary of compound objects made up of a string, a list, and two ints.

I am looping through this dictionary, performing some tests, and then based on these tests saving the currently tested object to a new dictionary and then modify some of the attributes. This so far has been putting a reference to the object in the new dictionary so when I change the some of the attributes, then the old object changes also and I want to avoid this behaviour.

I tried using the copy.copy and copy.deepcopy methods from the copy module, but for some reason after copying I was not able to change the attributes. They would simply remain as they were in the original.

I should say I am pretty new to OOP, so aim any suggestions to moron level!

So in the code below, pathways is a dictionary of pathway objects, and variants is just a list.
names() and addMutant() are methods belonging to the pathway object.

In case it helps: pathway objects hold a list of genes (also another object) that belong to that pathway. I want to find out which pathways are represented in the list of variants (a list of gene names) and then return a new (smaller) dictionary of pathways that will have been modified to record the number of mutated genes in each pathway. The addMutant() method simply increments a int attribute that belongs to the pathway object.

def method(variants, pathways):
    vpathways = {}
            check = 0
            for var in variants:
                for k,v in pathways.iteritems():
                    if(var in v.names()):
                        check +=1
                        vpathways[k] = copy.deepcopy(v)
                        vpathways[k].addMutant()
     return(vpathways)

When I did this, vpathways did contain the right pathways, and but the number of mutations for each pathway was all still 0. I added a print statement to the addMutant() method and it is definitely being called, and the number of mutations attributes is increased, but not in the final object.

Edit: Pathway class definition:

class Pathway():
    def __init__(self, pid = None, genes = [],nmut = 0 ):
        self.pid = pid
        self.genes = genes
        self.length = 0
        self.nmut = nmut
        for g in self.genes:
            self.length += g.seqlen
    def __str__(self):
        return('{0} pathway containing {1} genes, with a total sequence length of {2} and {3} mutations'.format(self.pid, len(self.genes), self.length, self.nmut))
    def __repr__(self):
        return self.__str__()   
    def addGene2Pathway(self,g):
        self.genes.append(g)
        self.length += g.seqlen
    def addMutant(self):
        self.nmut +=1  
    def names(self):
        l = []
        for g in self.genes:
            l.append(g.entrezid)
        return l
  • 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-06-08T21:42:52+00:00Added an answer on June 8, 2026 at 9:42 pm
    vpathways[k] = copy.deepcopy(v)
    

    replaces whatever vpathways[k] contained before so at most one .addMutant() might work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dictionary, user_dict, and create a list for each user value, this
I have a dictionary list of words, some of the words containing sequences like
Suppose I have Dictionary like this: Dictionary<string, string> values = new Dictionary<string, string>() {
I have a Dictionary of Dictionarys of Array of Objects. Just like this: A
I have dictionary of about 20,000 objects The key is a string representation of
I have dictionary, like Dictionary<string, bool> accValues = new Dictionary<string, bool>() And I want
i have this dictionary: a) 2012 UN NEWNW = ( 2012/06/04 Saudi Arabia Huge
I have a dictionary public static IDictionary<string, IList<string>> checksCollection = new Dictionary<string, IList<string>>(); I
I have a particular case where using compound dictionary keys would make a task
I have dictionary entries that are read to a Dictionary <string,string> myDict=null; The entries

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.