[Genabel-commits] r2016 - in pkg/ProbABEL: doc src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 21 17:17:59 CEST 2015


Author: lckarssen
Date: 2015-09-21 17:17:59 +0200 (Mon, 21 Sep 2015)
New Revision: 2016

Modified:
   pkg/ProbABEL/doc/extract-snp.1
   pkg/ProbABEL/src/extract-snp.cpp
Log:
Added the --listsnps and --listids options to ProbABEL's extract-snp tool.
These options list all SNP names or ID names found in the filevector file, respectively.


Modified: pkg/ProbABEL/doc/extract-snp.1
===================================================================
--- pkg/ProbABEL/doc/extract-snp.1	2015-09-21 12:33:14 UTC (rev 2015)
+++ pkg/ProbABEL/doc/extract-snp.1	2015-09-21 15:17:59 UTC (rev 2016)
@@ -28,6 +28,16 @@
 \fIindividualID\fR) for the SNP listed with the \-\-snp option.
 .RE
 .TP
+.BI "-I, \-\^\-listids"
+List all ID names in the fv file. If this option is used, any other
+options are ignored.
+.RE
+.TP
+.BI "-L, \-\^\-listsnps"
+List all SNP names in the fv file. If this option is used, any other
+options are ignored.
+.RE
+.TP
 .BI "-h, \-\^\-help"
 Print usage information to the screen and exit.
 .RE
@@ -38,10 +48,11 @@
 found in the file.
 .RE
 .SH EXAMPLES
-This extracts the dosages for all individuals:
+This extracts the dosages for all individuals and saves them in the
+file dosages.txt:
 .nf
 .RS
-extract-snp \-f ../checks/inputfiles/mmscore_gen.dose.fvi \-s  rs70099 > dosage.txt
+extract-snp \-f ../checks/inputfiles/mmscore_gen.dose.fvi \-s rs70099 > dosages.txt
 .RE
 .fi
 .SH "SEE ALSO"

Modified: pkg/ProbABEL/src/extract-snp.cpp
===================================================================
--- pkg/ProbABEL/src/extract-snp.cpp	2015-09-21 12:33:14 UTC (rev 2015)
+++ pkg/ProbABEL/src/extract-snp.cpp	2015-09-21 15:17:59 UTC (rev 2016)
@@ -47,6 +47,12 @@
     cout << "   or: " << program_name << " -f <fv file> -s <snpname>" << endl;
     cout << endl;
     cout << "Additional options:" << endl;
+    cout << "\t--listsnps (-L); list all SNP names from the fv file"
+         << " (the program exist after this)"
+         << endl;
+    cout << "\t--listids (-I); list all ID names from the fv file"
+         << " (the program exist after this)"
+         << endl;
     cout << "\t--id (-i) <idname>: "
          << "only print the dosage for the given SNP and ID" << endl;
     cout << "\t--debug (-d): show debugging output" << endl;
@@ -63,21 +69,26 @@
     }
 
     int next_option;
-    const char * const short_options = "df:hi:s:";
+    const char * const short_options = "df:hi:ILs:";
     const struct option long_options [] =
         {
-            {"debug",  0, NULL, 'd'},
-            {"file",  1, NULL, 'f'},
-            {"help",  0, NULL, 'h'},
-            {"id",   1, NULL, 'i'},
-            {"snp",  1, NULL, 's'},
-            {NULL  ,   0, NULL, 0  }
+            {"debug",    0, NULL, 'd'},
+            {"file",     1, NULL, 'f'},
+            {"help",     0, NULL, 'h'},
+            {"id",       1, NULL, 'i'},
+            {"listids",  0, NULL, 'I'},
+            {"listsnps", 0, NULL, 'L'},
+            {"snp",      1, NULL, 's'},
+            {NULL,       0, NULL, 0  }
         };
+
     char *program_name = argv[0];
-    bool debug = false;
+    bool debug    = false;
+    bool listSNPs = false;
+    bool listIDs  = false;
     string inputFileName = "";
-    string idname = "";
-    string snpname = "";
+    string idname        = "";
+    string snpname       = "";
     do
     {
         next_option = getopt_long(argc, argv,
@@ -96,6 +107,12 @@
         case 'i':
             idname = string(optarg);
             break;
+        case 'I':
+            listIDs = true;
+            break;
+        case 'L':
+            listSNPs = true;
+            break;
         case 's':
             snpname = string(optarg);
             break;
@@ -104,34 +121,70 @@
         }
     } while (next_option != -1);
 
-    if (snpname.compare("") == 0)
+    if (inputFileName.compare("") == 0)
     {
-        cerr << "Error: No SNP name given" << endl << endl;
+        cerr << "Error: No filevector file specified.\n";
         info(program_name);
-        exit(2);
+        exit(4);
     }
 
-    unsigned long int snprow = 0;
-    bool snpfound = false;
-    bool idfound  = false;
-
     if (debug) cout << "Input file is '" << inputFileName << "'." << endl;
 
+
     FileVector fv(inputFileName, 64, true);
 
-    if (debug)
+    if (listSNPs)
     {
-        // Print all individual names
+        // Only print SNPs to stdout.
+        for (unsigned long int row = 0; row < fv.getNumVariables(); row++)
+        {
+            string current_snpname = fv.readVariableName(row).name;
+            cout << current_snpname << " ";
+        }
+        cout << endl;
+        exit(0);
+    }
+
+    if (listIDs || debug)
+    {
+        if(debug)
+        {
+            cout << "---------- List of IDs ----------" << endl;
+        }
+        // Only print IDs to stdout.
         for (unsigned long int col = 0; col < fv.getNumObservations(); col++)
         {
             cout << fv.readObservationName(col).name << " ";
         }
 
         cout << endl;
-        cout << "----------------------" << endl;
+
+        if(debug)
+        {
+            cout << "---------- End of IDs ----------" << endl;
+        }
+
+        if(!debug) exit(0);
     }
 
+
+    if (snpname.compare("") == 0)
+    {
+        cerr << "Error: No SNP name given" << endl << endl;
+        info(program_name);
+        exit(2);
+    }
+
+    unsigned long int snprow = 0;
+    bool snpfound = false;
+    bool idfound  = false;
+
+
     // Look at the SNPs (rows) first
+    if(debug)
+    {
+        cout << "---------- List of SNP names ----------" << endl;
+    }
     for (unsigned long int row = 0; row < fv.getNumVariables(); row++)
     {
         string current_snpname = fv.readVariableName(row).name;
@@ -153,7 +206,7 @@
     if (debug)
     {
         cout << endl;
-        cout << "----------------------" << endl;
+        cout << "---------- End of SNP names ----------" << endl;
 
         cout << "N_obs = " << fv.getNumObservations() << "\telement size: "
              <<  fv.getElementSize() << "\tDataType: "



More information about the Genabel-commits mailing list