It could help target the use of immunotherapy - a new form of treatment that uses the body's own defences to tackle cancer. This therapy has shown great promise in recent years, but identifying which patients will respond best is a challenge for doctors.
The new approach - based on gene analysis - makes it easier to spot the range of immune cells present in a tumour. These cells could help the body detect and kill cancer when activated by certain drugs, scientists say.
Traditional treatments such as radiology do not discriminate between cell types and attack both cancerous and healthy cells, often leading to side-effects.
Researchers at the University of Edinburgh analysed genes from anonymised medical databases of thousands of tumours to identify genes associated with immune cells.
This allowed them to quickly detect immune cells in a tumour based on their genetic code even when they were mixed in with harmful cancerous cells and normal cells.
They say that this resource - called ImSig - paints the best picture of tumours to date and will allow scientists to study how certain immune cell types affect cancer growth.
In future, this could help doctors decide which patients were most likely to respond to immunotherapy, experts say.
The study is published in Cancer Immunology Research and was funded by the Biotechnology and Biological Sciences Research Council.
Professor Tom Freeman from the University of Edinburgh's Roslin Institute, who led the study, said: "Our approach, which helps us to find out exactly what cells make up a tumour is like deciphering which fruits went into making a smoothie. Although more work needs to be done before this could be used to help patients, we believe that this new technique is a step towards better understanding of tumours that could help guide patient treatment."
Ajit J Nirmal, Tim Regan, Barbara B Shih, David A Hume, Andrew H Sims, Tom C Freeman.
Immune Cell Gene Signatures for Profiling the Microenvironment of Solid Tumors.
Cancer Immunol Res November 2 2018 6 (11) 1388-1400. doi: 10.1158/2326-6066.CIR-18-0342.