How to use get_family method in avocado

Best Python code snippet using avocado_python

test_x_dominant.py

Source:test_x_dominant.py Github

copy

Full Screen

1from genmod.annotate_models.models import check_X_dominant2from genmod.vcf_tools import Genotype3from ped_parser import FamilyParser4FAMILY_FILE = "tests/fixtures/recessive_trio.ped"5def get_family(family_file = None, family_lines = None):6 """Return a family object7 8 """9 family = None10 if family_file:11 family = FamilyParser(open(family_file, 'r'))12 elif family_lines:13 family = FamilyParser(family_lines)14 15 return family16################# Test affected ###############17def test_x_affected_recessive_male():18 """Test a sick male19 """20 family_lines = [21 "#FamilyID\tSampleID\tFather\tMother\tSex\tPhenotype\n",22 "1\tproband\t0\t0\t1\t2\n"23 ]24 25 family = get_family(family_lines=family_lines)26 27 recessive_variant = {'genotypes': {}}28 recessive_variant['genotypes']['proband'] = Genotype(**{'GT':'0/1'})29 30 assert check_X_dominant(31 variant = recessive_variant,32 family = family33 ) == True34def test_x_affected_recessive_female():35 """Test a sick heterozygote female36 37 Females needs to bo hom alt to follow pattern38 """39 family_lines = [40 "#FamilyID\tSampleID\tFather\tMother\tSex\tPhenotype\n",41 "1\tproband\t0\t0\t2\t2\n"42 ]43 44 family = get_family(family_lines=family_lines)45 46 recessive_variant = {'genotypes': {}}47 recessive_variant['genotypes']['proband'] = Genotype(**{'GT':'0/1'})48 49 assert check_X_dominant(50 variant = recessive_variant,51 family = family52 ) == True53def test_x_affected_homozygote_male():54 """Test an affected homozygote male"""55 56 family_lines = [57 "#FamilyID\tSampleID\tFather\tMother\tSex\tPhenotype\n",58 "1\tproband\t0\t0\t1\t2\n"59 ]60 61 family = get_family(family_lines=family_lines)62 63 homozygote_variant = {'genotypes': {}}64 homozygote_variant['genotypes']['proband'] = Genotype(**{'GT':'1/1'})65 66 assert check_X_dominant(67 variant = homozygote_variant,68 family = family69 ) == True70def test_x_affected_homozygote_female():71 """Test an affected homozygote male"""72 73 family_lines = [74 "#FamilyID\tSampleID\tFather\tMother\tSex\tPhenotype\n",75 "1\tproband\t0\t0\t2\t2\n"76 ]77 78 family = get_family(family_lines=family_lines)79 80 homozygote_variant = {'genotypes': {}}81 homozygote_variant['genotypes']['proband'] = Genotype(**{'GT':'1/1'})82 83 assert check_X_dominant(84 variant = homozygote_variant,85 family = family86 ) == True87def test_x_affected_male_ref_call():88 """Test an affected ref call male"""89 90 family_lines = [91 "#FamilyID\tSampleID\tFather\tMother\tSex\tPhenotype\n",92 "1\tproband\t0\t0\t1\t2\n"93 ]94 95 family = get_family(family_lines=family_lines)96 97 homozygote_variant = {'genotypes': {}}98 homozygote_variant['genotypes']['proband'] = Genotype(**{'GT':'0/0'})99 100 assert check_X_dominant(101 variant = homozygote_variant,102 family = family103 ) == False104def test_x_affected_female_ref_call():105 """Test an affected ref call male"""106 107 family_lines = [108 "#FamilyID\tSampleID\tFather\tMother\tSex\tPhenotype\n",109 "1\tproband\t0\t0\t2\t2\n"110 ]111 112 family = get_family(family_lines=family_lines)113 114 homozygote_variant = {'genotypes': {}}115 homozygote_variant['genotypes']['proband'] = Genotype(**{'GT':'0/0'})116 117 assert check_X_dominant(118 variant = homozygote_variant,119 family = family120 ) == False121 122def test_x_affected_no_call_male():123 """Test a sick male with no gt call124 125 This should be true since there is no information that contradicts the model126 """127 family_lines = [128 "#FamilyID\tSampleID\tFather\tMother\tSex\tPhenotype\n",129 "1\tproband\t0\t0\t1\t2\n"130 ]131 132 family = get_family(family_lines=family_lines)133 134 no_call_variant = {'genotypes': {}}135 no_call_variant['genotypes']['proband'] = Genotype(**{'GT':'./.'})136 137 assert check_X_dominant(138 variant = no_call_variant,139 family = family140 ) == True141def test_x_affected_no_call_male_strict():142 """Test a sick male with no gt call143 144 This should not be true since we allways need 'proof'145 for an inheritance pattern if strict mode.146 """147 family_lines = [148 "#FamilyID\tSampleID\tFather\tMother\tSex\tPhenotype\n",149 "1\tproband\t0\t0\t1\t2\n"150 ]151 152 family = get_family(family_lines=family_lines)153 154 no_call_variant = {'genotypes': {}}155 no_call_variant['genotypes']['proband'] = Genotype(**{'GT':'./.'})156 157 assert check_X_dominant(158 variant = no_call_variant,159 family = family,160 strict = True161 ) == False162############### Test healthy ##############163def test_x_healthy_recessive_male():164 """Test a healthy recessive male165 """166 family_lines = [167 "#FamilyID\tSampleID\tFather\tMother\tSex\tPhenotype\n",168 "1\tproband\t0\t0\t1\t1\n"169 ]170 171 family = get_family(family_lines=family_lines)172 173 recessive_variant = {'genotypes': {}}174 recessive_variant['genotypes']['proband'] = Genotype(**{'GT':'0/1'})175 176 assert check_X_dominant(177 variant = recessive_variant,178 family = family179 ) == False180def test_x_healthy_recessive_female():181 """Test a healthy heterozygote female182 183 Females needs to bo hom alt to follow pattern184 """185 family_lines = [186 "#FamilyID\tSampleID\tFather\tMother\tSex\tPhenotype\n",187 "1\tproband\t0\t0\t2\t1\n"188 ]189 190 family = get_family(family_lines=family_lines)191 192 recessive_variant = {'genotypes': {}}193 recessive_variant['genotypes']['proband'] = Genotype(**{'GT':'0/1'})194 195 assert check_X_dominant(196 variant = recessive_variant,197 family = family198 ) == True199def test_x_healthy_homozygote_male():200 """Test an healthy homozygote male"""201 202 family_lines = [203 "#FamilyID\tSampleID\tFather\tMother\tSex\tPhenotype\n",204 "1\tproband\t0\t0\t1\t1\n"205 ]206 207 family = get_family(family_lines=family_lines)208 209 homozygote_variant = {'genotypes': {}}210 homozygote_variant['genotypes']['proband'] = Genotype(**{'GT':'1/1'})211 212 assert check_X_dominant(213 variant = homozygote_variant,214 family = family215 ) == False216def test_x_healthy_homozygote_female():217 """Test an healthy homozygote female"""218 219 family_lines = [220 "#FamilyID\tSampleID\tFather\tMother\tSex\tPhenotype\n",221 "1\tproband\t0\t0\t2\t1\n"222 ]223 224 family = get_family(family_lines=family_lines)225 226 homozygote_variant = {'genotypes': {}}227 homozygote_variant['genotypes']['proband'] = Genotype(**{'GT':'1/1'})228 229 assert check_X_dominant(230 variant = homozygote_variant,231 family = family232 ) == False233def test_x_healthy_male_ref_call():234 """Test an healthy ref call male"""235 236 family_lines = [237 "#FamilyID\tSampleID\tFather\tMother\tSex\tPhenotype\n",238 "1\tproband\t0\t0\t1\t1\n"239 ]240 241 family = get_family(family_lines=family_lines)242 243 homozygote_variant = {'genotypes': {}}244 homozygote_variant['genotypes']['proband'] = Genotype(**{'GT':'0/0'})245 246 assert check_X_dominant(247 variant = homozygote_variant,248 family = family249 ) == True250def test_x_healthy_female_ref_call():251 """Test an healthy female ref call"""252 253 family_lines = [254 "#FamilyID\tSampleID\tFather\tMother\tSex\tPhenotype\n",255 "1\tproband\t0\t0\t2\t1\n"256 ]257 258 family = get_family(family_lines=family_lines)259 260 homozygote_variant = {'genotypes': {}}261 homozygote_variant['genotypes']['proband'] = Genotype(**{'GT':'0/0'})262 263 assert check_X_dominant(264 variant = homozygote_variant,265 family = family...

