How to operate IGV using socket communication, and the story of making a Ruby Gem using that method

Introduction

IGV is software called a genome browser. You can browse various files such as the bam file of the aligned read, the bed file in which the position information on the genome is annotated, and the gff3 file in which the genetic information is written. If you have been involved in bioinformatics, you probably know this software.

IGV repository on Github IGV.png

Although it is such an IGV, it may take some time to operate it while clicking with the mouse.

It's fun to check the results visually, and I think it's a very important task, but on the other hand, I also want to automate routine tasks as much as possible. Therefore, consider operating the IGV from a programming language.

Operate IGV using socket communication

In fact, IGV can be operated from port 60151 using socket communication.

There is a tab called advanced in View> Preference on the menu bar. If Enable port is not checked, check here.

image.png

You will then be able to use port 60151 to steer the IGV using socket communication.

List of commands that can be used to operate IGV

I translated the official reference into Japanese using DeepL Translator.

Command Description
new Create a new session. Remove all tracks except the default genome annotation.
load file Read data or session files. Specify the full path or URL separated by commas.
collapse trackName Collapses the specified trackName. If you do not specify trackName, all tracks will be collapsed.
echo In response"echo "Returns.(for test)
exit Quit the IGV application.
expand trackName Expands the specified trackName. If trackName is not specified, all tracks will be expanded.
genome genomeIdOrPath Select the genome by id or load the genome (indexed fasta) from the specified path.
goto locus or listOfLoci Scroll to a single locus or a space-separated list of loci. If a list is provided, these sitting positions are displayed in split screen view. Any syntax that is valid in the IGV search box is fine.
goto all Scroll to View the entire genome.
group option Alignment track only. Group the alignments with one of the following options: STRAND, SAMPLE, READ_GROUP, LIBRARY, FIRST_OF_PAIR_STRAND, TAG, PAIR_ORIENTATION, MATE_CHROMOSOME, SUPPLEMENTARY, MOVIE, ZMW, HAPLOTYPE, READ_ORDER, NONE, BASE_AT_POS
region chr start end Define a region of interest surrounded by two loci (for example, region chr1 100 200).
maxPanelHeight height Sets the number of pixels (height) in the vertical direction for each panel included in the image. Images created from port commands or batch scripts are not limited to the data displayed on the screen. In other words, you can include the entire panel in your image, not just what is displayed in the scrollable screen area. The default value for this setting is 1000, increase this value to display more data and decrease this value to create smaller images.
setLogScale(true or false)
setSleepInterval ms Sets the delay (sleep) time in milliseconds. The sleep interval is called between consecutive commands.
snapshotDirectory path Set the directory to write the image.
snapshot filename Save a snapshot of the IGV window to an image file. If filename is omitted, a PNG file with the filename generated based on the trajectory will be written. If filename is specified, the filename extension determines the format of the image file..png、.jpg, or.Must be svg.
sort option locus Sort tracks with aligned or segmented copy numbers. The value applied to the segmented copy number option is(1)AMPLIFICATION and DELETION of segmented copy numbers,(2)POSITION, STRAND, BASE, QUALITY, SAMPLE, READGROUP, INSERSTSIZE, FIRSTOFPAIRSTRAND, MATECHR, READORDER, and READNAME of the alignment track. option is case insensitive. You can specify locus to define a single position or range. If you do not specify an option, the sort is performed based on the displayed area or the center position of the displayed area.
squish trackName Squish the given trackName. trackName is optional and if not specified, all annotation tracks will be squished.
viewaspairs trackName Alignment track display mode"View as pairs "Set to.
preference key value Temporarily sets the setting named key to the specified value. This setting is valid only until the IGV is shut down.

Manipulate IGV from a programming language

Java

Since IGV is software developed in Java, the official example is also written in Java.

  Socket socket = new Socket("127.0.0.1", 60151);
  PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
  BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

  out.println("load na12788.bam,n12788.tdf");
  String response = in.readLine();
  System.out.println(response);

  out.println("genome hg18");
  response = in.readLine();
  System.out.println(response);

  out.println("goto chr1:65,827,301");
  //out.println("goto chr1:65,839,697");
  response = in.readLine();
  System.out.println(response);

  out.println("snapshotDirectory /screenshots");
  response = in.readLine();
  System.out.println(response);

  out.println("snapshot");
  response = in.readLine();
  System.out.println(response);

R

Now, what about programming languages other than Java? If you are using R, I'm not very familiar with it, but you can use it because a library for operating IGV will be provided from around bioconductor. A little search will hit the software igvR. This seems to utilize igv.js, so it may not automatically operate the IGV on the desktop ...

Python

