Pas-Kapli / mptp

mPTP - a tool for single-locus species delimitation
GNU Affero General Public License v3.0
24 stars 5 forks source link

Output file to csv #83

Open Lithobius opened 5 years ago

Lithobius commented 5 years ago

I wrote a quick Python script to convert the output of mPTP to a CSV file so that I could use the output with ggmap and with other things where I might want to use the output of mPTP to sort my data in lieu of other elements of my spreadsheets.

It would be nice if mPTP had a built-in option to export csv versions of the output alongside the txt file.

Here is the script I wrote, it might not be perfect but if anyone else needs it it is there: https://github.com/Lithobius/lazylithobius/blob/master/mPTP2csv./mptp2csv.py

stamatak commented 5 years ago

thank you very much for sharing this :-)

alexis

On 24.01.19 22:32, Kate Sheridan wrote:

I wrote a quick Python script to convert the output of mPTP to a CSV file so that I could use the output with ggmap and with other things where I might want to use the output of mPTP to sort my data in lieu of other elements of my spreadsheets.

It would be nice if mPTP had a built-in option to export csv versions of the output alongside the txt file.

Here is the script I wrote, it might not be perfect but if anyone else needs it it is there: https://github.com/Lithobius/lazylithobius/tree/master/mPTP2csv.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Pas-Kapli/mptp/issues/83, or mute the thread https://github.com/notifications/unsubscribe-auth/AA1w-i9GNC59iC8k9beARAYOEXNhxM4sks5vGiZ6gaJpZM4aRwIo.

-- Alexandros (Alexis) Stamatakis

Research Group Leader, Heidelberg Institute for Theoretical Studies Full Professor, Dept. of Informatics, Karlsruhe Institute of Technology

www.exelixis-lab.org

boopsboops commented 2 years ago

If any use to anyone, here's also quick R function to read mPTP output as two-column tabular format:

# load libs
library("tidyverse")

# load func
read_mptp <- function(file,skiplines) {
    mptp.raw <- readr::read_delim(file,skip=skiplines,delim=",",col_names="individual",show_col_types=FALSE)
    mptp.tab <- mptp.raw %>% 
        dplyr::mutate(species=ifelse(grepl(":",individual),individual,NA)) %>%
        tidyr::fill(species,.direction="down") %>%
        dplyr::filter(!grepl(":",individual)) %>%
        dplyr::mutate(species=stringr::str_replace_all(species,":| ","")) %>%
        dplyr::relocate(species,.before=individual)
    return(mptp.tab)
}

# run func
my.mptp.table <- read_mptp(file="path/to/mptp-output.txt",skiplines=6)

# write out if required
readr::write_csv(my.mptp.table,file="path/to/mptp-output.csv")

Note: the skiplines option ignores the first n lines of the mPTP output file containing model parameters. Therefore make sure the skiplines option is correct for your mPTP output. With delimitations starting on line 7, set skiplines to 6 (skiplines=6). If the model parameters are required in the table, then the script should be easy to adapt.