Full Screen

Full Screen

family.py

Source:family.py Github

copy

Full Screen

...13 """14 res = []15 for prot, peps in peptideToProtein.items():16 for elt in peps:17 if elt.get_family() not in res:18 res.append(elt.get_family())19 return res20def assignPeptideToFamily(peptideToProtein):21 """Crée un dictionnaire qui associe à chaque famille les peptides qui y apparaissent22 Args:23 peptideToProtein (dict) : les peptides associés à leur protéine24 Raises:25 /26 Returns:27 dict : dictionnaire contenant en clé les familles, et en valeurs les peptides appartenant à ces familles28 """29 res = {}30 for prot, otherPeps in peptideToProtein.items():31 for otherP in otherPeps:32 if otherP.get_family() not in res:33 res[otherP.get_family()] = [otherP]34 else:35 if otherP not in res[otherP.get_family()]:36 res[otherP.get_family()].append(otherP)37 return res38def familyOfPeptides(dicoPeptides):39 """Crée un dictionnaire contenant pour chaque peptide les familles auxquelles il appartient40 Args:41 dicoPeptides (dict) : les dictionnaire contenant les peptides, et les peptides identiques à celui-ci en valeur42 Raises:43 /44 Returns:45 dict : dictionnaire avec les peptides en clé, et les familles auxquelles ils appartiennet en valeur46 """47 dico_family = {}48 for pep, pep_list in dicoPeptides.items():49 family = []50 family.append(pep.get_family())51 for pep_identique in pep_list:52 if pep_identique.get_family() != pep.get_family():53 if pep_identique.get_family() not in family:54 family.append(pep_identique.get_family())55 dico_family[pep] = family56 return dico_family57def seqToFamily(peptideToProtein):58 """Crée un dictionnaire qui associe à chaque famille les séquences leur appartenant59 Args:60 peptideToProtein (dict) : les peptides associés à leur protéine61 Raises:62 /63 Returns:64 dict : dictionnaire qui associe à chaque famille les séquences leur appartenant65 """66 res = {}67 for prot, peptides in peptideToProtein.items():68 if peptides[0].get_family() not in res:69 res[peptides[0].get_family()] = [prot]70 else:71 res[peptides[0].get_family()].append(prot)72 return res73def getFamilyWithoutUnique(peptideToFamily, uniquePeptides):74 """Crée une liste contenant les familles n'ayant pas de peptide unique75 Args:76 peptideToFamily (dict) : le dictionnaire associant les peptides à leur famille77 uniquePeptides (list) : la liste des peptides uniques pour une séquence78 Raises:79 /80 Returns:81 list : une liste contenant les familles n'ayant pas de peptide unique82 """83 res = list(peptideToFamily.keys())84 for pep in uniquePeptides:85 if pep.get_family() in res:86 res.remove(pep.get_family())87 return res88def where_pep_present_family(dico):89 """stock the different species the peptide appears in and make sublist of species that are part of the same family.90 Args:91 dico (dict): the dictonnary made after compare_peptide()92 Returns:93 dict: key = peptide94 values = list of sublist of species the peptide appears in (sublist = family)95 """96 dico_family = {}97 for pep, pep_list in dico.items(): # On parcours le dico98 species = [] # liste pour stocker les espèces où le peptide apparaît99 species.append(pep)100 for pep_identique in pep_list:101 if pep_identique.get_nb_prot() != pep.get_nb_prot():102 species.append(pep_identique)103 family_list = [] # liste pour pouvoir constituer les sous listes d'espèces104 species = sorted(species, key=lambda105 pep: pep.get_family()) # on range les espèces en fonction de la famille auquelles elles appartiennent106 for k, g in itertools.groupby(species,107 lambda pep: pep.get_family()): # fonction du module itertools (permet de regrouper en sous listes les elements d'une liste de départ en fonction d'un critère, ici la famille)108 family_list.append(list(g))109 dico_family[110 pep] = family_list # le dico avec pour chaque peptide, les espèces regroupées en genre auquel il apparaît111 return dico_family112def unique_pep_family(dico_pep_family):113 """Let the user find the peptides that are unique to only one family (if the peptide appears only in one family).114 Args:115 dico_pep_family (dict): the dictonnary made in where_pep_present_family()116 Returns:117 list: the list containing the peptides that are unique for one family118 """119 unique_pep_family_list = []120 for pep, family_list in dico_pep_family.items():121 unique = True122 for i in range(len(family_list)):123 if i > 0: # si la liste contient plus d'une sous liste, c'est que le peptide apparaît dans plus d'une famille donc il n'est pas unique à une famille124 unique = False125 break126 if unique:127 unique_pep_family_list.append(pep)128 return sorted(unique_pep_family_list, key=lambda pep: pep.get_family())129def pretty_print_unique_peptide_family(liste, listAllFamily, output_dir):130 """Permet le formatage du fichier txt seulement pour les peptides uniques pour chaque famille131 Args:132 liste (List): the output of unique_pep_family()133 output_file (str): the name of the output file we want134 allResultsFile (str) : the name of the output file that contains all the results135 Raises:136 TypeError: if the parameters is not a list and a str137 """138 if not os.path.exists(output_dir):139 os.makedirs(output_dir)140 with open(output_dir + 'unique_pep_family.csv', 'w', newline='') as results:141 writer_family = csv.writer(results)142 writer_family.writerow(["Family", "Genus", "Protein Name", "Position", "Peptide mass", "Peptide seq"])143 for peptide in liste:144 rowToInsert = [peptide.get_family(), peptide.get_genus(), peptide.get_prot_name(), peptide.get_position(), peptide.get_mass(), peptide.get_seq()]145 writer_family.writerow(rowToInsert)146 writer_family.writerow("")147 noUnique = []148 for family in listAllFamily:149 tmp = False150 for elt in liste :151 if family == elt.get_family():152 tmp = True153 if not tmp:154 noUnique.append(family)155 strNoUnique = ",".join(noUnique)156 writer_family.writerow(["Families that don't have a unique peptide :" + strNoUnique])157def mainFamily(dict_p, output_dir, peptidesToProtein):158 dict_f = where_pep_present_family(dict_p)159 uniquePepFamily = unique_pep_family(dict_f)160 AllFamilies = getAllFamilies(peptidesToProtein)161 # Création du fichier contenant les peptides uniques pour chaque famille162 pretty_print_unique_peptide_family(uniquePepFamily, AllFamilies, output_dir)163 # On cherche et renvoie les familles sans peptides uniques164 seqWithoutUniqueFamily = combinations.getSequencesWithoutUnique(peptidesToProtein, uniquePepFamily)165 return seqWithoutUniqueFamily

Full Screen

Full Screen

sim_community.py

Source:sim_community.py Github

copy

Full Screen

...63 if not target_citizen.is_inmune():64 target_citizen.infect(step=0)65 # Creación de familias66 for citizen in self.citizens:67 if len(citizen.get_family()) < self.minFam:68 if self.avaible_family():69 while len(citizen.get_family()) < self.minFam:70 family_member = choice(self.citizens)71 if family_member != citizen:72 if len(family_member.get_family()) < self.minFam:73 if not citizen in family_member.get_family():74 citizen.add_family_member(family_member)75 family_member.add_family_member(citizen)76 else:77 self.population_is_generated = False78 break79 80 for citizen in self.citizens:81 new_max = randrange(self.maxFam+1)82 while len(citizen.get_family()) < new_max:83 family_member = choice(self.citizens)84 if family_member != citizen:85 if len(family_member.get_family()) < self.maxFam:86 if not citizen in family_member.get_family():87 citizen.add_family_member(family_member)88 family_member.add_family_member(citizen)89 citizen.end_gen()90 self.update_log()91 def avaible_family(self):92 avaible_family_spaces = 093 for citizen in self.citizens:94 if len(citizen.get_family()) < self.minFam:95 avaible_family_spaces += 196 if avaible_family_spaces == 2:97 return True98 return False99 def show_population(self):100 self.core.load_citizen_data(self.citizens)101 def take_step(self):102 self.step += 1103 # Vacunación104 if self.step >= self.vaccines_start:105 for i in range(3):106 if self.vaccines[i].get_inventory() != 0:107 vaccinations = randrange(self.vaccines[i].get_inventory())108 for k in range(vaccinations):109 not_ready = True110 while not_ready:111 citizen = choice(self.citizens)112 if not citizen.is_vaccinated():113 citizen.vaccinate(self.vaccines[i].get_vaccine_type(),self.step)114 self.vaccines[i].use()115 not_ready = False116 # Evolución117 for citizen in self.citizens:118 citizen.evolve(self.step)119 # Contacto Cercano120 for contact in range(self.contactProm):121 contact_increment = 0122 infection_increment = 0123 while True:124 citizen_a = choice(self.citizens)125 citizen_b = choice(self.citizens)126 if citizen_a != citizen_b:127 break128 # Contacto Muy Estrecho129 if citizen_a in citizen_b.get_family():130 contact_increment = 10131 infection_increment = 5132 if randrange(100) < self.contactProb+contact_increment:133 # A infecta B134 if citizen_a.get_status():135 if not citizen_b.is_inmune():136 citizen_b.try_infection(self.step,infection_increment)137 # B infecta A138 if citizen_b.get_status():139 if not citizen_a.is_inmune():140 citizen_a.try_infection(self.step,infection_increment)141 self.update_log()142 143 def update_log(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful