Add unique identifier from file to filetype in directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add unique identifier from file to filetype in directory
# 15  
Old 11-28-2016
Where are you getting that list from? Is this a ls of the directory?
Quote:
Originally Posted by cmccabe
after script is run files are renamed to: ---- desired output

Code:
MEC1.bam
MEC1.vcf
MEC1.bam.bai
MEV32.bam
MEV32.vcf
MEV32.bam.bai
MEV33.bam
MEV33.vcf
MEV33.bam.bai


Are you saying that when you do ls /home/cmccabe/Desktop/index/R_2016_09_21_11_26_19_user_S5-00580-8-Medexome, this is what you see in it?
Quote:
Originally Posted by cmccabe
but what the directory looks like currently after the script is run.
Code:
IonXpress_001_MEVxx_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.bam
IonXpress_001_MEVxx_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.vcf
IonXpress_001_MEVxx_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.bam.bai
IonXpress_002_MEVxy_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.bam
IonXpress_002_MEVxy_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.vcf
IonXpress_002_MEVxy_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.bam.bai
IonXpress_003_MEVxw_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.bam
IonXpress_003_MEVxw_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.vcf
IonXpress_003_MEVxw_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.bam.bai

Quote:
Originally Posted by cmccabe
Maybe I typed something wrong, but I do get a log in the index directory. Thank you Smilie.
Did you make the change in identifier.pl as suggested in the comment? Did you comment the print and remove the # from move?

Code:
# For testing purposes. Comment this line and remove the # on the one after.
print "$working_path/$f => GETS RENAMED TO => $working_path/$new$ext\n";
#move "$working_path/$f", "$working_path/$new$ext";

This User Gave Thanks to Aia For This Post:
# 16  
Old 11-28-2016
Here is the information: the code as well as the directory after the execution of it. Thank you very much Smilie.

perl

Code:
#!/usr/bin/perl
#
use strict;
use warnings;
use File::Copy;

{
    $/ = "\n\n";
    while(<>) {
        work_space();
    }
}

sub work_space{
    my @lines = split /\n/;
    my $curr_dir = pop @lines;
    for my $info (@lines) {
        my ($pattern, $new_name) = split /\s+/, $info;
        change_filename($curr_dir, $pattern, $new_name);
    }
}

sub change_filename {
    my ($c_dir, $pat, $new) = @_;
    my $base_path = "/home/cmccabe/Desktop/index"; # path to directory
    my $working_path = "$base_path/$c_dir";

    opendir my $dir, "$working_path" or return;
    my @files = grep { /$pat.*\.(bam|vcf)/ && -f "$working_path/$_" } readdir $dir;
    for my $f (@files) {
        my ($ext) = $f =~ /(\..*)$/;
        # For testing purposes. Comment this line and remove the # on the one after.
        #print "$working_path/$f => GETS RENAMED TO => $working_path/$new$ext\n";
        move "$working_path/$f", "$working_path/$new$ext";
    }
}

after the script executes:

ls /home/cmccabe/Desktop/index
Code:
/R_2016_09_21_14_01_15_user_S5-00580-8-Medexome
IonXpress_001_MEV21_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.bam
IonXpress_001_MEV21_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.bam.bai
IonXpress_001_MEV21_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.vcf
IonXpress_002_MEV22_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.bam
IonXpress_002_MEV22_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.bam.bai
IonXpress_002_MEV22_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.vcf
IonXpress_003_MEV23_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.bam
IonXpress_003_MEV23_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.bam.bai
IonXpress_003_MEV23_R_2016_09_21_14_01_15_user_S5-00580-9-Medexome.vcf

# 17  
Old 11-28-2016
Thank you, but where did you get this list from and what did you mean by "files are renamed to"?

Quote:
Originally Posted by cmccabe
after script is run files are renamed to: ---- desired output

Code:
MEC1.bam
MEC1.vcf
MEC1.bam.bai
MEV32.bam
MEV32.vcf
MEV32.bam.bai
MEV33.bam
MEV33.vcf
MEV33.bam.bai

Please, do some troubleshooting.
Place back the # to the move command. Remove the # from the print command.
Create a new_input file with just:
Code:
IonXpress_001 MEC1
IonXpress_002 MEC32
IonXpress_003 MEC33
R_2016_09_21_11_26_19_user_S5-00580-8-Medexome

Issue the command perl /home/cmccabe/Desktop/NGS/scripts/identifier.pl /home/cmccabe/s5_files/identifier/new_input

After that, please, post just the unmodified output showing the source => GETS RENAMED TO => destination.

Also, cd into R_2016_09_21_11_26_19_user_S5-00580-8-Medexome and post the result of the command: pwd

Last edited by Aia; 11-28-2016 at 04:42 PM.. Reason: Adds pwd request.
This User Gave Thanks to Aia For This Post:
# 18  
Old 11-28-2016
I tried the suggestions and the comand runs but there is source => GETS RENAMED TO => destination

Thank you Smilie.
# 19  
Old 11-28-2016
Quote:
Originally Posted by cmccabe
I tried the suggestions and the comand runs but there is source => GETS RENAMED TO => destination

Thank you Smilie.
Did you mean "there is NOT" source => GETS RENAMED TO => destination? No output?
If there is output, please post it as displayed.
cd into R_2016_09_21_11_26_19_user_S5-00580-8-Medexome and post the result of the command: pwd
This User Gave Thanks to Aia For This Post:
# 20  
Old 11-29-2016
There is no output from the command though it does execute, I will post the pwd soon as well. Thank you very muchSmilie.

