Skip to content

Commit

Permalink
smoothing out
Browse files Browse the repository at this point in the history
  • Loading branch information
greenkidneybean committed Jun 18, 2018
1 parent d938951 commit 448b92f
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 22 deletions.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,49 @@ cd ~/circos-py
python make_circos_plots.py example_input_data.csv
```

## Install Circos-Py
## Install
### Quick-Guide
Just a quick gerneral guide for Mac users: if you do not actively use Python, Perl, or Circos already I would recommend installing [Anaconda3](https://www.anaconda.com/download/), then installing Perl via conda:

```
conda install -c anaconda perl
```

Then install [Circos](http://circos.ca/software/download/), unzip, and symlink to usr/local/bin:

```
cd ~/Desktop
wget http://circos.ca/distribution/circos-0.69-6.tgz
tar xvfz circos-0.69-6.tgz
ln -s ~/Desktop/circos-0.69-6/bin/circos /usr/local/bin/circos
```

You should now be able to run circos from the command line. Check this by running the following from the terminal:

`$ circos -v`

And you should see something similar to:

`circos | v 0.69-6 | 31 July 2017 | Perl 5.022000`

Now it's time to check what Perl modules are needed to run Circos: `circos -module`

A list of modules should sputter forth. Use the below snippet to install all Circos Perl modules with CPAN:

```
cpan Carp Clone Config::General Cwd Data::Dumper Digest::MD5 File::Basename File::Spec::Functions File::Temp FindBin Font::TTF::Font GD GF::Polyline Getopt::Long IO::File List::MoreUtils List::Util Math::Bezier Math::BigFloat Math::Round Math::VecStat Memoize POSIX Params::Validate Pod::Usage Readonly Regexp::Common SVG Set::IntSpan Statistics::Basic Storable Sys::Hostname Text::Balanced Text::Format Time::HiRes
```

Last thing is to clone this repository:

```
git clone [email protected]:greenkidneybean/circos-py.git
```

### Circos
Unfortunately Circos takes a bit of effort to get up and running. If you're on a Mac I'd recommend [installing via Homebrew](http://circos.ca/tutorials/lessons/configuration/distribution_and_installation/).
### Circos-Py


## Setup
### Add Circos Binary to Your Shell Path
Expand Down
Binary file modified __pycache__/circos.cpython-36.pyc
Binary file not shown.
7 changes: 4 additions & 3 deletions circos.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,14 @@ def generate_circos_links(input_dataframe, spec_dict):
final_links=final_links.rename(columns={'circos_time':'#ciros_time'})

# write link files
# this can be changed
final_links.to_csv(f'links_{output_file_name}.txt', sep='\t', index=False, header=True)

# this is dangerous because it will layer the links.txt with each iteration
if os.path.isfile('links.txt') is False:
final_links.to_csv('links.txt', sep='\t', index=False, header=True)
if os.path.isfile('links_all-data.txt') is False:
final_links.to_csv('links_all-data.txt', sep='\t', index=False, header=True)
else:
with open('links.txt', 'a') as f:
with open('links_all-data.txt', 'a') as f:
final_links.to_csv(f, sep='\t', index=False)

return final_links
2 changes: 1 addition & 1 deletion circos_conf/circos.conf
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ format = %d
<links>

<link>
file = links.txt
file = links_all-data.txt
ribbon = yes
flat = yes
radius = .99r
Expand Down
2 changes: 1 addition & 1 deletion circos_conf/circos_h7.conf
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ format = %d
<links>

<link>
file = links_h7.txt
file = links_spec_1.txt
ribbon = yes
flat = yes
radius = .99r
Expand Down
2 changes: 1 addition & 1 deletion circos_conf/circos_stem.conf
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ format = %d
<links>

<link>
file = links_stem.txt
file = links_spec_2.txt
ribbon = yes
flat = yes
radius = .99r
Expand Down
Binary file modified example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 22 additions & 15 deletions make_circos_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

'''
TODO:
dump all images into generated project folder
better names for files
handle .csv and .xls file input
easily replicate environment (Docker?)
Expand All @@ -21,6 +20,8 @@
function to make file paths
option for all images or specific color layer
specify full path to project folder if saving somewhere else
run circos and specify links file rather than specific circos.conf?
run circos once if current_spec is "all-data"
'''

# imports may not be necessary with the circos module imported
Expand All @@ -42,19 +43,19 @@
args = parser.parse_args()

# setup sample dictionaries
# includes circos.conf files to be used (call different link files)

all_spec_dict = {'output_file_name':'h7-stem',
all_spec_dict = {'output_file_name':'all-data',
'circos_conf_file':'circos.conf'}
h7_spec_dict = {'output_file_name':'h7',
'spec_list':['H7 sp', 'spec_2'],
spec_dict_1 = {'output_file_name':'spec_1',
'spec_list':['H7 sp', 'spec_1'], # feature #1 in "spec" column
'color':'red_orange',
'circos_conf_file':'circos_h7.conf'}
stem_spec_dict = {'output_file_name':'stem',
'spec_list':['H7 dp', 'spec_1'],
spec_dict_2 = {'output_file_name':'spec_2',
'spec_list':['H7 dp', 'spec_2'], # feature #2 in "spec" column
'color':'blue',
'circos_conf_file':'circos_stem.conf'}
dict_list = [all_spec_dict, h7_spec_dict, stem_spec_dict]

dict_list = [all_spec_dict, spec_dict_1, spec_dict_2]

# assign variables
input_file = args.input_excel
Expand All @@ -72,6 +73,8 @@
os.makedirs(input_files_folder, exist_ok=True)
os.makedirs(samples_dir, exist_ok=True)

### run a test to check for .csv or .xlsx file and generate sheet

# identify all sheets in Excel input file
x1 = pd.ExcelFile(input_file)
sheets = x1.sheet_names
Expand Down Expand Up @@ -111,11 +114,11 @@
os.chdir(sample_dir)
# make directories
img_fld = sample_image_dir + '/' + i['output_file_name']
current_folder_name = i['output_file_name']
os.makedirs(current_folder_name, exist_ok=True)
current_spec = i['output_file_name']
os.makedirs(current_spec, exist_ok=True)
os.makedirs(img_fld, exist_ok=True)
# go to directory
os.chdir(current_folder_name)
os.chdir(current_spec)
# make circos files
#df = circos_input_file(sample_input_file, i) # spits out sorted file
df = format_dataframe(start_df, i)
Expand All @@ -124,17 +127,21 @@
for a in dict_list[1:]:
generate_circos_links(df, a)

# run circos
# run circos
for i in dict_list:
circos_conf = circos_conf_dir + '/' + i['circos_conf_file']
circos_plot_name = sample_id + '_' + i['output_file_name']
#circos_conf = circos_conf_dir + '/' + i['circos_conf_file']
current_circos_spec = i['output_file_name']
circos_conf = f'{circos_conf_dir}/circos.conf'
circos_plot_name = f'{sample_id}_{current_circos_spec}'

link_file=f'links_{current_circos_spec}.txt'
print()
print('---')
print('Running Circos')
print(f'Circos configuration file path: {circos_conf}')
print(f'Output plot name: {circos_plot_name}')
print('---')
subprocess.run('circos -conf {0} -outputfile {1}'.format(circos_conf, circos_plot_name), shell=True)
subprocess.run('circos -conf {0} -outputfile {1} -param links/link/file={2}'.format(circos_conf, circos_plot_name, link_file), shell=True)

# copy images to main image folder
print()
Expand Down

0 comments on commit 448b92f

Please sign in to comment.