-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change +'/'+ by oS.path.join, change system table creation and fix Ca…
…sFinder as a type of system
- Loading branch information
1 parent
0681c86
commit 6576132
Showing
4 changed files
with
50 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
import os | ||
from defense_finder_posttreat import best_solution | ||
|
||
def export_defense_finder_genes(defense_finder_genes, outdir, filename): | ||
defense_finder_genes.to_csv(outdir+'/'+filename+'_defense_finder_genes.tsv',sep='\t',index=False) | ||
|
||
|
||
def write_defense_finder_genes(defense_finder_genes_list, outdir, filename): | ||
filepath = os.path.join(outdir, f'{filename}_defense_finder_genes.tsv') | ||
defense_finder_genes_list.to_csv('filepath',sep='\t',index=False) | ||
|
||
def export_defense_finder_genes(defense_finder_genes, outdir, filename): | ||
defense_finder_genes.to_csv(os.path.join(outdir, filename+'_defense_finder_genes.tsv'), sep='\t', index=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
import os | ||
import pandas as pd | ||
|
||
|
||
def export_defense_finder_systems(defense_finder_genes, outdir, filename): | ||
systems = build_defense_finder_systems(defense_finder_genes) | ||
systems.to_csv(outdir+'/'+filename+'_defense_finder_systems.tsv',sep='\t',index=False) | ||
systems.to_csv(os.path.join(outdir, filename + '_defense_finder_systems.tsv'), sep='\t', index=False) | ||
|
||
|
||
def build_defense_finder_systems(defense_finder_genes): | ||
sys=defense_finder_genes.drop_duplicates('sys_id')[['sys_id' , 'type' , 'subtype']] | ||
|
||
sys_beg=defense_finder_genes.sort_values('hit_pos').drop_duplicates('sys_id').rename({'hit_id' : 'sys_beg'},axis=1)[['sys_id','sys_beg']] | ||
sys_end=defense_finder_genes.sort_values('hit_pos' , ascending=False).drop_duplicates('sys_id').rename({'hit_id' : 'sys_end'},axis=1)[['sys_id','sys_end']] | ||
protein_in_syst=defense_finder_genes.groupby('sys_id').hit_id.apply(lambda x: ",".join(x.sort_values())).reset_index().rename({'hit_id':'protein_in_syst'},axis=1) | ||
name_of_profiles_in_sys=defense_finder_genes.groupby('sys_id').gene_name.apply(lambda x : ",".join(x.sort_values())).reset_index().rename({'hit_id' : 'protein_in_syst'},axis = 1) | ||
genes_count=defense_finder_genes.sys_id.value_counts().reset_index() | ||
genes_count.columns=['sys_id','genes_count'] | ||
if defense_finder_genes.empty is False: | ||
out = defense_finder_genes.groupby(['sys_id', 'type', 'subtype'])[['hit_id', 'hit_pos']].apply(lambda x: ",".join(x.sort_values('hit_pos').hit_id.to_list())).reset_index() | ||
out.columns = ['sys_id', 'type', 'subtype', 'protein_in_syst'] | ||
out['sys_beg'] = out.protein_in_syst.map(lambda x: x.split()[0]) | ||
out['sys_end'] = out.protein_in_syst.map(lambda x: x.split()[-1]) | ||
|
||
genes_count = defense_finder_genes.sys_id.value_counts().reset_index() | ||
genes_count.columns = ['sys_id', 'genes_count'] | ||
out = out.merge(genes_count, on='sys_id') | ||
|
||
out=sys.merge(sys_beg,on = 'sys_id') | ||
out=out.merge(sys_end,on = 'sys_id') | ||
out=out.merge(protein_in_syst,on = 'sys_id') | ||
out=out.merge(genes_count,on = 'sys_id') | ||
out=out.merge(name_of_profiles_in_sys,on = 'sys_id') | ||
name_of_profiles_in_sys = defense_finder_genes.groupby('sys_id').gene_name.apply(lambda x: ",".join(x.sort_values())).reset_index().rename({'gene_name': 'name_of_profiles_in_sys'}, axis=1) | ||
out = out.merge(name_of_profiles_in_sys, on='sys_id') | ||
else: | ||
out = pd.DataFrame(columns=['sys_id', 'type', 'subtype', 'sys_beg', 'sys_end', 'protein_in_syst', 'genes_count', 'name_of_profiles_in_sys']) | ||
|
||
return(out) | ||
|
||
return out[['sys_id', 'type', 'subtype', 'sys_beg', 'sys_end', 'protein_in_syst', 'genes_count', 'name_of_profiles_in_sys']] |