---------- Post updated 11-29-16 at 06:27 AM ---------- Previous update was 11-28-16 at 06:14 PM ----------

Here is the pwd

Code:
~/Desktop/index$ cd /home/cmccabe/Desktop/index/R_2016_09_21_14_01_15_user_S5-00580-8-Medexome

~/Desktop/index/R_2016_09_21_14_01_15_user_S5-00580-8-Medexome$ pwd

/home/cmccabe/Desktop/index/R_2016_09_21_14_01_15_user_S5-00580-8-Medexome

Thank you Smilie.
# 21  
Old 11-29-2016
Quote:
Originally Posted by Aia
Did you mean "there is NOT" source => GETS RENAMED TO => destination? No output?
If there is output, please post it as displayed.
cd into R_2016_09_21_11_26_19_user_S5-00580-8-Medexome and post the result of the command: pwd
Hi,

I asked you to troubleshoot using R_2016_09_21_11_26_19_user_S5-00580-8-Medexome, but you used R_2016_09_21_14_01_15_user_S5-00580-8-Medexome

Regardless. In the input file the line that detonates the working directory does not match with what you actually have in your system.

input file:
Code:
IonXpress_007 MEV21
IonXpress_008 MEV22
IonXpress_009 MEV23
R_2016_09_21_14_01_15_user_S5-00580-9-Medexome

Quote:
/home/cmccabe/Desktop/index/R_2016_09_21_14_01_15_user_S5-00580-8-Medexome
The script is designed to jump any directory that can not open or it doesn't exist.

Last edited by Aia; 11-29-2016 at 07:49 PM..
This User Gave Thanks to Aia For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to create new directory by date followed by identifier and additional subdirectories

I have a bash that downloads a list and if that list has data in it then a new main directory is created (with the date) with several subdirectories (example1, example2, example3). My question is in that list there are portion of specific file types (.vcf.gz) - identifier towards the end that have... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. UNIX for Advanced & Expert Users

File command return wrong filetype while file holds group separator char.

hi, I am trying to get the FileType using the File command. I have one file, which holds Group separator along with ASCII character. It's a Text file. But when I ran the File command the FileType is coming as "data". It should be "ASCII, Text file". Is the latest version of File... (6 Replies)
Discussion started by: Arpitak29
6 Replies

3. Shell Programming and Scripting

Change everything in a file that maps to {module::name.filetype} to _modules/name/applicat

path = content.txt filename = application directory = _modules define create $(eval from := $(shell echo $$1)) \ $(eval to := $(shell echo $$2)) \ sed -i '' 's/$(from)/$(to)/g' content.txt endef all: clear $(eval modules := $(shell egrep -o "{module+\}" $(path))) ... (1 Reply)
Discussion started by: bmson
1 Replies

4. Shell Programming and Scripting

HPUX find string in directory and filetype and replace string

Hi, Here's my dilemma. I need to replace the string Sept_2012 to Oct_2012 in all *config.py files within the current directory and below directories Is this possible? Also I am trying to find all instances of the string Sept_2012 within files in the current directory and below I have... (13 Replies)
Discussion started by: pure_jax
13 Replies

5. Shell Programming and Scripting

Change unique file names into new unique filenames

I have 84 files with the following names splitseqs.1, spliseqs.2 etc. and I want to change the .number to a unique filename. E.g. change splitseqs.1 into splitseqs.7114_1#24 and change spliseqs.2 into splitseqs.7067_2#4 So all the current file names are unique, so are the new file names.... (1 Reply)
Discussion started by: avonm
1 Replies

6. Shell Programming and Scripting

Unique files in a given directory

I keep all my files on a NAS device and copy files from it to usb or local storage when needed. The bad part about this is that I often have the same file on numerous places. I'd like to write a script to check if the files in a given directory exist in another. An example: say I have a... (7 Replies)
Discussion started by: cue
7 Replies

7. Shell Programming and Scripting

get part of file with unique & non-unique string

I have an archive file that holds a batch of statements. I would like to be able to extract a certain statement based on the unique customer # (ie. 123456). The end for each statement is noted by "ENDSTM". I can find the line number for the beginning of the statement section with sed. ... (5 Replies)
Discussion started by: andrewsc
5 Replies

8. Shell Programming and Scripting

Unique Directory and Folder Deletion Script

Ok, so I just got charged with the task of deleting some 300 user folders in a FTP server to free up some space. I managed to grep and cut the list of user folders to delete into a list of one user folder per line. Example: bob00 jane01 sue03 In the home folder, there are folders a-z, and... (5 Replies)
Discussion started by: b4sher
5 Replies

9. UNIX for Dummies Questions & Answers

Shell Script Unique Identifier Question

i All I have scripting question. I have a file "out.txt" which is generated by another script the file contains the following my_identifier8859574 logout The number is generated in the script and I have put the my_identifier bit in front of it as a unique identifier I now have... (7 Replies)
Discussion started by: grahambo2005
7 Replies

10. UNIX for Dummies Questions & Answers

Directory Inode Number Not Unique

Hi, I know that inode for each file is unique, but is it the for the directory? So far I found different directories has the same inode nubmer when you do ls -i, could some one explain why? Thanks a lot. (9 Replies)
Discussion started by: nj302
9 Replies
Login or Register to Ask a Question