It's a bit old script, but igv.py created by Brent Pedersen, who has recently been energetically developing bioinformatics tools using the Nim language. -There is a tool called playground / blob / master / igv / igv.py). This is a small library that wraps the socket communication above.

Ruby

I like Ruby. ** Nani Nani? Are there few tools? Then you can make it yourself !** So, referring to Brent Pedersen's script above, I created a tool called ruby-igv that can operate IGV from Ruby language. Now you can easily operate IGV from the Ruby language.

https://github.com/kojix2/ruby-igv

The usage is like this.

igv = IGV.new

igv.load 'na12788.bam'
igv.genome 'hg18'
igv.go 'goto chr1:65,827,301'
igv.save 'image.png'

It's still a freshly made tool. If you encounter a rough cut, a bug, or find a request, please report it to issue on Github. Of course, pull requests are also welcome.

in conclusion

Not limited to bioinformatics, attention tends to be focused on how to combine existing tools to achieve the purpose and how to master the tools. And when you are making a tool, you may think that the purpose and means are reversed. But in a sense, I think it's a very selfish and narrow-minded way of thinking. The more people who make and publish tools, the more convenient, expanding and prosperous the world will be. Let's make and publish tools more freely. (Because it doesn't have to be Ruby)

Recommended Posts

How to operate IGV using socket communication, and the story of making a Ruby Gem using that method
The story of making a communication type Othello game using Scala.
The story of making a binding for libui, a GUI library for Ruby that is easy to install
The story of introducing Ajax communication to ruby
[Ruby] How to calculate the total amount using the initialize method and class variables
[ruby] How to assign a value to a hash by referring to the value and key of another hash
[Ruby] How to retrieve the contents of a double hash
Method definition location Summary of how to check When defined in the project and Rails / Gem
How to test a private method in Java and partially mock that method
The story of forgetting to close a file in Java and failing
[Java] How to get to the front of a specific string using the String class
Iterative processing of Ruby using each method (find the sum from 1 to 10)
[Ruby On Rails] How to search the contents of params using include?
How to create a convenient method that utilizes generics and functional interfaces
[Ruby on Rails] How to log in with only your name and password using the gem devise
The story of making it possible to build a project that was built by Maven with Ant
If it is Ruby, it is efficient to make it a method and stock the processing.
[Ruby] How to use gsub method and sub method
Output of how to use the slice method
A story about making a Builder that inherits the Builder
[Ruby basics] How to use the slice method
[Ruby] How to use the map method. How to process the value of an object and get it by hash or symbol.
I tried to create a Ruby gem that outputs json output of book search results using Google Books API
[Ruby] I want to make a program that displays today's day of the week!
A memo about the types of Java O/R mappers and how to select them
Pass arguments to the method and receive the result of the operation as a return value
[Ruby] Cut out a string using the slice method
[Ruby] How to find the sum of each digit
The story of making a reverse proxy with ProxyServlet
Summary of Java communication API (1) How to use Socket
How to convert A to a and a to A using AND and OR in Java
[Ruby] How to get the tens place and the ones place
The story of making Dr. Oakid using LINE BOT
[Rails] How to install a decorator using gem draper
[Ruby On Rails] How to search and save the data of the parent table from the child table
[Swift5] How to analyze complex JSON and get the index of the element that satisfies the condition
The story of pushing a Docker container to GitHub Package Registry and Docker Hub with GitHub Actions
A story that deepened the understanding of devise's methods user_signed_in? And current_user through error resolution
A story I was addicted to before building a Ruby and Rails environment using Ubuntu (20.04.1 LTS)
[Ruby] Questions and verification about the number of method arguments
I want to call a method and count the number
The nth and n + 1st characters of a Ruby string
[Ruby] Creating code using the concept of classes and instances
How to join a table without using DBFlute and sql
Socket communication with a web browser using Java and JavaScript ②
Socket communication with a web browser using Java and JavaScript ①
The story of pushing Java to Heroku using the BitBucket pipeline
How to check the extension and size of uploaded files
[jsoup] How to get the full amount of a document
How to deal with different versions of rbenv and Ruby
[Apache Tomcat] The story of using Apache OpenWebBeans to enable CDI
[Rails] How to temporarily save the request URL of a user who is not logged in and return to that URL after logging in
A story that a Ruby beginner made and released a LINE BOT that tells the train time in 2 months
[Swift5] How to create a .gitignore file and the code that should be written by default
A story about using the CoreImage framework to erase stains with Swift and implement a blur erase function
How to create a method
How to create a jar file or war file using the jar command
[Rails] How to get the URL of the transition source and redirect
How to set the IP address and host name of CentOS8
The story of Collectors.groupingBy that I want to keep for posterity
I made a gem to post the text of org-mode to qiita